From e33496b3aa93f19f54b3e8093fbdab82fd7c2cf0 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 10 Aug 2022 09:39:42 +0200 Subject: [PATCH 01/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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/44] 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 9849e123393a6ac2c523d1fa55cf433eb91568b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 31 Aug 2022 11:38:25 +0200 Subject: [PATCH 41/44] Add wasi_io_typenames and wasi_snapshot0 --- lib/wasi-types-generated/regenerate.sh | 10 ++++++++++ lib/wasi-types-generated/src/lib.rs | 2 ++ .../src/wasi_io_typenames/bindings.rs | 9 +++++++++ lib/wasi-types-generated/src/wasi_io_typenames/mod.rs | 2 ++ .../src/wasi_snapshot0/bindings.rs | 9 +++++++++ lib/wasi-types-generated/src/wasi_snapshot0/mod.rs | 2 ++ 6 files changed, 34 insertions(+) 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 create mode 100644 lib/wasi-types-generated/src/wasi_snapshot0/bindings.rs create 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 fa266c371f8..ac5748ec826 100755 --- a/lib/wasi-types-generated/regenerate.sh +++ b/lib/wasi-types-generated/regenerate.sh @@ -16,4 +16,14 @@ 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 51b9aafb921..26801020bba 100644 --- a/lib/wasi-types-generated/src/lib.rs +++ b/lib/wasi-types-generated/src/lib.rs @@ -1,2 +1,4 @@ pub mod wasi; pub mod wasi_filesystem; +pub mod wasi_io_typenames; +pub mod wasi_snapshot0; \ No newline at end of file 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..5ee86fb0339 --- /dev/null +++ b/lib/wasi-types-generated/src/wasi_io_typenames/bindings.rs @@ -0,0 +1,9 @@ +#[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 new file mode 100644 index 00000000000..c896660823f --- /dev/null +++ b/lib/wasi-types-generated/src/wasi_io_typenames/mod.rs @@ -0,0 +1,2 @@ +mod bindings; +pub use bindings::wasi_io_typenames::*; diff --git a/lib/wasi-types-generated/src/wasi_snapshot0/bindings.rs b/lib/wasi-types-generated/src/wasi_snapshot0/bindings.rs new file mode 100644 index 00000000000..28de26091a2 --- /dev/null +++ b/lib/wasi-types-generated/src/wasi_snapshot0/bindings.rs @@ -0,0 +1,9 @@ +#[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 new file mode 100644 index 00000000000..76d241271b0 --- /dev/null +++ b/lib/wasi-types-generated/src/wasi_snapshot0/mod.rs @@ -0,0 +1,2 @@ +mod bindings; +pub use bindings::wasi_snapshot0::*; From 04c4bee368ca2366a5d3affc24cf9100ca24f449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 31 Aug 2022 12:48:40 +0200 Subject: [PATCH 42/44] Disable wasi_snapshot0 and wasi_io_typenames for now --- .../src/wasi_filesystem/bindings.rs | 2502 +++++++++++++++++ .../src/wasi_io_typenames/bindings.rs | 9 - .../src/wasi_io_typenames/mod.rs | 4 +- .../src/wasi_snapshot0/mod.rs | 4 +- .../wit/wasi-filesystem.wit | 536 ++-- .../wit/wasi-io-typenames.wit | 198 +- 6 files changed, 2870 insertions(+), 383 deletions(-) delete mode 100644 lib/wasi-types-generated/src/wasi_io_typenames/bindings.rs diff --git a/lib/wasi-types-generated/src/wasi_filesystem/bindings.rs b/lib/wasi-types-generated/src/wasi_filesystem/bindings.rs index 7473d7f699e..dddfa94a17f 100644 --- a/lib/wasi-types-generated/src/wasi_filesystem/bindings.rs +++ b/lib/wasi-types-generated/src/wasi_filesystem/bindings.rs @@ -2,6 +2,29 @@ pub mod wasi_filesystem { #[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; + /// Relative offset within a file. + pub type Filedelta = i64; + /// Timestamp in nanoseconds. + /// + /// TODO: wasi-clocks is moving to seconds+nanoseconds. + pub type Timestamp = u64; + /// Information associated with a descriptor. + /// + /// Note: This was called `fdstat` in earlier versions of WASI. + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Info { + /// The type of filesystem object referenced by a descriptor. + pub type_: Type, + /// Flags associated with a descriptor. + pub flags: Flags, + } + impl core::fmt::Debug for Info { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Info").field("type", &self.type_).field("flags", &self.flags).finish()} + } /// The type of a filesystem object referenced by a descriptor. /// /// Note: This was called `filetype` in earlier versions of WASI. @@ -91,6 +114,34 @@ pub mod wasi_filesystem { Ok(())} } + /// File attributes. + /// + /// Note: This was called `filestat` in earlier versions of WASI. + #[repr(C)] + #[derive(Copy, Clone)] + pub struct Stat { + /// Device ID of device containing the file. + pub dev: Device, + /// File serial number. + pub ino: Inode, + /// File type. + pub type_: Type, + /// Number of hard links to the file. + pub 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. + pub size: Filesize, + /// Last data access timestamp. + pub atim: Timestamp, + /// Last data modification timestamp. + pub mtim: Timestamp, + /// Last file status change timestamp. + pub ctim: Timestamp, + } + impl core::fmt::Debug for Stat { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("Stat").field("dev", &self.dev).field("ino", &self.ino).field("type", &self.type_).field("nlink", &self.nlink).field("size", &self.size).field("atim", &self.atim).field("mtim", &self.mtim).field("ctim", &self.ctim).finish()} + } 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. @@ -155,6 +206,39 @@ pub mod wasi_filesystem { Ok(())} } + /// Number of hard links to an inode. + pub 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. + pub type Device = u64; + /// Filesystem object serial number that is unique within its file system. + pub type Inode = u64; + /// When setting a timestamp, this gives the value to set it to. + #[derive(Clone, Copy)] + pub enum NewTimestamp{ + /// Leave the timestamp set to its previous value. + NoChange, + /// 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), + } + impl core::fmt::Debug for NewTimestamp { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + NewTimestamp::NoChange => { + f.debug_tuple("NewTimestamp::NoChange").finish() + } + NewTimestamp::Now => { + f.debug_tuple("NewTimestamp::Now").finish() + } + NewTimestamp::Timestamp(e) => { + f.debug_tuple("NewTimestamp::Timestamp").field(e).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 @@ -529,6 +613,31 @@ pub mod wasi_filesystem { } } } + /// The position relative to which to set the offset of the descriptor. + #[derive(Clone, Copy)] + pub enum SeekFrom{ + /// Seek relative to start-of-file. + Set(Filesize), + /// Seek relative to current position. + Cur(Filedelta), + /// Seek relative to end-of-file. + End(Filesize), + } + impl core::fmt::Debug for SeekFrom { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + SeekFrom::Set(e) => { + f.debug_tuple("SeekFrom::Set").field(e).finish() + } + SeekFrom::Cur(e) => { + f.debug_tuple("SeekFrom::Cur").field(e).finish() + } + SeekFrom::End(e) => { + f.debug_tuple("SeekFrom::End").field(e).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. @@ -547,7 +656,29 @@ pub mod wasi_filesystem { pub struct WasiFilesystem { #[allow(dead_code)] env: wasmer::FunctionEnv, + func_canonical_abi_free: wasmer::TypedFunction<(i32, i32, i32), ()>, + func_canonical_abi_realloc: wasmer::TypedFunction<(i32, i32, i32, i32), i32>, + func_descriptor_change_directory_permissions_at: wasmer::TypedFunction<(i32,i32,i32,i32,i32,), i32>, + func_descriptor_change_file_permissions_at: wasmer::TypedFunction<(i32,i32,i32,i32,i32,), i32>, + func_descriptor_create_directory_at: wasmer::TypedFunction<(i32,i32,i32,), i32>, + func_descriptor_datasync: wasmer::TypedFunction, func_descriptor_fadvise: wasmer::TypedFunction<(i32,i64,i64,i32,), i32>, + func_descriptor_fallocate: wasmer::TypedFunction<(i32,i64,i64,), i32>, + func_descriptor_info: wasmer::TypedFunction, + func_descriptor_link_at: wasmer::TypedFunction<(i32,i32,i32,i32,i32,i32,i32,), i32>, + func_descriptor_open_at: wasmer::TypedFunction<(i32,i32,i32,i32,i32,i32,i32,), i32>, + func_descriptor_readlink_at: wasmer::TypedFunction<(i32,i32,i32,), i32>, + func_descriptor_remove_directory_at: wasmer::TypedFunction<(i32,i32,i32,), i32>, + func_descriptor_rename_at: wasmer::TypedFunction<(i32,i32,i32,i32,i32,i32,), i32>, + func_descriptor_seek: wasmer::TypedFunction<(i32,i32,i64,), i32>, + func_descriptor_set_size: wasmer::TypedFunction<(i32,i64,), i32>, + func_descriptor_set_times: wasmer::TypedFunction<(i32,i32,i64,i32,i64,), i32>, + func_descriptor_set_times_at: wasmer::TypedFunction<(i32,i32,i32,i32,i32,i64,i32,i64,), i32>, + func_descriptor_stat_at: wasmer::TypedFunction<(i32,i32,i32,i32,), i32>, + func_descriptor_symlink_at: wasmer::TypedFunction<(i32,i32,i32,i32,i32,), i32>, + func_descriptor_sync: wasmer::TypedFunction, + func_descriptor_tell: wasmer::TypedFunction, + func_descriptor_unlink_file_at: wasmer::TypedFunction<(i32,i32,i32,), i32>, memory: wasmer::Memory, } impl WasiFilesystem { @@ -671,10 +802,54 @@ pub mod wasi_filesystem { _instance: &wasmer::Instance, env: wasmer::FunctionEnv, ) -> Result { + let func_canonical_abi_free= _instance.exports.get_typed_function(&store, "canonical_abi_free")?; + let func_canonical_abi_realloc= _instance.exports.get_typed_function(&store, "canonical_abi_realloc")?; + let func_descriptor_change_directory_permissions_at= _instance.exports.get_typed_function(&store, "descriptor::change-directory-permissions-at")?; + let func_descriptor_change_file_permissions_at= _instance.exports.get_typed_function(&store, "descriptor::change-file-permissions-at")?; + let func_descriptor_create_directory_at= _instance.exports.get_typed_function(&store, "descriptor::create-directory-at")?; + let func_descriptor_datasync= _instance.exports.get_typed_function(&store, "descriptor::datasync")?; let func_descriptor_fadvise= _instance.exports.get_typed_function(&store, "descriptor::fadvise")?; + let func_descriptor_fallocate= _instance.exports.get_typed_function(&store, "descriptor::fallocate")?; + let func_descriptor_info= _instance.exports.get_typed_function(&store, "descriptor::info")?; + let func_descriptor_link_at= _instance.exports.get_typed_function(&store, "descriptor::link-at")?; + let func_descriptor_open_at= _instance.exports.get_typed_function(&store, "descriptor::open-at")?; + let func_descriptor_readlink_at= _instance.exports.get_typed_function(&store, "descriptor::readlink-at")?; + let func_descriptor_remove_directory_at= _instance.exports.get_typed_function(&store, "descriptor::remove-directory-at")?; + let func_descriptor_rename_at= _instance.exports.get_typed_function(&store, "descriptor::rename-at")?; + let func_descriptor_seek= _instance.exports.get_typed_function(&store, "descriptor::seek")?; + let func_descriptor_set_size= _instance.exports.get_typed_function(&store, "descriptor::set-size")?; + let func_descriptor_set_times= _instance.exports.get_typed_function(&store, "descriptor::set-times")?; + let func_descriptor_set_times_at= _instance.exports.get_typed_function(&store, "descriptor::set-times-at")?; + let func_descriptor_stat_at= _instance.exports.get_typed_function(&store, "descriptor::stat-at")?; + let func_descriptor_symlink_at= _instance.exports.get_typed_function(&store, "descriptor::symlink-at")?; + let func_descriptor_sync= _instance.exports.get_typed_function(&store, "descriptor::sync")?; + let func_descriptor_tell= _instance.exports.get_typed_function(&store, "descriptor::tell")?; + let func_descriptor_unlink_file_at= _instance.exports.get_typed_function(&store, "descriptor::unlink-file-at")?; let memory= _instance.exports.get_memory("memory")?.clone(); Ok(WasiFilesystem{ + func_canonical_abi_free, + func_canonical_abi_realloc, + func_descriptor_change_directory_permissions_at, + func_descriptor_change_file_permissions_at, + func_descriptor_create_directory_at, + func_descriptor_datasync, func_descriptor_fadvise, + func_descriptor_fallocate, + func_descriptor_info, + func_descriptor_link_at, + func_descriptor_open_at, + func_descriptor_readlink_at, + func_descriptor_remove_directory_at, + func_descriptor_rename_at, + func_descriptor_seek, + func_descriptor_set_size, + func_descriptor_set_times, + func_descriptor_set_times_at, + func_descriptor_stat_at, + func_descriptor_symlink_at, + func_descriptor_sync, + func_descriptor_tell, + func_descriptor_unlink_file_at, memory, env, }) @@ -781,6 +956,2331 @@ pub mod wasi_filesystem { _ => return Err(invalid_variant("expected")), }) } + /// Force the allocation of space in a file. + /// + /// Note: This is similar to `posix_fallocate` in POSIX. + pub fn descriptor_fallocate(&self, store: &mut wasmer::Store,self_: & Descriptor,offset: Filesize,len: Filesize,)-> 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_fallocate.call(store, handle0 as i32, wit_bindgen_wasmer::rt::as_i64(offset), wit_bindgen_wasmer::rt::as_i64(len), )?; + 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")), + }) + } + /// Synchronize the data of a file to disk. + /// + /// Note: This is similar to `fdatasync` in POSIX. + pub fn descriptor_datasync(&self, store: &mut wasmer::Store,self_: & Descriptor,)-> 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_datasync.call(store, handle0 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")), + }) + } + /// 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. + pub fn descriptor_info(&self, store: &mut wasmer::Store,self_: & Descriptor,)-> 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_info.call(store, handle0 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({ + let _memory_view = _memory.view(&store); + let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 1)?; + let _memory_view = _memory.view(&store); + let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 2)?; + Info{type_:match i32::from(load3) { + 0 => Type::Unknown, + 1 => Type::BlockDevice, + 2 => Type::CharacterDevice, + 3 => Type::Directory, + 4 => Type::Fifo, + 5 => Type::SymbolicLink, + 6 => Type::RegularFile, + 7 => Type::Socket, + _ => return Err(invalid_variant("Type")), + }, flags:validate_flags( + 0| ((i32::from(load4) as u8) << 0), + Flags::all().bits(), + "Flags", + |bits| Flags { bits } + )?, } + }), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 1)?; + match i32::from(load5) { + 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")), + }) + } + /// 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. + pub fn descriptor_set_size(&self, store: &mut wasmer::Store,self_: & Descriptor,size: Filesize,)-> 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_set_size.call(store, handle0 as i32, wit_bindgen_wasmer::rt::as_i64(size), )?; + 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")), + }) + } + /// 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. + pub fn descriptor_set_times(&self, store: &mut wasmer::Store,self_: & Descriptor,atim: NewTimestamp,mtim: NewTimestamp,)-> 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_0,result1_1,) = match atim { + NewTimestamp::NoChange=> { + let e = (); + { + let () = e; + (0i32, 0i64) + } + } + NewTimestamp::Now=> { + let e = (); + { + let () = e; + (1i32, 0i64) + } + } + NewTimestamp::Timestamp(e) => (2i32, wit_bindgen_wasmer::rt::as_i64(e)), + }; + let (result2_0,result2_1,) = match mtim { + NewTimestamp::NoChange=> { + let e = (); + { + let () = e; + (0i32, 0i64) + } + } + NewTimestamp::Now=> { + let e = (); + { + let () = e; + (1i32, 0i64) + } + } + NewTimestamp::Timestamp(e) => (2i32, wit_bindgen_wasmer::rt::as_i64(e)), + }; + let result3 = self.func_descriptor_set_times.call(store, handle0 as i32, result1_0, result1_1, result2_0, result2_1, )?; + let _memory_view = _memory.view(&store); + let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 0)?; + Ok(match i32::from(load4) { + 0 => Ok(()), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 1)?; + match i32::from(load5) { + 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")), + }) + } + /// 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. + pub fn descriptor_seek(&self, store: &mut wasmer::Store,self_: & Descriptor,from: SeekFrom,)-> 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_0,result1_1,) = match from { + SeekFrom::Set(e) => (0i32, wit_bindgen_wasmer::rt::as_i64(e)), + SeekFrom::Cur(e) => (1i32, wit_bindgen_wasmer::rt::as_i64(e)), + SeekFrom::End(e) => (2i32, wit_bindgen_wasmer::rt::as_i64(e)), + }; + let result2 = self.func_descriptor_seek.call(store, handle0 as i32, result1_0, result1_1, )?; + let _memory_view = _memory.view(&store); + let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 0)?; + Ok(match i32::from(load3) { + 0 => Ok({ + let _memory_view = _memory.view(&store); + let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 8)?; + load4 as u64 + }), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 8)?; + match i32::from(load5) { + 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")), + }) + } + /// Synchronize the data and metadata of a file to disk. + /// + /// Note: This is similar to `fsync` in POSIX. + pub fn descriptor_sync(&self, store: &mut wasmer::Store,self_: & Descriptor,)-> 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_sync.call(store, handle0 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")), + }) + } + /// 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. + pub fn descriptor_tell(&self, store: &mut wasmer::Store,self_: & Descriptor,)-> 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_tell.call(store, handle0 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({ + let _memory_view = _memory.view(&store); + let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 8)?; + load3 as u64 + }), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 8)?; + match i32::from(load4) { + 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")), + }) + } + /// Create a directory. + /// + /// Note: This is similar to `mkdirat` in POSIX. + pub fn descriptor_create_directory_at(&self, store: &mut wasmer::Store,self_: & Descriptor,path: & str,)-> Result, wasmer::RuntimeError> { + let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; + 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 vec1 = path; + let ptr1 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec1.len() as i32)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr1, vec1.as_bytes())?; + let result2 = self.func_descriptor_create_directory_at.call(store, handle0 as i32, ptr1, vec1.len() as i32, )?; + let _memory_view = _memory.view(&store); + let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 0)?; + Ok(match i32::from(load3) { + 0 => Ok(()), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 1)?; + match i32::from(load4) { + 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")), + }) + } + /// 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. + pub fn descriptor_stat_at(&self, store: &mut wasmer::Store,self_: & Descriptor,at_flags: AtFlags,path: & str,)-> Result, wasmer::RuntimeError> { + let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; + 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 flags1 = at_flags; + let vec2 = path; + let ptr2 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec2.len() as i32)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr2, vec2.as_bytes())?; + let result3 = self.func_descriptor_stat_at.call(store, handle0 as i32, (flags1.bits >> 0) as i32, ptr2, vec2.len() as i32, )?; + let _memory_view = _memory.view(&store); + let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 0)?; + Ok(match i32::from(load4) { + 0 => Ok({ + let _memory_view = _memory.view(&store); + let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 8)?; + let _memory_view = _memory.view(&store); + let load6 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 16)?; + let _memory_view = _memory.view(&store); + let load7 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 24)?; + let _memory_view = _memory.view(&store); + let load8 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 32)?; + let _memory_view = _memory.view(&store); + let load9 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 40)?; + let _memory_view = _memory.view(&store); + let load10 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 48)?; + let _memory_view = _memory.view(&store); + let load11 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 56)?; + let _memory_view = _memory.view(&store); + let load12 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 64)?; + Stat{dev:load5 as u64, ino:load6 as u64, type_:match i32::from(load7) { + 0 => Type::Unknown, + 1 => Type::BlockDevice, + 2 => Type::CharacterDevice, + 3 => Type::Directory, + 4 => Type::Fifo, + 5 => Type::SymbolicLink, + 6 => Type::RegularFile, + 7 => Type::Socket, + _ => return Err(invalid_variant("Type")), + }, nlink:load8 as u64, size:load9 as u64, atim:load10 as u64, mtim:load11 as u64, ctim:load12 as u64, } + }), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load13 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 8)?; + match i32::from(load13) { + 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")), + }) + } + /// 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. + pub fn descriptor_set_times_at(&self, store: &mut wasmer::Store,self_: & Descriptor,at_flags: AtFlags,path: & str,atim: NewTimestamp,mtim: NewTimestamp,)-> Result, wasmer::RuntimeError> { + let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; + 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 flags1 = at_flags; + let vec2 = path; + let ptr2 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec2.len() as i32)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr2, vec2.as_bytes())?; + let (result3_0,result3_1,) = match atim { + NewTimestamp::NoChange=> { + let e = (); + { + let () = e; + (0i32, 0i64) + } + } + NewTimestamp::Now=> { + let e = (); + { + let () = e; + (1i32, 0i64) + } + } + NewTimestamp::Timestamp(e) => (2i32, wit_bindgen_wasmer::rt::as_i64(e)), + }; + let (result4_0,result4_1,) = match mtim { + NewTimestamp::NoChange=> { + let e = (); + { + let () = e; + (0i32, 0i64) + } + } + NewTimestamp::Now=> { + let e = (); + { + let () = e; + (1i32, 0i64) + } + } + NewTimestamp::Timestamp(e) => (2i32, wit_bindgen_wasmer::rt::as_i64(e)), + }; + let result5 = self.func_descriptor_set_times_at.call(store, handle0 as i32, (flags1.bits >> 0) as i32, ptr2, vec2.len() as i32, result3_0, result3_1, result4_0, result4_1, )?; + let _memory_view = _memory.view(&store); + let load6 = unsafe { _memory_view.data_unchecked_mut() }.load::(result5 + 0)?; + Ok(match i32::from(load6) { + 0 => Ok(()), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load7 = unsafe { _memory_view.data_unchecked_mut() }.load::(result5 + 1)?; + match i32::from(load7) { + 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")), + }) + } + /// Create a hard link. + /// + /// Note: This is similar to `linkat` in POSIX. + pub fn descriptor_link_at(&self, store: &mut wasmer::Store,self_: & Descriptor,old_at_flags: AtFlags,old_path: & str,new_descriptor: & Descriptor,new_path: & str,)-> Result, wasmer::RuntimeError> { + let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; + 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 flags1 = old_at_flags; + let vec2 = old_path; + let ptr2 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec2.len() as i32)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr2, vec2.as_bytes())?; + + let obj3 = new_descriptor; + let handle3 = { + let state = self.env.as_mut(store); + state.resource_slab0.clone(obj3.0)?; + state.index_slab0.insert(obj3.0) + }; + let vec4 = new_path; + let ptr4 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec4.len() as i32)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr4, vec4.as_bytes())?; + let result5 = self.func_descriptor_link_at.call(store, handle0 as i32, (flags1.bits >> 0) as i32, ptr2, vec2.len() as i32, handle3 as i32, ptr4, vec4.len() as i32, )?; + let _memory_view = _memory.view(&store); + let load6 = unsafe { _memory_view.data_unchecked_mut() }.load::(result5 + 0)?; + Ok(match i32::from(load6) { + 0 => Ok(()), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load7 = unsafe { _memory_view.data_unchecked_mut() }.load::(result5 + 1)?; + match i32::from(load7) { + 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")), + }) + } + /// 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. + pub fn descriptor_open_at(&self, store: &mut wasmer::Store,self_: & Descriptor,at_flags: AtFlags,path: & str,o_flags: OFlags,flags: Flags,mode: Mode,)-> Result, wasmer::RuntimeError> { + let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; + 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 flags1 = at_flags; + let vec2 = path; + let ptr2 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec2.len() as i32)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr2, vec2.as_bytes())?; + let flags3 = o_flags; + let flags4 = flags; + let flags5 = mode; + let result6 = self.func_descriptor_open_at.call(store, handle0 as i32, (flags1.bits >> 0) as i32, ptr2, vec2.len() as i32, (flags3.bits >> 0) as i32, (flags4.bits >> 0) as i32, (flags5.bits >> 0) as i32, )?; + let _memory_view = _memory.view(&store); + let load7 = unsafe { _memory_view.data_unchecked_mut() }.load::(result6 + 0)?; + Ok(match i32::from(load7) { + 0 => Ok({ + let _memory_view = _memory.view(&store); + let load8 = unsafe { _memory_view.data_unchecked_mut() }.load::(result6 + 4)?; + let state = self.env.as_mut(store); + let handle9 = state.index_slab0.remove(load8 as u32)?; + Descriptor(handle9) + }), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load10 = unsafe { _memory_view.data_unchecked_mut() }.load::(result6 + 4)?; + match i32::from(load10) { + 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")), + }) + } + /// Read the contents of a symbolic link. + /// + /// Note: This is similar to `readlinkat` in POSIX. + pub fn descriptor_readlink_at(&self, store: &mut wasmer::Store,self_: & Descriptor,path: & str,)-> Result, wasmer::RuntimeError> { + let func_canonical_abi_free = &self.func_canonical_abi_free; + let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; + 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 vec1 = path; + let ptr1 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec1.len() as i32)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr1, vec1.as_bytes())?; + let result2 = self.func_descriptor_readlink_at.call(store, handle0 as i32, ptr1, vec1.len() as i32, )?; + let _memory_view = _memory.view(&store); + let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 0)?; + Ok(match i32::from(load3) { + 0 => Ok({ + let _memory_view = _memory.view(&store); + let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 4)?; + let _memory_view = _memory.view(&store); + let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 8)?; + let ptr6 = load4; + let len6 = load5; + + let data6 = copy_slice( + store, + _memory, + func_canonical_abi_free, + ptr6, len6, 1, + )?; + String::from_utf8(data6) + .map_err(|_| wasmer::RuntimeError::new("invalid utf-8"))? + }), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load7 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 4)?; + match i32::from(load7) { + 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")), + }) + } + /// Remove a directory. + /// + /// Return `errno::notempty` if the directory is not empty. + /// + /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. + pub fn descriptor_remove_directory_at(&self, store: &mut wasmer::Store,self_: & Descriptor,path: & str,)-> Result, wasmer::RuntimeError> { + let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; + 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 vec1 = path; + let ptr1 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec1.len() as i32)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr1, vec1.as_bytes())?; + let result2 = self.func_descriptor_remove_directory_at.call(store, handle0 as i32, ptr1, vec1.len() as i32, )?; + let _memory_view = _memory.view(&store); + let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 0)?; + Ok(match i32::from(load3) { + 0 => Ok(()), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 1)?; + match i32::from(load4) { + 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")), + }) + } + /// Rename a filesystem object. + /// + /// Note: This is similar to `renameat` in POSIX. + pub fn descriptor_rename_at(&self, store: &mut wasmer::Store,self_: & Descriptor,old_path: & str,new_descriptor: & Descriptor,new_path: & str,)-> Result, wasmer::RuntimeError> { + let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; + 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 vec1 = old_path; + let ptr1 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec1.len() as i32)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr1, vec1.as_bytes())?; + + let obj2 = new_descriptor; + let handle2 = { + let state = self.env.as_mut(store); + state.resource_slab0.clone(obj2.0)?; + state.index_slab0.insert(obj2.0) + }; + let vec3 = new_path; + let ptr3 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec3.len() as i32)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr3, vec3.as_bytes())?; + let result4 = self.func_descriptor_rename_at.call(store, handle0 as i32, ptr1, vec1.len() as i32, handle2 as i32, ptr3, vec3.len() as i32, )?; + let _memory_view = _memory.view(&store); + let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result4 + 0)?; + Ok(match i32::from(load5) { + 0 => Ok(()), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load6 = unsafe { _memory_view.data_unchecked_mut() }.load::(result4 + 1)?; + match i32::from(load6) { + 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")), + }) + } + /// Create a symbolic link. + /// + /// Note: This is similar to `symlinkat` in POSIX. + pub fn descriptor_symlink_at(&self, store: &mut wasmer::Store,self_: & Descriptor,old_path: & str,new_path: & str,)-> Result, wasmer::RuntimeError> { + let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; + 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 vec1 = old_path; + let ptr1 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec1.len() as i32)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr1, vec1.as_bytes())?; + let vec2 = new_path; + let ptr2 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec2.len() as i32)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr2, vec2.as_bytes())?; + let result3 = self.func_descriptor_symlink_at.call(store, handle0 as i32, ptr1, vec1.len() as i32, ptr2, vec2.len() as i32, )?; + let _memory_view = _memory.view(&store); + let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 0)?; + Ok(match i32::from(load4) { + 0 => Ok(()), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 1)?; + match i32::from(load5) { + 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")), + }) + } + /// 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. + pub fn descriptor_unlink_file_at(&self, store: &mut wasmer::Store,self_: & Descriptor,path: & str,)-> Result, wasmer::RuntimeError> { + let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; + 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 vec1 = path; + let ptr1 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec1.len() as i32)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr1, vec1.as_bytes())?; + let result2 = self.func_descriptor_unlink_file_at.call(store, handle0 as i32, ptr1, vec1.len() as i32, )?; + let _memory_view = _memory.view(&store); + let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 0)?; + Ok(match i32::from(load3) { + 0 => Ok(()), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 1)?; + match i32::from(load4) { + 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")), + }) + } + /// 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. + pub fn descriptor_change_file_permissions_at(&self, store: &mut wasmer::Store,self_: & Descriptor,at_flags: AtFlags,path: & str,mode: Mode,)-> Result, wasmer::RuntimeError> { + let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; + 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 flags1 = at_flags; + let vec2 = path; + let ptr2 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec2.len() as i32)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr2, vec2.as_bytes())?; + let flags3 = mode; + let result4 = self.func_descriptor_change_file_permissions_at.call(store, handle0 as i32, (flags1.bits >> 0) as i32, ptr2, vec2.len() as i32, (flags3.bits >> 0) as i32, )?; + let _memory_view = _memory.view(&store); + let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result4 + 0)?; + Ok(match i32::from(load5) { + 0 => Ok(()), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load6 = unsafe { _memory_view.data_unchecked_mut() }.load::(result4 + 1)?; + match i32::from(load6) { + 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")), + }) + } + /// 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. + pub fn descriptor_change_directory_permissions_at(&self, store: &mut wasmer::Store,self_: & Descriptor,at_flags: AtFlags,path: & str,mode: Mode,)-> Result, wasmer::RuntimeError> { + let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; + 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 flags1 = at_flags; + let vec2 = path; + let ptr2 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec2.len() as i32)?; + let _memory_view = _memory.view(&store); + unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr2, vec2.as_bytes())?; + let flags3 = mode; + let result4 = self.func_descriptor_change_directory_permissions_at.call(store, handle0 as i32, (flags1.bits >> 0) as i32, ptr2, vec2.len() as i32, (flags3.bits >> 0) as i32, )?; + let _memory_view = _memory.view(&store); + let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result4 + 0)?; + Ok(match i32::from(load5) { + 0 => Ok(()), + 1 => Err({ + let _memory_view = _memory.view(&store); + let load6 = unsafe { _memory_view.data_unchecked_mut() }.load::(result4 + 1)?; + match i32::from(load6) { + 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. @@ -811,4 +3311,6 @@ pub mod wasi_filesystem { use wasmer::AsStoreRef as _; use wit_bindgen_wasmer::rt::RawMem; use wit_bindgen_wasmer::rt::invalid_variant; + use wit_bindgen_wasmer::rt::validate_flags; + use wit_bindgen_wasmer::rt::copy_slice; } 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 index c896660823f..f8c658ea1b1 100644 --- a/lib/wasi-types-generated/src/wasi_io_typenames/mod.rs +++ b/lib/wasi-types-generated/src/wasi_io_typenames/mod.rs @@ -1,2 +1,2 @@ -mod bindings; -pub use bindings::wasi_io_typenames::*; +// mod bindings; +// pub use bindings::wasi_io_typenames::*; diff --git a/lib/wasi-types-generated/src/wasi_snapshot0/mod.rs b/lib/wasi-types-generated/src/wasi_snapshot0/mod.rs index 76d241271b0..182d1716c56 100644 --- a/lib/wasi-types-generated/src/wasi_snapshot0/mod.rs +++ b/lib/wasi-types-generated/src/wasi_snapshot0/mod.rs @@ -1,2 +1,2 @@ -mod bindings; -pub use bindings::wasi_snapshot0::*; +// mod bindings; +// pub use bindings::wasi_snapshot0::*; diff --git a/lib/wasi-types-generated/wit/wasi-filesystem.wit b/lib/wasi-types-generated/wit/wasi-filesystem.wit index c5154f03793..78be8e6ce7e 100644 --- a/lib/wasi-types-generated/wit/wasi-filesystem.wit +++ b/lib/wasi-types-generated/wit/wasi-filesystem.wit @@ -355,272 +355,272 @@ resource descriptor { 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 + /// 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 index c0eb25ef25a..e1aae1bc3b4 100644 --- a/lib/wasi-types-generated/wit/wasi-io-typenames.wit +++ b/lib/wasi-types-generated/wit/wasi-io-typenames.wit @@ -1,109 +1,103 @@ // 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. +/// Size of a range of bytes in memory. +type size = u32 + +/// A region of memory for scatter/gather reads. +record iovec { + /// The address of the buffer to be filled. + /// TODO: (field $buf (@witx pointer u8)) + /// wit has no "pointer" + /// pointer + buf: size, + /// The length of the buffer to be filled. + buf_len: size, +} + +/// A region of memory for scatter/gather writes. +record ciovec { + /// The address of the buffer to be written. + /// TODO: (field $buf (field $buf (@witx const_pointer u8))): wit has no "pointer" + buf: size, + /// The length of the buffer to be written. + buf_len: size, +} + +type iovec_array: list + +type ciovec_array: list + +/// Relative offset within a file. +type filedelta = s64 + +/// The position relative to which to set the offset of the file descriptor. +enum whence { + /// 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. +type linkcount = s64 + +/// 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. +/// +/// TODO: (@witx repr u8) +flags permissions { + /// 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. +record filestat { + /// Device ID of device containing the file. + $dev $device) + /// File serial number. + $ino $inode) + /// File type. + $filetype $filetype) + /// File permissions. + $permissions $permissions) + /// 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) +} + +// +// ;;; // (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) + // ) // ) // From d3fac0ce1bf590ff33c7b887d4082c1e35d09bc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Wed, 31 Aug 2022 12:52:48 +0200 Subject: [PATCH 43/44] 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 ce7576565d3928abf0f87e1d80b2ece9a0916916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Fri, 2 Sep 2022 20:32:51 +0200 Subject: [PATCH 44/44] Meeting discussion --- Cargo.lock | 243 +- lib/wasi-types-generated/Cargo.toml | 9 +- lib/wasi-types-generated/regenerate.sh | 21 +- lib/wasi-types-generated/src/wasi/bindings.rs | 672 ++-- .../src/wasi_filesystem/bindings.rs | 3316 ----------------- .../src/wasi_filesystem/mod.rs | 2 - .../src/wasi_io_typenames/mod.rs | 2 - .../src/wasi_snapshot0/bindings.rs | 9 - .../src/wasi_snapshot0/mod.rs | 2 - .../{wit/wasi.wit => wit-clean/typenames.wit} | 0 .../wit-clean/wasi_unstable.wit | 3 + .../wit/wasi-io-typenames.wit | 8 +- 12 files changed, 383 insertions(+), 3904 deletions(-) delete mode 100644 lib/wasi-types-generated/src/wasi_filesystem/bindings.rs delete mode 100644 lib/wasi-types-generated/src/wasi_snapshot0/bindings.rs rename lib/wasi-types-generated/{wit/wasi.wit => wit-clean/typenames.wit} (100%) create mode 100644 lib/wasi-types-generated/wit-clean/wasi_unstable.wit diff --git a/Cargo.lock b/Cargo.lock index 5a22999ce98..748f1311862 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2996,35 +2996,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 +3015,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 +3038,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 +3059,7 @@ dependencies = [ "rand", "tempfile", "thiserror", - "wasmer 3.0.0-beta", + "wasmer", "wasmer-compiler-singlepass", ] @@ -3104,17 +3082,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 +3118,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 +3140,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 +3161,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 +3182,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 +3201,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 +3214,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 +3227,8 @@ dependencies = [ "libc", "log", "time", - "wasmer 3.0.0-beta", - "wasmer-types 3.0.0-beta", + "wasmer", + "wasmer-types", ] [[package]] @@ -3322,9 +3248,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 +3259,7 @@ version = "3.0.0-beta" dependencies = [ "object 0.28.4", "thiserror", - "wasmer-types 3.0.0-beta", + "wasmer-types", ] [[package]] @@ -3352,20 +3278,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 +3317,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 +3349,7 @@ dependencies = [ "typetag", "wasm-bindgen", "wasm-bindgen-test", - "wasmer 3.0.0-beta", + "wasmer", "wasmer-vbus", "wasmer-vfs", "wasmer-vnet", @@ -3500,8 +3389,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 +3398,9 @@ 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-derive", + "wasmer-types", + "wit-bindgen-gen-rust-wasm", ] [[package]] @@ -3522,7 +3411,7 @@ dependencies = [ "serde", "tempfile", "thiserror", - "wasmer 3.0.0-beta", + "wasmer", "wasmer-vfs", "wasmer-wasi", "wast 38.0.1", @@ -3547,15 +3436,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", ] @@ -3852,7 +3741,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" +source = "git+https://github.com/wasmerio/wit-bindgen.git?branch=main#005a9e6d5befe4652c0e6e05578b245ab96b3cea" dependencies = [ "anyhow", "wit-parser", @@ -3861,50 +3750,26 @@ 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" +source = "git+https://github.com/wasmerio/wit-bindgen.git?branch=main#005a9e6d5befe4652c0e6e05578b245ab96b3cea" dependencies = [ "heck 0.3.3", "wit-bindgen-gen-core", ] [[package]] -name = "wit-bindgen-gen-wasmer" +name = "wit-bindgen-gen-rust-wasm" 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.git?branch=main#005a9e6d5befe4652c0e6e05578b245ab96b3cea" 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" +source = "git+https://github.com/wasmerio/wit-bindgen.git?branch=main#005a9e6d5befe4652c0e6e05578b245ab96b3cea" dependencies = [ "anyhow", "id-arena", diff --git a/lib/wasi-types-generated/Cargo.toml b/lib/wasi-types-generated/Cargo.toml index 74e0418dd04..20d4b359c14 100644 --- a/lib/wasi-types-generated/Cargo.toml +++ b/lib/wasi-types-generated/Cargo.toml @@ -9,11 +9,12 @@ edition = "2018" wasmer-derive = { path = "../derive", version = "=3.0.0-beta" } wasmer-types = { path = "../types", version = "=3.0.0-beta" } -[dependencies.wit-bindgen-wasmer] +[dependencies.wit-bindgen-rust] default-features = false git = "https://github.com/wasmerio/wit-bindgen.git" -branch = "silwol/wasi-types-generation" +branch = "main" +package = "wit-bindgen-gen-rust-wasm" [features] -js = ["wit-bindgen-wasmer/js"] -sys = ["wit-bindgen-wasmer/sys"] +js = [] +sys = [] \ No newline at end of file diff --git a/lib/wasi-types-generated/regenerate.sh b/lib/wasi-types-generated/regenerate.sh index ac5748ec826..b83f7f7884e 100755 --- a/lib/wasi-types-generated/regenerate.sh +++ b/lib/wasi-types-generated/regenerate.sh @@ -6,24 +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 \ - --out-dir "$BASEDIR"/src/wasi_filesystem +# TODO: merge typenames.wit and wasi_unstable.wit -wit-bindgen wasmer \ +wit-bindgen rust-wasm \ --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 + "$BASEDIR"/wit-clean/typenames.wit \ + --out-dir "$BASEDIR"/src/wasi #wit-bindgen rust-wasm --import wit/wasi-snapshot0.wit wit/wasi-filesystem.wit --out-dir . diff --git a/lib/wasi-types-generated/src/wasi/bindings.rs b/lib/wasi-types-generated/src/wasi/bindings.rs index 8ec7e7e9370..74825629268 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}; +mod typenames { /// 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 = TYPENAMES_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 = "typenames")] + extern "C" { + #[cfg_attr(target_arch = "wasm32", link_name = "expose-types-dummy-func")] + #[cfg_attr(not(target_arch = "wasm32"), link_name = "typenames_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 TYPENAMES_RET_AREA: RetArea = RetArea([0; 472]); } 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 dddfa94a17f..00000000000 --- a/lib/wasi-types-generated/src/wasi_filesystem/bindings.rs +++ /dev/null @@ -1,3316 +0,0 @@ -#[allow(clippy::all)] -pub mod wasi_filesystem { - #[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; - /// Relative offset within a file. - pub type Filedelta = i64; - /// Timestamp in nanoseconds. - /// - /// TODO: wasi-clocks is moving to seconds+nanoseconds. - pub type Timestamp = u64; - /// Information associated with a descriptor. - /// - /// Note: This was called `fdstat` in earlier versions of WASI. - #[repr(C)] - #[derive(Copy, Clone)] - pub struct Info { - /// The type of filesystem object referenced by a descriptor. - pub type_: Type, - /// Flags associated with a descriptor. - pub flags: Flags, - } - impl core::fmt::Debug for Info { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.debug_struct("Info").field("type", &self.type_).field("flags", &self.flags).finish()} - } - /// 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(())} - } - - /// File attributes. - /// - /// Note: This was called `filestat` in earlier versions of WASI. - #[repr(C)] - #[derive(Copy, Clone)] - pub struct Stat { - /// Device ID of device containing the file. - pub dev: Device, - /// File serial number. - pub ino: Inode, - /// File type. - pub type_: Type, - /// Number of hard links to the file. - pub 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. - pub size: Filesize, - /// Last data access timestamp. - pub atim: Timestamp, - /// Last data modification timestamp. - pub mtim: Timestamp, - /// Last file status change timestamp. - pub ctim: Timestamp, - } - impl core::fmt::Debug for Stat { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.debug_struct("Stat").field("dev", &self.dev).field("ino", &self.ino).field("type", &self.type_).field("nlink", &self.nlink).field("size", &self.size).field("atim", &self.atim).field("mtim", &self.mtim).field("ctim", &self.ctim).finish()} - } - 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(())} - } - - /// Number of hard links to an inode. - pub 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. - pub type Device = u64; - /// Filesystem object serial number that is unique within its file system. - pub type Inode = u64; - /// When setting a timestamp, this gives the value to set it to. - #[derive(Clone, Copy)] - pub enum NewTimestamp{ - /// Leave the timestamp set to its previous value. - NoChange, - /// 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), - } - impl core::fmt::Debug for NewTimestamp { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - NewTimestamp::NoChange => { - f.debug_tuple("NewTimestamp::NoChange").finish() - } - NewTimestamp::Now => { - f.debug_tuple("NewTimestamp::Now").finish() - } - NewTimestamp::Timestamp(e) => { - f.debug_tuple("NewTimestamp::Timestamp").field(e).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, - } - 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() - } - } - } - } - /// The position relative to which to set the offset of the descriptor. - #[derive(Clone, Copy)] - pub enum SeekFrom{ - /// Seek relative to start-of-file. - Set(Filesize), - /// Seek relative to current position. - Cur(Filedelta), - /// Seek relative to end-of-file. - End(Filesize), - } - impl core::fmt::Debug for SeekFrom { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - SeekFrom::Set(e) => { - f.debug_tuple("SeekFrom::Set").field(e).finish() - } - SeekFrom::Cur(e) => { - f.debug_tuple("SeekFrom::Cur").field(e).finish() - } - SeekFrom::End(e) => { - f.debug_tuple("SeekFrom::End").field(e).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_canonical_abi_free: wasmer::TypedFunction<(i32, i32, i32), ()>, - func_canonical_abi_realloc: wasmer::TypedFunction<(i32, i32, i32, i32), i32>, - func_descriptor_change_directory_permissions_at: wasmer::TypedFunction<(i32,i32,i32,i32,i32,), i32>, - func_descriptor_change_file_permissions_at: wasmer::TypedFunction<(i32,i32,i32,i32,i32,), i32>, - func_descriptor_create_directory_at: wasmer::TypedFunction<(i32,i32,i32,), i32>, - func_descriptor_datasync: wasmer::TypedFunction, - func_descriptor_fadvise: wasmer::TypedFunction<(i32,i64,i64,i32,), i32>, - func_descriptor_fallocate: wasmer::TypedFunction<(i32,i64,i64,), i32>, - func_descriptor_info: wasmer::TypedFunction, - func_descriptor_link_at: wasmer::TypedFunction<(i32,i32,i32,i32,i32,i32,i32,), i32>, - func_descriptor_open_at: wasmer::TypedFunction<(i32,i32,i32,i32,i32,i32,i32,), i32>, - func_descriptor_readlink_at: wasmer::TypedFunction<(i32,i32,i32,), i32>, - func_descriptor_remove_directory_at: wasmer::TypedFunction<(i32,i32,i32,), i32>, - func_descriptor_rename_at: wasmer::TypedFunction<(i32,i32,i32,i32,i32,i32,), i32>, - func_descriptor_seek: wasmer::TypedFunction<(i32,i32,i64,), i32>, - func_descriptor_set_size: wasmer::TypedFunction<(i32,i64,), i32>, - func_descriptor_set_times: wasmer::TypedFunction<(i32,i32,i64,i32,i64,), i32>, - func_descriptor_set_times_at: wasmer::TypedFunction<(i32,i32,i32,i32,i32,i64,i32,i64,), i32>, - func_descriptor_stat_at: wasmer::TypedFunction<(i32,i32,i32,i32,), i32>, - func_descriptor_symlink_at: wasmer::TypedFunction<(i32,i32,i32,i32,i32,), i32>, - func_descriptor_sync: wasmer::TypedFunction, - func_descriptor_tell: wasmer::TypedFunction, - func_descriptor_unlink_file_at: wasmer::TypedFunction<(i32,i32,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_canonical_abi_free= _instance.exports.get_typed_function(&store, "canonical_abi_free")?; - let func_canonical_abi_realloc= _instance.exports.get_typed_function(&store, "canonical_abi_realloc")?; - let func_descriptor_change_directory_permissions_at= _instance.exports.get_typed_function(&store, "descriptor::change-directory-permissions-at")?; - let func_descriptor_change_file_permissions_at= _instance.exports.get_typed_function(&store, "descriptor::change-file-permissions-at")?; - let func_descriptor_create_directory_at= _instance.exports.get_typed_function(&store, "descriptor::create-directory-at")?; - let func_descriptor_datasync= _instance.exports.get_typed_function(&store, "descriptor::datasync")?; - let func_descriptor_fadvise= _instance.exports.get_typed_function(&store, "descriptor::fadvise")?; - let func_descriptor_fallocate= _instance.exports.get_typed_function(&store, "descriptor::fallocate")?; - let func_descriptor_info= _instance.exports.get_typed_function(&store, "descriptor::info")?; - let func_descriptor_link_at= _instance.exports.get_typed_function(&store, "descriptor::link-at")?; - let func_descriptor_open_at= _instance.exports.get_typed_function(&store, "descriptor::open-at")?; - let func_descriptor_readlink_at= _instance.exports.get_typed_function(&store, "descriptor::readlink-at")?; - let func_descriptor_remove_directory_at= _instance.exports.get_typed_function(&store, "descriptor::remove-directory-at")?; - let func_descriptor_rename_at= _instance.exports.get_typed_function(&store, "descriptor::rename-at")?; - let func_descriptor_seek= _instance.exports.get_typed_function(&store, "descriptor::seek")?; - let func_descriptor_set_size= _instance.exports.get_typed_function(&store, "descriptor::set-size")?; - let func_descriptor_set_times= _instance.exports.get_typed_function(&store, "descriptor::set-times")?; - let func_descriptor_set_times_at= _instance.exports.get_typed_function(&store, "descriptor::set-times-at")?; - let func_descriptor_stat_at= _instance.exports.get_typed_function(&store, "descriptor::stat-at")?; - let func_descriptor_symlink_at= _instance.exports.get_typed_function(&store, "descriptor::symlink-at")?; - let func_descriptor_sync= _instance.exports.get_typed_function(&store, "descriptor::sync")?; - let func_descriptor_tell= _instance.exports.get_typed_function(&store, "descriptor::tell")?; - let func_descriptor_unlink_file_at= _instance.exports.get_typed_function(&store, "descriptor::unlink-file-at")?; - let memory= _instance.exports.get_memory("memory")?.clone(); - Ok(WasiFilesystem{ - func_canonical_abi_free, - func_canonical_abi_realloc, - func_descriptor_change_directory_permissions_at, - func_descriptor_change_file_permissions_at, - func_descriptor_create_directory_at, - func_descriptor_datasync, - func_descriptor_fadvise, - func_descriptor_fallocate, - func_descriptor_info, - func_descriptor_link_at, - func_descriptor_open_at, - func_descriptor_readlink_at, - func_descriptor_remove_directory_at, - func_descriptor_rename_at, - func_descriptor_seek, - func_descriptor_set_size, - func_descriptor_set_times, - func_descriptor_set_times_at, - func_descriptor_stat_at, - func_descriptor_symlink_at, - func_descriptor_sync, - func_descriptor_tell, - func_descriptor_unlink_file_at, - 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")), - }) - } - /// Force the allocation of space in a file. - /// - /// Note: This is similar to `posix_fallocate` in POSIX. - pub fn descriptor_fallocate(&self, store: &mut wasmer::Store,self_: & Descriptor,offset: Filesize,len: Filesize,)-> 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_fallocate.call(store, handle0 as i32, wit_bindgen_wasmer::rt::as_i64(offset), wit_bindgen_wasmer::rt::as_i64(len), )?; - 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")), - }) - } - /// Synchronize the data of a file to disk. - /// - /// Note: This is similar to `fdatasync` in POSIX. - pub fn descriptor_datasync(&self, store: &mut wasmer::Store,self_: & Descriptor,)-> 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_datasync.call(store, handle0 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")), - }) - } - /// 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. - pub fn descriptor_info(&self, store: &mut wasmer::Store,self_: & Descriptor,)-> 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_info.call(store, handle0 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({ - let _memory_view = _memory.view(&store); - let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 1)?; - let _memory_view = _memory.view(&store); - let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 2)?; - Info{type_:match i32::from(load3) { - 0 => Type::Unknown, - 1 => Type::BlockDevice, - 2 => Type::CharacterDevice, - 3 => Type::Directory, - 4 => Type::Fifo, - 5 => Type::SymbolicLink, - 6 => Type::RegularFile, - 7 => Type::Socket, - _ => return Err(invalid_variant("Type")), - }, flags:validate_flags( - 0| ((i32::from(load4) as u8) << 0), - Flags::all().bits(), - "Flags", - |bits| Flags { bits } - )?, } - }), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 1)?; - match i32::from(load5) { - 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")), - }) - } - /// 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. - pub fn descriptor_set_size(&self, store: &mut wasmer::Store,self_: & Descriptor,size: Filesize,)-> 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_set_size.call(store, handle0 as i32, wit_bindgen_wasmer::rt::as_i64(size), )?; - 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")), - }) - } - /// 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. - pub fn descriptor_set_times(&self, store: &mut wasmer::Store,self_: & Descriptor,atim: NewTimestamp,mtim: NewTimestamp,)-> 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_0,result1_1,) = match atim { - NewTimestamp::NoChange=> { - let e = (); - { - let () = e; - (0i32, 0i64) - } - } - NewTimestamp::Now=> { - let e = (); - { - let () = e; - (1i32, 0i64) - } - } - NewTimestamp::Timestamp(e) => (2i32, wit_bindgen_wasmer::rt::as_i64(e)), - }; - let (result2_0,result2_1,) = match mtim { - NewTimestamp::NoChange=> { - let e = (); - { - let () = e; - (0i32, 0i64) - } - } - NewTimestamp::Now=> { - let e = (); - { - let () = e; - (1i32, 0i64) - } - } - NewTimestamp::Timestamp(e) => (2i32, wit_bindgen_wasmer::rt::as_i64(e)), - }; - let result3 = self.func_descriptor_set_times.call(store, handle0 as i32, result1_0, result1_1, result2_0, result2_1, )?; - let _memory_view = _memory.view(&store); - let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 0)?; - Ok(match i32::from(load4) { - 0 => Ok(()), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 1)?; - match i32::from(load5) { - 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")), - }) - } - /// 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. - pub fn descriptor_seek(&self, store: &mut wasmer::Store,self_: & Descriptor,from: SeekFrom,)-> 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_0,result1_1,) = match from { - SeekFrom::Set(e) => (0i32, wit_bindgen_wasmer::rt::as_i64(e)), - SeekFrom::Cur(e) => (1i32, wit_bindgen_wasmer::rt::as_i64(e)), - SeekFrom::End(e) => (2i32, wit_bindgen_wasmer::rt::as_i64(e)), - }; - let result2 = self.func_descriptor_seek.call(store, handle0 as i32, result1_0, result1_1, )?; - let _memory_view = _memory.view(&store); - let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 0)?; - Ok(match i32::from(load3) { - 0 => Ok({ - let _memory_view = _memory.view(&store); - let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 8)?; - load4 as u64 - }), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 8)?; - match i32::from(load5) { - 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")), - }) - } - /// Synchronize the data and metadata of a file to disk. - /// - /// Note: This is similar to `fsync` in POSIX. - pub fn descriptor_sync(&self, store: &mut wasmer::Store,self_: & Descriptor,)-> 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_sync.call(store, handle0 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")), - }) - } - /// 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. - pub fn descriptor_tell(&self, store: &mut wasmer::Store,self_: & Descriptor,)-> 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_tell.call(store, handle0 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({ - let _memory_view = _memory.view(&store); - let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 8)?; - load3 as u64 - }), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result1 + 8)?; - match i32::from(load4) { - 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")), - }) - } - /// Create a directory. - /// - /// Note: This is similar to `mkdirat` in POSIX. - pub fn descriptor_create_directory_at(&self, store: &mut wasmer::Store,self_: & Descriptor,path: & str,)-> Result, wasmer::RuntimeError> { - let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; - 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 vec1 = path; - let ptr1 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec1.len() as i32)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr1, vec1.as_bytes())?; - let result2 = self.func_descriptor_create_directory_at.call(store, handle0 as i32, ptr1, vec1.len() as i32, )?; - let _memory_view = _memory.view(&store); - let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 0)?; - Ok(match i32::from(load3) { - 0 => Ok(()), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 1)?; - match i32::from(load4) { - 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")), - }) - } - /// 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. - pub fn descriptor_stat_at(&self, store: &mut wasmer::Store,self_: & Descriptor,at_flags: AtFlags,path: & str,)-> Result, wasmer::RuntimeError> { - let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; - 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 flags1 = at_flags; - let vec2 = path; - let ptr2 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec2.len() as i32)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr2, vec2.as_bytes())?; - let result3 = self.func_descriptor_stat_at.call(store, handle0 as i32, (flags1.bits >> 0) as i32, ptr2, vec2.len() as i32, )?; - let _memory_view = _memory.view(&store); - let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 0)?; - Ok(match i32::from(load4) { - 0 => Ok({ - let _memory_view = _memory.view(&store); - let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 8)?; - let _memory_view = _memory.view(&store); - let load6 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 16)?; - let _memory_view = _memory.view(&store); - let load7 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 24)?; - let _memory_view = _memory.view(&store); - let load8 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 32)?; - let _memory_view = _memory.view(&store); - let load9 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 40)?; - let _memory_view = _memory.view(&store); - let load10 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 48)?; - let _memory_view = _memory.view(&store); - let load11 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 56)?; - let _memory_view = _memory.view(&store); - let load12 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 64)?; - Stat{dev:load5 as u64, ino:load6 as u64, type_:match i32::from(load7) { - 0 => Type::Unknown, - 1 => Type::BlockDevice, - 2 => Type::CharacterDevice, - 3 => Type::Directory, - 4 => Type::Fifo, - 5 => Type::SymbolicLink, - 6 => Type::RegularFile, - 7 => Type::Socket, - _ => return Err(invalid_variant("Type")), - }, nlink:load8 as u64, size:load9 as u64, atim:load10 as u64, mtim:load11 as u64, ctim:load12 as u64, } - }), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load13 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 8)?; - match i32::from(load13) { - 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")), - }) - } - /// 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. - pub fn descriptor_set_times_at(&self, store: &mut wasmer::Store,self_: & Descriptor,at_flags: AtFlags,path: & str,atim: NewTimestamp,mtim: NewTimestamp,)-> Result, wasmer::RuntimeError> { - let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; - 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 flags1 = at_flags; - let vec2 = path; - let ptr2 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec2.len() as i32)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr2, vec2.as_bytes())?; - let (result3_0,result3_1,) = match atim { - NewTimestamp::NoChange=> { - let e = (); - { - let () = e; - (0i32, 0i64) - } - } - NewTimestamp::Now=> { - let e = (); - { - let () = e; - (1i32, 0i64) - } - } - NewTimestamp::Timestamp(e) => (2i32, wit_bindgen_wasmer::rt::as_i64(e)), - }; - let (result4_0,result4_1,) = match mtim { - NewTimestamp::NoChange=> { - let e = (); - { - let () = e; - (0i32, 0i64) - } - } - NewTimestamp::Now=> { - let e = (); - { - let () = e; - (1i32, 0i64) - } - } - NewTimestamp::Timestamp(e) => (2i32, wit_bindgen_wasmer::rt::as_i64(e)), - }; - let result5 = self.func_descriptor_set_times_at.call(store, handle0 as i32, (flags1.bits >> 0) as i32, ptr2, vec2.len() as i32, result3_0, result3_1, result4_0, result4_1, )?; - let _memory_view = _memory.view(&store); - let load6 = unsafe { _memory_view.data_unchecked_mut() }.load::(result5 + 0)?; - Ok(match i32::from(load6) { - 0 => Ok(()), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load7 = unsafe { _memory_view.data_unchecked_mut() }.load::(result5 + 1)?; - match i32::from(load7) { - 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")), - }) - } - /// Create a hard link. - /// - /// Note: This is similar to `linkat` in POSIX. - pub fn descriptor_link_at(&self, store: &mut wasmer::Store,self_: & Descriptor,old_at_flags: AtFlags,old_path: & str,new_descriptor: & Descriptor,new_path: & str,)-> Result, wasmer::RuntimeError> { - let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; - 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 flags1 = old_at_flags; - let vec2 = old_path; - let ptr2 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec2.len() as i32)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr2, vec2.as_bytes())?; - - let obj3 = new_descriptor; - let handle3 = { - let state = self.env.as_mut(store); - state.resource_slab0.clone(obj3.0)?; - state.index_slab0.insert(obj3.0) - }; - let vec4 = new_path; - let ptr4 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec4.len() as i32)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr4, vec4.as_bytes())?; - let result5 = self.func_descriptor_link_at.call(store, handle0 as i32, (flags1.bits >> 0) as i32, ptr2, vec2.len() as i32, handle3 as i32, ptr4, vec4.len() as i32, )?; - let _memory_view = _memory.view(&store); - let load6 = unsafe { _memory_view.data_unchecked_mut() }.load::(result5 + 0)?; - Ok(match i32::from(load6) { - 0 => Ok(()), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load7 = unsafe { _memory_view.data_unchecked_mut() }.load::(result5 + 1)?; - match i32::from(load7) { - 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")), - }) - } - /// 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. - pub fn descriptor_open_at(&self, store: &mut wasmer::Store,self_: & Descriptor,at_flags: AtFlags,path: & str,o_flags: OFlags,flags: Flags,mode: Mode,)-> Result, wasmer::RuntimeError> { - let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; - 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 flags1 = at_flags; - let vec2 = path; - let ptr2 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec2.len() as i32)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr2, vec2.as_bytes())?; - let flags3 = o_flags; - let flags4 = flags; - let flags5 = mode; - let result6 = self.func_descriptor_open_at.call(store, handle0 as i32, (flags1.bits >> 0) as i32, ptr2, vec2.len() as i32, (flags3.bits >> 0) as i32, (flags4.bits >> 0) as i32, (flags5.bits >> 0) as i32, )?; - let _memory_view = _memory.view(&store); - let load7 = unsafe { _memory_view.data_unchecked_mut() }.load::(result6 + 0)?; - Ok(match i32::from(load7) { - 0 => Ok({ - let _memory_view = _memory.view(&store); - let load8 = unsafe { _memory_view.data_unchecked_mut() }.load::(result6 + 4)?; - let state = self.env.as_mut(store); - let handle9 = state.index_slab0.remove(load8 as u32)?; - Descriptor(handle9) - }), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load10 = unsafe { _memory_view.data_unchecked_mut() }.load::(result6 + 4)?; - match i32::from(load10) { - 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")), - }) - } - /// Read the contents of a symbolic link. - /// - /// Note: This is similar to `readlinkat` in POSIX. - pub fn descriptor_readlink_at(&self, store: &mut wasmer::Store,self_: & Descriptor,path: & str,)-> Result, wasmer::RuntimeError> { - let func_canonical_abi_free = &self.func_canonical_abi_free; - let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; - 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 vec1 = path; - let ptr1 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec1.len() as i32)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr1, vec1.as_bytes())?; - let result2 = self.func_descriptor_readlink_at.call(store, handle0 as i32, ptr1, vec1.len() as i32, )?; - let _memory_view = _memory.view(&store); - let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 0)?; - Ok(match i32::from(load3) { - 0 => Ok({ - let _memory_view = _memory.view(&store); - let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 4)?; - let _memory_view = _memory.view(&store); - let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 8)?; - let ptr6 = load4; - let len6 = load5; - - let data6 = copy_slice( - store, - _memory, - func_canonical_abi_free, - ptr6, len6, 1, - )?; - String::from_utf8(data6) - .map_err(|_| wasmer::RuntimeError::new("invalid utf-8"))? - }), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load7 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 4)?; - match i32::from(load7) { - 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")), - }) - } - /// Remove a directory. - /// - /// Return `errno::notempty` if the directory is not empty. - /// - /// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. - pub fn descriptor_remove_directory_at(&self, store: &mut wasmer::Store,self_: & Descriptor,path: & str,)-> Result, wasmer::RuntimeError> { - let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; - 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 vec1 = path; - let ptr1 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec1.len() as i32)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr1, vec1.as_bytes())?; - let result2 = self.func_descriptor_remove_directory_at.call(store, handle0 as i32, ptr1, vec1.len() as i32, )?; - let _memory_view = _memory.view(&store); - let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 0)?; - Ok(match i32::from(load3) { - 0 => Ok(()), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 1)?; - match i32::from(load4) { - 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")), - }) - } - /// Rename a filesystem object. - /// - /// Note: This is similar to `renameat` in POSIX. - pub fn descriptor_rename_at(&self, store: &mut wasmer::Store,self_: & Descriptor,old_path: & str,new_descriptor: & Descriptor,new_path: & str,)-> Result, wasmer::RuntimeError> { - let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; - 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 vec1 = old_path; - let ptr1 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec1.len() as i32)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr1, vec1.as_bytes())?; - - let obj2 = new_descriptor; - let handle2 = { - let state = self.env.as_mut(store); - state.resource_slab0.clone(obj2.0)?; - state.index_slab0.insert(obj2.0) - }; - let vec3 = new_path; - let ptr3 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec3.len() as i32)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr3, vec3.as_bytes())?; - let result4 = self.func_descriptor_rename_at.call(store, handle0 as i32, ptr1, vec1.len() as i32, handle2 as i32, ptr3, vec3.len() as i32, )?; - let _memory_view = _memory.view(&store); - let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result4 + 0)?; - Ok(match i32::from(load5) { - 0 => Ok(()), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load6 = unsafe { _memory_view.data_unchecked_mut() }.load::(result4 + 1)?; - match i32::from(load6) { - 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")), - }) - } - /// Create a symbolic link. - /// - /// Note: This is similar to `symlinkat` in POSIX. - pub fn descriptor_symlink_at(&self, store: &mut wasmer::Store,self_: & Descriptor,old_path: & str,new_path: & str,)-> Result, wasmer::RuntimeError> { - let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; - 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 vec1 = old_path; - let ptr1 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec1.len() as i32)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr1, vec1.as_bytes())?; - let vec2 = new_path; - let ptr2 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec2.len() as i32)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr2, vec2.as_bytes())?; - let result3 = self.func_descriptor_symlink_at.call(store, handle0 as i32, ptr1, vec1.len() as i32, ptr2, vec2.len() as i32, )?; - let _memory_view = _memory.view(&store); - let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 0)?; - Ok(match i32::from(load4) { - 0 => Ok(()), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result3 + 1)?; - match i32::from(load5) { - 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")), - }) - } - /// 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. - pub fn descriptor_unlink_file_at(&self, store: &mut wasmer::Store,self_: & Descriptor,path: & str,)-> Result, wasmer::RuntimeError> { - let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; - 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 vec1 = path; - let ptr1 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec1.len() as i32)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr1, vec1.as_bytes())?; - let result2 = self.func_descriptor_unlink_file_at.call(store, handle0 as i32, ptr1, vec1.len() as i32, )?; - let _memory_view = _memory.view(&store); - let load3 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 0)?; - Ok(match i32::from(load3) { - 0 => Ok(()), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load4 = unsafe { _memory_view.data_unchecked_mut() }.load::(result2 + 1)?; - match i32::from(load4) { - 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")), - }) - } - /// 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. - pub fn descriptor_change_file_permissions_at(&self, store: &mut wasmer::Store,self_: & Descriptor,at_flags: AtFlags,path: & str,mode: Mode,)-> Result, wasmer::RuntimeError> { - let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; - 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 flags1 = at_flags; - let vec2 = path; - let ptr2 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec2.len() as i32)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr2, vec2.as_bytes())?; - let flags3 = mode; - let result4 = self.func_descriptor_change_file_permissions_at.call(store, handle0 as i32, (flags1.bits >> 0) as i32, ptr2, vec2.len() as i32, (flags3.bits >> 0) as i32, )?; - let _memory_view = _memory.view(&store); - let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result4 + 0)?; - Ok(match i32::from(load5) { - 0 => Ok(()), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load6 = unsafe { _memory_view.data_unchecked_mut() }.load::(result4 + 1)?; - match i32::from(load6) { - 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")), - }) - } - /// 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. - pub fn descriptor_change_directory_permissions_at(&self, store: &mut wasmer::Store,self_: & Descriptor,at_flags: AtFlags,path: & str,mode: Mode,)-> Result, wasmer::RuntimeError> { - let func_canonical_abi_realloc = &self.func_canonical_abi_realloc; - 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 flags1 = at_flags; - let vec2 = path; - let ptr2 = func_canonical_abi_realloc.call(&mut store.as_store_mut(), 0, 0, 1, vec2.len() as i32)?; - let _memory_view = _memory.view(&store); - unsafe { _memory_view.data_unchecked_mut() }.store_many(ptr2, vec2.as_bytes())?; - let flags3 = mode; - let result4 = self.func_descriptor_change_directory_permissions_at.call(store, handle0 as i32, (flags1.bits >> 0) as i32, ptr2, vec2.len() as i32, (flags3.bits >> 0) as i32, )?; - let _memory_view = _memory.view(&store); - let load5 = unsafe { _memory_view.data_unchecked_mut() }.load::(result4 + 0)?; - Ok(match i32::from(load5) { - 0 => Ok(()), - 1 => Err({ - let _memory_view = _memory.view(&store); - let load6 = unsafe { _memory_view.data_unchecked_mut() }.load::(result4 + 1)?; - match i32::from(load6) { - 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; - use wit_bindgen_wasmer::rt::validate_flags; - use wit_bindgen_wasmer::rt::copy_slice; -} diff --git a/lib/wasi-types-generated/src/wasi_filesystem/mod.rs b/lib/wasi-types-generated/src/wasi_filesystem/mod.rs index 3092f553d6d..e69de29bb2d 100644 --- a/lib/wasi-types-generated/src/wasi_filesystem/mod.rs +++ b/lib/wasi-types-generated/src/wasi_filesystem/mod.rs @@ -1,2 +0,0 @@ -mod bindings; -pub use bindings::wasi_filesystem::*; diff --git a/lib/wasi-types-generated/src/wasi_io_typenames/mod.rs b/lib/wasi-types-generated/src/wasi_io_typenames/mod.rs index f8c658ea1b1..e69de29bb2d 100644 --- a/lib/wasi-types-generated/src/wasi_io_typenames/mod.rs +++ b/lib/wasi-types-generated/src/wasi_io_typenames/mod.rs @@ -1,2 +0,0 @@ -// mod bindings; -// pub use bindings::wasi_io_typenames::*; 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 index 182d1716c56..e69de29bb2d 100644 --- a/lib/wasi-types-generated/src/wasi_snapshot0/mod.rs +++ b/lib/wasi-types-generated/src/wasi_snapshot0/mod.rs @@ -1,2 +0,0 @@ -// mod bindings; -// pub use bindings::wasi_snapshot0::*; diff --git a/lib/wasi-types-generated/wit/wasi.wit b/lib/wasi-types-generated/wit-clean/typenames.wit similarity index 100% rename from lib/wasi-types-generated/wit/wasi.wit rename to lib/wasi-types-generated/wit-clean/typenames.wit 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..6255fc09dc0 --- /dev/null +++ b/lib/wasi-types-generated/wit-clean/wasi_unstable.wit @@ -0,0 +1,3 @@ + +// TODO: translate https://github.com/WebAssembly/WASI/blob/main/phases/old/snapshot_0/witx/wasi_unstable.witx +// if importing doesn't work, put it in typenames.wit \ No newline at end of file diff --git a/lib/wasi-types-generated/wit/wasi-io-typenames.wit b/lib/wasi-types-generated/wit/wasi-io-typenames.wit index e1aae1bc3b4..2be2ed04538 100644 --- a/lib/wasi-types-generated/wit/wasi-io-typenames.wit +++ b/lib/wasi-types-generated/wit/wasi-io-typenames.wit @@ -11,7 +11,7 @@ record iovec { /// pointer buf: size, /// The length of the buffer to be filled. - buf_len: size, + buf-len: size, } /// A region of memory for scatter/gather writes. @@ -20,12 +20,12 @@ record ciovec { /// TODO: (field $buf (field $buf (@witx const_pointer u8))): wit has no "pointer" buf: size, /// The length of the buffer to be written. - buf_len: size, + buf-len: size, } -type iovec_array: list +type iovec-array: list -type ciovec_array: list +type ciovec-array: list /// Relative offset within a file. type filedelta = s64