kobako 0.29.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +552 -10
- data/Cargo.lock +595 -139
- data/README.md +126 -564
- data/ROADMAP.md +3 -2
- data/crates/kobako-runtime/CHANGELOG.md +488 -1
- data/crates/kobako-runtime/Cargo.toml +73 -15
- data/crates/kobako-runtime/README.md +11 -4
- data/crates/kobako-runtime/src/cred.rs +124 -0
- data/crates/kobako-runtime/src/dispatch.rs +5 -6
- data/crates/kobako-runtime/src/endpoint/buffer.rs +301 -0
- data/crates/kobako-runtime/src/endpoint/dispatch.rs +292 -0
- data/crates/kobako-runtime/src/endpoint/invoke.rs +181 -0
- data/crates/kobako-runtime/src/endpoint.rs +267 -0
- data/crates/kobako-runtime/src/errno.rs +391 -0
- data/crates/kobako-runtime/src/error.rs +31 -10
- data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
- data/crates/kobako-runtime/src/filesystem/bind/fid.rs +82 -0
- data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +274 -0
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +248 -0
- data/crates/kobako-runtime/src/filesystem/bind.rs +2857 -0
- data/crates/kobako-runtime/src/filesystem/overlay/file.rs +89 -0
- data/crates/kobako-runtime/src/filesystem/overlay/inode.rs +106 -0
- data/crates/kobako-runtime/src/filesystem/overlay/path.rs +263 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +128 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +238 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +135 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +54 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +316 -739
- data/crates/kobako-runtime/src/filesystem/overlay.rs +2627 -1154
- data/crates/kobako-runtime/src/filesystem/pipe.rs +224 -0
- data/crates/kobako-runtime/src/filesystem/rdir.rs +84 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +107 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +22 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs.rs +1997 -0
- data/crates/kobako-runtime/src/filesystem/wrap.rs +208 -0
- data/crates/kobako-runtime/src/filesystem.rs +25 -388
- data/crates/kobako-runtime/src/fork.rs +96 -0
- data/crates/kobako-runtime/src/grant.rs +3 -0
- data/crates/kobako-runtime/src/hashtable.rs +46 -0
- data/crates/kobako-runtime/src/lib.rs +27 -11
- data/crates/kobako-runtime/src/limits.rs +195 -0
- data/crates/kobako-runtime/src/locking/seqlock.rs +66 -0
- data/crates/kobako-runtime/src/locking.rs +228 -0
- data/crates/kobako-runtime/src/memcg.rs +383 -0
- data/crates/kobako-runtime/src/mount.rs +86 -101
- data/crates/kobako-runtime/src/net/backends.rs +43 -0
- data/crates/kobako-runtime/src/net/connections.rs +179 -0
- data/crates/kobako-runtime/src/net/credential.rs +125 -0
- data/crates/kobako-runtime/src/net/egress.rs +160 -0
- data/crates/kobako-runtime/src/net/family.rs +181 -0
- data/crates/kobako-runtime/src/net/http.rs +2733 -0
- data/crates/kobako-runtime/src/net/lookup.rs +285 -0
- data/crates/kobako-runtime/src/net/mock.rs +251 -0
- data/crates/kobako-runtime/src/net/namespace.rs +1366 -0
- data/crates/kobako-runtime/src/net/reactor.rs +531 -0
- data/crates/kobako-runtime/src/net/resolv/darwin.rs +275 -0
- data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +469 -0
- data/crates/kobako-runtime/src/net/resolv/stub.rs +536 -0
- data/crates/kobako-runtime/src/net/resolv/windows.rs +248 -0
- data/crates/kobako-runtime/src/net/resolv.rs +227 -0
- data/crates/kobako-runtime/src/net/socket.rs +870 -0
- data/crates/kobako-runtime/src/net/tcp.rs +1588 -0
- data/crates/kobako-runtime/src/net/tls.rs +58 -0
- data/crates/kobako-runtime/src/net/transport.rs +279 -0
- data/crates/kobako-runtime/src/net/udp.rs +1003 -0
- data/crates/kobako-runtime/src/net.rs +42 -0
- data/crates/kobako-runtime/src/network/builder.rs +177 -0
- data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
- data/crates/kobako-runtime/src/network.rs +551 -0
- data/crates/kobako-runtime/src/policy.rs +16 -0
- data/crates/kobako-runtime/src/profile.rs +37 -16
- data/crates/kobako-runtime/src/runtime.rs +3 -5
- data/crates/kobako-runtime/src/sched.rs +311 -0
- data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
- data/crates/kobako-runtime/src/security/hooks.rs +242 -0
- data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
- data/crates/kobako-runtime/src/security.rs +601 -0
- data/crates/kobako-runtime/src/snapshot.rs +121 -2
- data/crates/kobako-runtime/src/vfs/attr.rs +162 -0
- data/crates/kobako-runtime/src/vfs/dentry.rs +1466 -0
- data/crates/kobako-runtime/src/vfs/file.rs +1911 -0
- data/crates/kobako-runtime/src/vfs/inode.rs +425 -0
- data/crates/kobako-runtime/src/vfs/kern_path.rs +213 -0
- data/crates/kobako-runtime/src/vfs/mount.rs +60 -0
- data/crates/kobako-runtime/src/vfs/namei.rs +5837 -0
- data/crates/kobako-runtime/src/vfs/namespace.rs +162 -0
- data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
- data/crates/kobako-runtime/src/vfs/openat2.rs +116 -0
- data/crates/kobako-runtime/src/vfs/path.rs +64 -0
- data/crates/kobako-runtime/src/vfs/readdir.rs +163 -0
- data/crates/kobako-runtime/src/vfs/stat.rs +293 -0
- data/crates/kobako-runtime/src/vfs/super_block.rs +126 -0
- data/crates/kobako-runtime/src/vfs/utimes.rs +299 -0
- data/crates/kobako-runtime/src/vfs.rs +63 -0
- data/crates/kobako-runtime/src/wait.rs +356 -0
- data/crates/kobako-transport/CHANGELOG.md +39 -2
- data/crates/kobako-transport/Cargo.toml +3 -3
- data/crates/kobako-transport/README.md +8 -8
- data/crates/kobako-transport/src/abi.rs +78 -72
- data/crates/kobako-transport/src/envelope/bytes.rs +49 -30
- data/crates/kobako-transport/src/envelope/call.rs +37 -9
- data/crates/kobako-transport/src/envelope/compile_reply.rs +2 -2
- data/crates/kobako-transport/src/envelope/error_record.rs +24 -3
- data/crates/kobako-transport/src/envelope/fault.rs +2 -2
- data/crates/kobako-transport/src/envelope/name.rs +99 -0
- data/crates/kobako-transport/src/envelope/outcome.rs +11 -11
- data/crates/kobako-transport/src/envelope/preamble.rs +34 -31
- data/crates/kobako-transport/src/envelope/reply.rs +29 -29
- data/crates/kobako-transport/src/envelope/request.rs +2 -2
- data/crates/kobako-transport/src/envelope/run.rs +1 -1
- data/crates/kobako-transport/src/envelope/unsupported.rs +12 -12
- data/crates/kobako-transport/src/envelope.rs +15 -10
- data/crates/kobako-wasmtime/CHANGELOG.md +315 -8
- data/crates/kobako-wasmtime/Cargo.toml +35 -15
- data/crates/kobako-wasmtime/README.md +11 -6
- data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
- data/crates/kobako-wasmtime/build.rs +16 -0
- data/crates/kobako-wasmtime/src/abi.rs +19 -47
- data/crates/kobako-wasmtime/src/ambient.rs +33 -19
- data/crates/kobako-wasmtime/src/cache.rs +28 -20
- data/crates/kobako-wasmtime/src/config.rs +59 -60
- data/crates/kobako-wasmtime/src/driver.rs +63 -145
- data/crates/kobako-wasmtime/src/exports.rs +147 -32
- data/crates/kobako-wasmtime/src/guest.rs +44 -0
- data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
- data/crates/kobako-wasmtime/src/imports.rs +48 -18
- data/crates/kobako-wasmtime/src/instance_pre.rs +7 -7
- data/crates/kobako-wasmtime/src/invocation.rs +93 -51
- data/crates/kobako-wasmtime/src/lib.rs +6 -7
- data/crates/kobako-wasmtime/src/limiter.rs +52 -211
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +309 -0
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +70 -57
- data/crates/kobako-wasmtime/src/preview1/differential.rs +137 -27
- data/crates/kobako-wasmtime/src/preview1/errno.rs +90 -233
- data/crates/kobako-wasmtime/src/preview1/fd.rs +1301 -522
- data/crates/kobako-wasmtime/src/preview1/memory.rs +126 -150
- data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +192 -0
- data/crates/kobako-wasmtime/src/preview1/mount_view.rs +1989 -708
- data/crates/kobako-wasmtime/src/preview1/path.rs +181 -365
- data/crates/kobako-wasmtime/src/preview1/poll.rs +345 -173
- data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -25
- data/crates/kobako-wasmtime/src/preview1/testsuite-expected.txt +6 -0
- data/crates/kobako-wasmtime/src/preview1/testsuite.rs +147 -0
- data/crates/kobako-wasmtime/src/preview1.rs +471 -416
- data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
- data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
- data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
- data/crates/kobako-wasmtime/src/preview2/host.rs +3959 -0
- data/crates/kobako-wasmtime/src/preview2/http.rs +1503 -0
- data/crates/kobako-wasmtime/src/preview2/io.rs +315 -0
- data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
- data/crates/kobako-wasmtime/src/preview2/table.rs +305 -0
- data/crates/kobako-wasmtime/src/preview2.rs +57 -0
- data/crates/kobako-wasmtime/src/trap.rs +31 -16
- data/crates/kobako-wasmtime/src/wasi.rs +238 -93
- data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
- data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
- data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
- data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
- data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
- data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
- data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
- data/crates/kobako-wasmtime/witx/typenames.witx +750 -0
- data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +441 -0
- data/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +1 -1
- data/ext/kobako/src/{runtime/errors.rs → errors.rs} +35 -27
- data/ext/kobako/src/escape.rs +98 -0
- data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +36 -16
- data/ext/kobako/src/filesystem/ruby.rs +689 -0
- data/ext/kobako/src/filesystem.rs +217 -0
- data/ext/kobako/src/gvl.rs +306 -0
- data/ext/kobako/src/lib.rs +64 -3
- data/ext/kobako/src/network/mock.rs +187 -0
- data/ext/kobako/src/network.rs +591 -0
- data/ext/kobako/src/runtime/bridge.rs +31 -30
- data/ext/kobako/src/runtime/snapshot.rs +5 -5
- data/ext/kobako/src/runtime.rs +221 -138
- data/ext/kobako/src/wire.rs +42 -0
- data/lib/kobako/catalog/extensions.rb +19 -7
- data/lib/kobako/catalog/flags.rb +4 -6
- data/lib/kobako/catalog/grants.rb +5 -4
- data/lib/kobako/catalog/handles.rb +9 -31
- data/lib/kobako/catalog/mount.rb +12 -12
- data/lib/kobako/catalog/network.rb +35 -0
- data/lib/kobako/catalog/replacements.rb +28 -0
- data/lib/kobako/catalog/services.rb +7 -21
- data/lib/kobako/catalog/snippets.rb +10 -25
- data/lib/kobako/catalog.rb +4 -1
- data/lib/kobako/codec/{utils.rb → boundary.rb} +5 -3
- data/lib/kobako/codec/decoder.rb +12 -12
- data/lib/kobako/codec/ext_types.rb +5 -7
- data/lib/kobako/codec/handle_walk.rb +5 -47
- data/lib/kobako/codec/nesting.rb +7 -7
- data/lib/kobako/codec/value_budget.rb +134 -42
- data/lib/kobako/codec.rb +1 -1
- data/lib/kobako/context.rb +28 -15
- data/lib/kobako/errors.rb +15 -12
- data/lib/kobako/extension.rb +3 -2
- data/lib/kobako/filesystem.rb +53 -15
- data/lib/kobako/handle.rb +2 -2
- data/lib/kobako/names.rb +28 -0
- data/lib/kobako/network.rb +210 -0
- data/lib/kobako/outcome.rb +7 -7
- data/lib/kobako/payload/arguments.rb +2 -2
- data/lib/kobako/pool.rb +47 -25
- data/lib/kobako/runtime.rb +3 -2
- data/lib/kobako/sandbox.rb +113 -56
- data/lib/kobako/sandbox_options.rb +41 -107
- data/lib/kobako/snippet/bytecode.rb +1 -1
- data/lib/kobako/snippet/source.rb +1 -1
- data/lib/kobako/transport/argument_wrap.rb +64 -0
- data/lib/kobako/transport/block_failure.rb +1 -1
- data/lib/kobako/transport/dispatcher.rb +10 -10
- data/lib/kobako/transport/exposure.rb +28 -17
- data/lib/kobako/transport/reflection.rb +28 -11
- data/lib/kobako/transport/run.rb +13 -28
- data/lib/kobako/transport/yielder.rb +3 -10
- data/lib/kobako/transport.rb +1 -0
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +38 -0
- data/release-please-config.json +16 -0
- data/sig/core/thread.rbs +6 -0
- data/sig/kobako/catalog/extensions.rbs +5 -3
- data/sig/kobako/catalog/grants.rbs +7 -4
- data/sig/kobako/catalog/handles.rbs +2 -4
- data/sig/kobako/catalog/mount.rbs +3 -5
- data/sig/kobako/catalog/network.rbs +20 -0
- data/sig/kobako/catalog/replacements.rbs +14 -0
- data/sig/kobako/catalog/services.rbs +1 -5
- data/sig/kobako/catalog/snippets.rbs +3 -5
- data/sig/kobako/catalog.rbs +1 -1
- data/sig/kobako/codec/boundary.rbs +9 -0
- data/sig/kobako/codec/decoder.rbs +1 -1
- data/sig/kobako/codec/handle_walk.rbs +0 -6
- data/sig/kobako/codec/nesting.rbs +2 -2
- data/sig/kobako/codec/value_budget.rbs +48 -5
- data/sig/kobako/codec.rbs +1 -2
- data/sig/kobako/context.rbs +4 -2
- data/sig/kobako/errors.rbs +4 -4
- data/sig/kobako/filesystem.rbs +38 -15
- data/sig/kobako/guest_yielder.rbs +1 -1
- data/sig/kobako/network.rbs +115 -0
- data/sig/kobako/outcome.rbs +1 -1
- data/sig/kobako/payload/arguments.rbs +1 -1
- data/sig/kobako/pool.rbs +8 -4
- data/sig/kobako/runtime.rbs +32 -3
- data/sig/kobako/sandbox.rbs +22 -7
- data/sig/kobako/sandbox_options.rbs +29 -38
- data/sig/kobako/transport/argument_wrap.rbs +15 -0
- data/sig/kobako/transport/dispatcher.rbs +2 -2
- data/sig/kobako/transport/error.rbs +1 -1
- data/sig/kobako/transport/exposure.rbs +3 -5
- data/sig/kobako/transport/reflection.rbs +12 -2
- data/sig/kobako/transport/run.rbs +3 -5
- data/sig/kobako/transport/yielder.rbs +0 -3
- data/sig/kobako/transport.rbs +2 -2
- data/sig/kobako.rbs +13 -0
- metadata +131 -34
- data/crates/kobako-runtime/src/filesystem/directory/spelling.rs +0 -194
- data/crates/kobako-runtime/src/filesystem/directory.rs +0 -1082
- data/crates/kobako-runtime/src/filesystem/memory.rs +0 -1100
- data/crates/kobako-runtime/src/filesystem/overlay/exclusive.rs +0 -88
- data/crates/kobako-runtime/src/filesystem/path.rs +0 -60
- data/crates/kobako-runtime/src/filesystem/temporary.rs +0 -167
- data/crates/kobako-wasmtime/src/capture.rs +0 -96
- data/crates/kobako-wasmtime/src/descriptors.rs +0 -167
- data/crates/kobako-wasmtime/src/dispatch.rs +0 -125
- data/crates/kobako-wasmtime/src/guest_mem.rs +0 -271
- data/crates/kobako-wasmtime/src/io.rs +0 -89
- data/crates/kobako-wasmtime/src/preview1/args.rs +0 -60
- data/crates/kobako-wasmtime/src/preview1/beneath.rs +0 -188
- data/crates/kobako-wasmtime/tests/compile_posture.rs +0 -43
- data/crates/kobako-wasmtime/tests/guest_file.rs +0 -1054
- data/crates/kobako-wasmtime/tests/preamble_flags.rs +0 -70
- data/crates/kobako-wasmtime/tests/snippet_compile.rs +0 -95
- data/crates/kobako-wasmtime/tests/support/mod.rs +0 -30
- data/crates/kobako-wasmtime/tests/unanswered_call.rs +0 -86
- data/crates/kobako-wasmtime/tests/unsupported_call.rs +0 -51
- data/ext/kobako/src/runtime/escape.rs +0 -53
- data/ext/kobako/src/runtime/filesystem/ruby.rs +0 -400
- data/ext/kobako/src/runtime/filesystem.rs +0 -236
- data/ext/kobako/src/runtime/gvl.rs +0 -112
- data/lib/kobako/constant_name.rb +0 -8
- data/sig/kobako/codec/utils.rbs +0 -9
- data/sig/kobako/constant_name.rbs +0 -3
- /data/ext/kobako/src/{runtime/pinned_value.rs → pinned_value.rs} +0 -0
|
@@ -1,37 +1,41 @@
|
|
|
1
1
|
//! The differential probe beneath a Mount: each path call, made on the
|
|
2
|
-
//! same host directory through kobako's `
|
|
2
|
+
//! same host directory through kobako's `Bind` Mount and through
|
|
3
3
|
//! wasmtime-wasi's own preopen, must leave the same errno, the same
|
|
4
4
|
//! descriptor, and the same directory behind. A listing of the Mount must
|
|
5
5
|
//! answer the same errno.
|
|
6
6
|
//!
|
|
7
|
-
//!
|
|
8
|
-
//! stat writes only the filetype is
|
|
9
|
-
//! directory carry the rest of the decision.
|
|
7
|
+
//! kobako's inode numbers are its own, and its times differ from the host's
|
|
8
|
+
//! by when each call ran, so of what a stat writes only the filetype is
|
|
9
|
+
//! compared; the errno and the directory carry the rest of the decision.
|
|
10
10
|
//!
|
|
11
11
|
//! Where POSIX lets each host choose, wasmtime-wasi passes on the host's
|
|
12
12
|
//! own answer — unlinking a directory is `ISDIR` on Linux and `PERM` on
|
|
13
13
|
//! macOS. kobako answers one way on every host, the way Linux does, so
|
|
14
14
|
//! the probe holds where CI runs it.
|
|
15
|
+
//!
|
|
16
|
+
//! An open asking to sync, or for a directory it would truncate, is left out:
|
|
17
|
+
//! wasmtime-wasi refuses both as invalid or unsupported, where kobako answers
|
|
18
|
+
//! as Linux does, which `mount_view` holds to literal answers.
|
|
15
19
|
|
|
16
20
|
use std::fs;
|
|
17
21
|
use std::path::{Path, PathBuf};
|
|
18
22
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
19
|
-
use std::sync::
|
|
23
|
+
use std::sync::OnceLock;
|
|
20
24
|
|
|
21
|
-
use kobako_runtime::filesystem::
|
|
22
|
-
use kobako_runtime::filesystem::
|
|
25
|
+
use kobako_runtime::filesystem::Bind;
|
|
26
|
+
use kobako_runtime::filesystem::Filesystem;
|
|
23
27
|
use kobako_runtime::grant::Grant;
|
|
24
|
-
use kobako_runtime::mount::Mount;
|
|
28
|
+
use kobako_runtime::mount::{Access, Mount};
|
|
25
29
|
use kobako_runtime::profile::Profile;
|
|
30
|
+
use kobako_runtime::vfs::PATH_MAX;
|
|
26
31
|
use wasmtime::{Linker, Module, Store};
|
|
27
32
|
use wasmtime_wasi::p1::{self, WasiP1Ctx};
|
|
28
33
|
use wasmtime_wasi::{FsPerms, WasiCtxBuilder};
|
|
29
34
|
|
|
30
|
-
use crate::cache::
|
|
35
|
+
use crate::cache::load_engine;
|
|
31
36
|
use crate::config::Config;
|
|
32
37
|
use crate::imports;
|
|
33
38
|
use crate::invocation::Invocation;
|
|
34
|
-
use crate::preview1::beneath::PATH_MAX;
|
|
35
39
|
use crate::trap::NO_TIMEOUT_EPOCH_DELTA;
|
|
36
40
|
use crate::wasi::Wasi;
|
|
37
41
|
|
|
@@ -89,7 +93,6 @@ const OFLAGS_DIRECTORY: i32 = 1 << 1;
|
|
|
89
93
|
const OFLAGS_EXCL: i32 = 1 << 2;
|
|
90
94
|
const OFLAGS_TRUNC: i32 = 1 << 3;
|
|
91
95
|
const FDFLAGS_NONBLOCK: i32 = 1 << 2;
|
|
92
|
-
const FDFLAGS_SYNC: i32 = 1 << 4;
|
|
93
96
|
const RIGHTS_FD_READ: i64 = 1 << 1;
|
|
94
97
|
const RIGHTS_FD_WRITE: i64 = 1 << 6;
|
|
95
98
|
|
|
@@ -102,6 +105,7 @@ const PATHS: &[&str] = &[
|
|
|
102
105
|
"",
|
|
103
106
|
".",
|
|
104
107
|
"a/",
|
|
108
|
+
"g",
|
|
105
109
|
"l/",
|
|
106
110
|
"n/",
|
|
107
111
|
"g/",
|
|
@@ -193,16 +197,6 @@ const CALLS: &[Call] = &[
|
|
|
193
197
|
rights: RIGHTS_FD_READ,
|
|
194
198
|
fdflags: 0,
|
|
195
199
|
},
|
|
196
|
-
Call::Open {
|
|
197
|
-
oflags: OFLAGS_DIRECTORY | OFLAGS_TRUNC,
|
|
198
|
-
rights: RIGHTS_FD_READ,
|
|
199
|
-
fdflags: 0,
|
|
200
|
-
},
|
|
201
|
-
Call::Open {
|
|
202
|
-
oflags: 0,
|
|
203
|
-
rights: RIGHTS_FD_READ,
|
|
204
|
-
fdflags: FDFLAGS_SYNC,
|
|
205
|
-
},
|
|
206
200
|
Call::Open {
|
|
207
201
|
oflags: 0,
|
|
208
202
|
rights: RIGHTS_FD_READ,
|
|
@@ -378,24 +372,21 @@ fn through_wasmtime_wasi(call: Call, path: &str) -> Observation {
|
|
|
378
372
|
observe(store, &linker, call, path, &host)
|
|
379
373
|
}
|
|
380
374
|
|
|
381
|
-
/// `host` behind a kobako `
|
|
375
|
+
/// `host` behind a kobako `Bind` Mount at `AT`.
|
|
382
376
|
fn kobako_preopen(host: &HostDir) -> (Store<Invocation>, Linker<Invocation>) {
|
|
383
|
-
let engine =
|
|
384
|
-
let config = Config
|
|
385
|
-
|
|
386
|
-
setup_timeout: None,
|
|
387
|
-
memory_limit: None,
|
|
388
|
-
stdout_limit: None,
|
|
389
|
-
stderr_limit: None,
|
|
390
|
-
open_file_limit: None,
|
|
391
|
-
profile: Profile::Hermetic,
|
|
392
|
-
};
|
|
393
|
-
let directory = Directory::new(&host.0).expect("the host directory must open");
|
|
377
|
+
let engine = load_engine().expect("shared engine must be constructible");
|
|
378
|
+
let config = Config::for_profile(Profile::Hermetic);
|
|
379
|
+
let directory = Bind::new(&host.0).expect("the host directory must open");
|
|
394
380
|
let grant = Grant::Mount(
|
|
395
|
-
Mount::new(
|
|
381
|
+
Mount::new(
|
|
382
|
+
AT,
|
|
383
|
+
Filesystem::new(directory).expect("the instance must stand"),
|
|
384
|
+
Access::ReadWrite,
|
|
385
|
+
)
|
|
386
|
+
.expect("AT is a guest path"),
|
|
396
387
|
);
|
|
397
|
-
let wasi = Wasi::for_invocation(&config, &[
|
|
398
|
-
let mut store = Store::new(engine, Invocation::new(
|
|
388
|
+
let wasi = Wasi::for_invocation(&config, &[grant]).expect("WASI context must build");
|
|
389
|
+
let mut store = Store::new(engine, Invocation::new(wasi));
|
|
399
390
|
store.set_epoch_deadline(NO_TIMEOUT_EPOCH_DELTA);
|
|
400
391
|
let linker = imports::linker().expect("host imports must link");
|
|
401
392
|
(store, linker)
|
|
@@ -403,7 +394,7 @@ fn kobako_preopen(host: &HostDir) -> (Store<Invocation>, Linker<Invocation>) {
|
|
|
403
394
|
|
|
404
395
|
/// `host` behind wasmtime-wasi's own preopen at `AT`.
|
|
405
396
|
fn wasmtime_wasi_preopen(host: &HostDir) -> (Store<WasiP1Ctx>, Linker<WasiP1Ctx>) {
|
|
406
|
-
let engine =
|
|
397
|
+
let engine = load_engine().expect("shared engine must be constructible");
|
|
407
398
|
let ctx = WasiCtxBuilder::new()
|
|
408
399
|
.preopened_dir(&host.0, AT, FsPerms::ReadWrite)
|
|
409
400
|
.expect("the host directory must preopen")
|
|
@@ -416,17 +407,17 @@ fn wasmtime_wasi_preopen(host: &HostDir) -> (Store<WasiP1Ctx>, Linker<WasiP1Ctx>
|
|
|
416
407
|
}
|
|
417
408
|
|
|
418
409
|
const ERRNO_BUSY: i32 = 10;
|
|
410
|
+
const ERRNO_EXIST: i32 = 20;
|
|
419
411
|
const ERRNO_INVAL: i32 = 28;
|
|
420
412
|
const ERRNO_ISDIR: i32 = 31;
|
|
421
|
-
const ERRNO_LOOP: i32 = 32;
|
|
422
413
|
const ERRNO_NAMETOOLONG: i32 = 37;
|
|
423
414
|
const ERRNO_NOENT: i32 = 44;
|
|
424
415
|
const ERRNO_NOTDIR: i32 = 54;
|
|
416
|
+
const ERRNO_NOTEMPTY: i32 = 55;
|
|
425
417
|
const ERRNO_NOTSUP: i32 = 58;
|
|
426
418
|
const ERRNO_PERM: i32 = 63;
|
|
427
419
|
const ERRNO_NOTCAPABLE: i32 = 76;
|
|
428
420
|
|
|
429
|
-
/// Whether `path` reaches above the root it is resolved beneath.
|
|
430
421
|
/// Whether `path` takes a `..`, or ends in a `.`, right after one of the
|
|
431
422
|
/// host directory's links.
|
|
432
423
|
fn steps_out_of_a_link(path: &str) -> bool {
|
|
@@ -439,6 +430,17 @@ fn steps_out_of_a_link(path: &str) -> bool {
|
|
|
439
430
|
}
|
|
440
431
|
}
|
|
441
432
|
|
|
433
|
+
/// Whether `call` acts on the last name of `path` rather than land on it, a
|
|
434
|
+
/// `.` or `..` there taking the walk nowhere, as Linux's `LOOKUP_PARENT` leaves
|
|
435
|
+
/// it.
|
|
436
|
+
fn acts_on_a_dot(call: Call, path: &str) -> bool {
|
|
437
|
+
matches!(
|
|
438
|
+
call,
|
|
439
|
+
Call::Mkdir | Call::Rmdir | Call::Unlink | Call::RenameFrom | Call::RenameTo
|
|
440
|
+
) && matches!(path.rsplit('/').next(), Some("." | ".."))
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/// Whether `path` reaches above the root it is resolved beneath.
|
|
442
444
|
fn escapes(path: &str) -> bool {
|
|
443
445
|
let mut depth = 0usize;
|
|
444
446
|
path.starts_with('/')
|
|
@@ -458,9 +460,8 @@ fn escapes(path: &str) -> bool {
|
|
|
458
460
|
})
|
|
459
461
|
}
|
|
460
462
|
|
|
461
|
-
/// What kobako answers where it differs from wasmtime-wasi on purpose.
|
|
462
|
-
///
|
|
463
|
-
/// flag and blocks anyway. A path above the root is `NOTCAPABLE`, the code preview1 names for a
|
|
463
|
+
/// What kobako answers where it differs from wasmtime-wasi on purpose. A path
|
|
464
|
+
/// above the root is `NOTCAPABLE`, the code preview1 names for a
|
|
464
465
|
/// capability the guest was never handed, where wasmtime-wasi passes on
|
|
465
466
|
/// cap-std's refusal as `PERM`. A path past `PATH_MAX` is `NAMETOOLONG`
|
|
466
467
|
/// as Linux answers the whole path, where cap-std resolves it one name
|
|
@@ -469,11 +470,13 @@ fn escapes(path: &str) -> bool {
|
|
|
469
470
|
/// which follows a link there, where cap-std's shortcut for one name
|
|
470
471
|
/// drops the `/` and finds the file or the link. A `rmdir` of a link
|
|
471
472
|
/// named with a trailing `/` is `NOTDIR` as Linux answers it, where
|
|
472
|
-
/// cap-std's split turns the `/` into `.` and answers `INVAL`. A
|
|
473
|
+
/// cap-std's split turns the `/` into `.` and answers `INVAL`. A `rmdir`
|
|
474
|
+
/// of a path ending in `..` is `NOTEMPTY` as Linux answers it, where
|
|
475
|
+
/// cap-std answers `INVAL` as it does for a final `.`. A `..` or
|
|
473
476
|
/// a final `.` after a link is `LOOP` and changes nothing, where cap-std
|
|
474
477
|
/// steps out of where the link points; a call refused before its path
|
|
475
478
|
/// resolves answers alike.
|
|
476
|
-
fn
|
|
479
|
+
fn predict(call: Call, path: &str, mut oracle: Observation) -> Observation {
|
|
477
480
|
let refused = |errno| Observation {
|
|
478
481
|
errno: Some(errno),
|
|
479
482
|
opened: [0; 4],
|
|
@@ -482,20 +485,24 @@ fn expected(call: Call, path: &str, mut oracle: Observation) -> Observation {
|
|
|
482
485
|
filetype: 0,
|
|
483
486
|
tree: HostDir::new().tree(),
|
|
484
487
|
};
|
|
485
|
-
if matches!(call, Call::Open { fdflags, .. } if fdflags & FDFLAGS_NONBLOCK != 0) {
|
|
486
|
-
return refused(if path.len() >= PATH_MAX {
|
|
487
|
-
ERRNO_NAMETOOLONG
|
|
488
|
-
} else {
|
|
489
|
-
ERRNO_NOTSUP
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
488
|
let refused_first = matches!(oracle.errno, Some(ERRNO_BUSY | ERRNO_INVAL | ERRNO_NOTSUP));
|
|
493
|
-
if steps_out_of_a_link(path) &&
|
|
494
|
-
|
|
489
|
+
if steps_out_of_a_link(path) && acts_on_a_dot(call, path) {
|
|
490
|
+
match call {
|
|
491
|
+
Call::Mkdir => return refused(ERRNO_EXIST),
|
|
492
|
+
Call::Unlink => return refused(ERRNO_ISDIR),
|
|
493
|
+
_ => {}
|
|
494
|
+
}
|
|
495
495
|
}
|
|
496
496
|
if escapes(path) && oracle.errno == Some(ERRNO_PERM) {
|
|
497
497
|
oracle.errno = Some(ERRNO_NOTCAPABLE);
|
|
498
498
|
}
|
|
499
|
+
// A directory keeps the flags it opened with, as Linux's `F_GETFL`
|
|
500
|
+
// reports them, where wasmtime-wasi reports none on one.
|
|
501
|
+
if let Call::Open { fdflags, .. } = call {
|
|
502
|
+
if oracle.errno == Some(0) && oracle.fdstat[0] == FILETYPE_DIRECTORY {
|
|
503
|
+
oracle.fdstat[2] = fdflags as u8;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
499
506
|
// A trailing `/` makes Linux's `lstat` follow the link at the end,
|
|
500
507
|
// where cap-std leaves it, so the host's own `lstat` answers.
|
|
501
508
|
if matches!(call, Call::StatNoFollow) && path.ends_with('/') {
|
|
@@ -532,7 +539,13 @@ fn expected(call: Call, path: &str, mut oracle: Observation) -> Observation {
|
|
|
532
539
|
_ => {}
|
|
533
540
|
}
|
|
534
541
|
}
|
|
535
|
-
if
|
|
542
|
+
if matches!(call, Call::Rmdir)
|
|
543
|
+
&& path.trim_end_matches('/').ends_with("..")
|
|
544
|
+
&& oracle.errno == Some(ERRNO_INVAL)
|
|
545
|
+
{
|
|
546
|
+
oracle.errno = Some(ERRNO_NOTEMPTY);
|
|
547
|
+
}
|
|
548
|
+
if path.len() >= PATH_MAX && !refused_first {
|
|
536
549
|
oracle.errno = Some(ERRNO_NAMETOOLONG);
|
|
537
550
|
}
|
|
538
551
|
oracle
|
|
@@ -554,13 +567,13 @@ fn every_path_call_beneath_a_mount_answers_as_a_wasmtime_wasi_preopen() {
|
|
|
554
567
|
.flat_map(|&call| paths.iter().map(move |path| (call, path.as_str())))
|
|
555
568
|
.filter_map(|(call, path)| {
|
|
556
569
|
let kobako = through_kobako(call, path);
|
|
557
|
-
let oracle =
|
|
570
|
+
let oracle = predict(call, path, through_wasmtime_wasi(call, path));
|
|
558
571
|
(kobako != oracle).then(|| format!("{call:?} {path:?}: {kobako:?} != {oracle:?}"))
|
|
559
572
|
})
|
|
560
573
|
.collect();
|
|
561
574
|
assert!(
|
|
562
575
|
differing.is_empty(),
|
|
563
|
-
"each path call on a host directory through a kobako
|
|
576
|
+
"each path call on a host directory through a kobako Bind Mount must answer as \
|
|
564
577
|
wasmtime-wasi's preopen of it does:\n{}",
|
|
565
578
|
differing.join("\n")
|
|
566
579
|
);
|
|
@@ -604,6 +617,6 @@ fn a_listing_holding_a_name_that_is_not_utf8_answers_as_a_wasmtime_wasi_preopen(
|
|
|
604
617
|
assert_eq!(
|
|
605
618
|
kobako, oracle,
|
|
606
619
|
"fd_readdir on a host directory holding a name that is not UTF-8 through a kobako \
|
|
607
|
-
|
|
620
|
+
Bind Mount must answer as wasmtime-wasi's preopen of it does"
|
|
608
621
|
);
|
|
609
622
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
//!
|
|
5
5
|
//! It guards each wasmtime-wasi upgrade: a change in what preview1 answers
|
|
6
6
|
//! shows up here rather than in a guest. The deliberate differences — a
|
|
7
|
-
//! clock wait
|
|
7
|
+
//! clock wait on the hermetic profile — are witnessed in `poll`.
|
|
8
8
|
|
|
9
9
|
mod mount;
|
|
10
10
|
|
|
@@ -15,7 +15,7 @@ use wasmtime_wasi::p1::{self, WasiP1Ctx};
|
|
|
15
15
|
use wasmtime_wasi::p2::pipe::{MemoryInputPipe, MemoryOutputPipe};
|
|
16
16
|
use wasmtime_wasi::WasiCtxBuilder;
|
|
17
17
|
|
|
18
|
-
use crate::cache::
|
|
18
|
+
use crate::cache::load_engine;
|
|
19
19
|
use crate::config::Config;
|
|
20
20
|
use crate::imports;
|
|
21
21
|
use crate::invocation::Invocation;
|
|
@@ -23,8 +23,8 @@ use crate::trap::NO_TIMEOUT_EPOCH_DELTA;
|
|
|
23
23
|
use crate::wasi::Wasi;
|
|
24
24
|
use kobako_runtime::profile::Profile;
|
|
25
25
|
|
|
26
|
-
/// The
|
|
27
|
-
const
|
|
26
|
+
/// The bytes descriptor 0 reads, on each side alike.
|
|
27
|
+
const STDIN: &[u8] = b"hello";
|
|
28
28
|
|
|
29
29
|
/// Every export takes a descriptor and answers the call's errno. Memory
|
|
30
30
|
/// holds an `iovec` at 64 over 512..528, an empty one at 72, a `ciovec` at 80 over "hello" at
|
|
@@ -91,6 +91,9 @@ const PROBE_WAT: &str = r#"
|
|
|
91
91
|
(func (export "fd_fdstat_set_rights") (param i32) (result i32) (call $fd_fdstat_set_rights (local.get 0) (i64.const 0) (i64.const 0)))
|
|
92
92
|
(func (export "fd_filestat_get") (param i32) (result i32) (call $fd_filestat_get (local.get 0) (i32.const 256)))
|
|
93
93
|
(func (export "fd_filestat_set_size") (param i32) (result i32) (call $fd_filestat_set_size (local.get 0) (i64.const 0)))
|
|
94
|
+
(func (export "fd_filestat_set_size_huge") (param i32) (result i32) (call $fd_filestat_set_size (local.get 0) (i64.const -1)))
|
|
95
|
+
(func (export "fd_pread_huge") (param i32) (result i32) (call $fd_pread (local.get 0) (i32.const 64) (i32.const 1) (i64.const -1) (i32.const 128)))
|
|
96
|
+
(func (export "fd_pwrite_huge") (param i32) (result i32) (call $fd_pwrite (local.get 0) (i32.const 80) (i32.const 1) (i64.const -1) (i32.const 128)))
|
|
94
97
|
(func (export "fd_filestat_set_times") (param i32) (result i32) (call $fd_filestat_set_times (local.get 0) (i64.const 0) (i64.const 0) (i32.const 0)))
|
|
95
98
|
(func (export "fd_pread") (param i32) (result i32) (call $fd_pread (local.get 0) (i32.const 64) (i32.const 1) (i64.const 0) (i32.const 128)))
|
|
96
99
|
(func (export "fd_prestat_get") (param i32) (result i32) (call $fd_prestat_get (local.get 0) (i32.const 256)))
|
|
@@ -244,12 +247,6 @@ struct Observation {
|
|
|
244
247
|
/// A capped Channel exercises the pipe filling mid-write.
|
|
245
248
|
const CHANNEL_LIMITS: [Option<usize>; 2] = [None, Some(3)];
|
|
246
249
|
|
|
247
|
-
fn stdin_bytes() -> Vec<u8> {
|
|
248
|
-
let mut bytes = (PREAMBLE.len() as u32).to_be_bytes().to_vec();
|
|
249
|
-
bytes.extend_from_slice(PREAMBLE);
|
|
250
|
-
bytes
|
|
251
|
-
}
|
|
252
|
-
|
|
253
250
|
fn observe<T>(
|
|
254
251
|
mut store: Store<T>,
|
|
255
252
|
linker: &Linker<T>,
|
|
@@ -282,18 +279,12 @@ fn observe<T>(
|
|
|
282
279
|
}
|
|
283
280
|
|
|
284
281
|
fn through_kobako(call: &str, fd: i32, limit: Option<usize>) -> Observation {
|
|
285
|
-
let engine =
|
|
286
|
-
let config = Config
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
stderr_limit: limit,
|
|
292
|
-
open_file_limit: None,
|
|
293
|
-
profile: Profile::Hermetic,
|
|
294
|
-
};
|
|
295
|
-
let wasi = Wasi::for_invocation(&config, PREAMBLE, &[]).expect("WASI context must build");
|
|
296
|
-
let mut store = Store::new(engine, Invocation::new(None, wasi));
|
|
282
|
+
let engine = load_engine().expect("shared engine must be constructible");
|
|
283
|
+
let mut config = Config::for_profile(Profile::Hermetic);
|
|
284
|
+
config.limits.stdout_limit = limit;
|
|
285
|
+
config.limits.stderr_limit = limit;
|
|
286
|
+
let wasi = Wasi::reading_stdin(&config, STDIN.to_vec());
|
|
287
|
+
let mut store = Store::new(engine, Invocation::new(wasi));
|
|
297
288
|
store.set_epoch_deadline(NO_TIMEOUT_EPOCH_DELTA);
|
|
298
289
|
let linker = imports::linker().expect("host imports must link");
|
|
299
290
|
let (mut observation, store) = observe(store, &linker, call, fd);
|
|
@@ -310,11 +301,11 @@ struct Oracle {
|
|
|
310
301
|
}
|
|
311
302
|
|
|
312
303
|
fn through_wasmtime_wasi(call: &str, fd: i32, limit: Option<usize>) -> Observation {
|
|
313
|
-
let engine =
|
|
314
|
-
let stdout = MemoryOutputPipe::new(
|
|
315
|
-
let stderr = MemoryOutputPipe::new(
|
|
304
|
+
let engine = load_engine().expect("shared engine must be constructible");
|
|
305
|
+
let stdout = MemoryOutputPipe::new(kobako_runtime::Capture::pipe_capacity_of(limit));
|
|
306
|
+
let stderr = MemoryOutputPipe::new(kobako_runtime::Capture::pipe_capacity_of(limit));
|
|
316
307
|
let ctx = WasiCtxBuilder::new()
|
|
317
|
-
.stdin(MemoryInputPipe::new(
|
|
308
|
+
.stdin(MemoryInputPipe::new(STDIN))
|
|
318
309
|
.stdout(stdout.clone())
|
|
319
310
|
.stderr(stderr.clone())
|
|
320
311
|
.build_p1();
|
|
@@ -360,8 +351,18 @@ fn every_descriptor_call_answers_as_wasmtime_wasi_preview1() {
|
|
|
360
351
|
for limit in CHANNEL_LIMITS {
|
|
361
352
|
for call in CALLS {
|
|
362
353
|
for fd in 0..=3 {
|
|
354
|
+
let kobako = through_kobako(call, fd, limit);
|
|
355
|
+
if let Some(errno) = answered_as_linux(call, fd) {
|
|
356
|
+
assert_eq!(
|
|
357
|
+
kobako.errno,
|
|
358
|
+
Some(errno),
|
|
359
|
+
"{call} on descriptor {fd} through kobako's preview1 imports must answer \
|
|
360
|
+
as Linux does"
|
|
361
|
+
);
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
363
364
|
assert_eq!(
|
|
364
|
-
|
|
365
|
+
kobako,
|
|
365
366
|
through_wasmtime_wasi(call, fd, limit),
|
|
366
367
|
"{call} on descriptor {fd} with Channels capped at {limit:?} through \
|
|
367
368
|
kobako's preview1 imports must answer as wasmtime-wasi's preview1 does"
|
|
@@ -370,3 +371,112 @@ fn every_descriptor_call_answers_as_wasmtime_wasi_preview1() {
|
|
|
370
371
|
}
|
|
371
372
|
}
|
|
372
373
|
}
|
|
374
|
+
|
|
375
|
+
/// Where kobako parts from wasmtime-wasi, the errno Linux answers, which
|
|
376
|
+
/// outranks it. For a standard stream it answers as for a pipe: an offset, a
|
|
377
|
+
/// sync, or a size is no pipe's, and a pipe is no directory to open beneath.
|
|
378
|
+
/// Linux also takes `O_APPEND` on a pipe, reports one link where wasmtime-wasi
|
|
379
|
+
/// reports none, checks neither path nor descriptor for a call setting no
|
|
380
|
+
/// time, as `utimensat` returns first, and reports a wait on a descriptor not
|
|
381
|
+
/// open in its event, as `poll` marks it `POLLNVAL`.
|
|
382
|
+
fn answered_as_linux(call: &str, fd: i32) -> Option<i32> {
|
|
383
|
+
const ERRNO_SUCCESS: i32 = 0;
|
|
384
|
+
const ERRNO_INVAL: i32 = 28;
|
|
385
|
+
const ERRNO_NOTDIR: i32 = 54;
|
|
386
|
+
const ERRNO_SPIPE: i32 = 70;
|
|
387
|
+
match (call, fd) {
|
|
388
|
+
("fd_filestat_set_times" | "path_filestat_set_times", 3) => Some(ERRNO_SUCCESS),
|
|
389
|
+
("poll_oneoff_read" | "poll_oneoff_write", 3) => Some(ERRNO_SUCCESS),
|
|
390
|
+
("fd_advise", 0..=2) => Some(ERRNO_SPIPE),
|
|
391
|
+
("fd_allocate" | "fd_sync" | "fd_datasync" | "fd_filestat_set_size", 0..=2) => {
|
|
392
|
+
Some(ERRNO_INVAL)
|
|
393
|
+
}
|
|
394
|
+
(
|
|
395
|
+
"fd_fdstat_set_flags"
|
|
396
|
+
| "fd_filestat_get"
|
|
397
|
+
| "fd_filestat_set_times"
|
|
398
|
+
| "path_filestat_set_times",
|
|
399
|
+
0..=2,
|
|
400
|
+
) => Some(ERRNO_SUCCESS),
|
|
401
|
+
("fd_read_empty", 0) => Some(ERRNO_SUCCESS),
|
|
402
|
+
("fd_readdir" | "fd_readdir_far", 0..=2) => Some(ERRNO_NOTDIR),
|
|
403
|
+
(
|
|
404
|
+
"path_create_directory"
|
|
405
|
+
| "path_filestat_get"
|
|
406
|
+
| "path_link"
|
|
407
|
+
| "path_open"
|
|
408
|
+
| "path_readlink"
|
|
409
|
+
| "path_remove_directory"
|
|
410
|
+
| "path_rename"
|
|
411
|
+
| "path_symlink"
|
|
412
|
+
| "path_unlink_file",
|
|
413
|
+
0..=2,
|
|
414
|
+
) => Some(ERRNO_NOTDIR),
|
|
415
|
+
("fd_pread" | "fd_pread_far", 1 | 2) => Some(ERRNO_SPIPE),
|
|
416
|
+
("fd_pwrite" | "fd_pwrite_far", 0) => Some(ERRNO_SPIPE),
|
|
417
|
+
_ => None,
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// wasmtime-wasi fails the whole wait; the witx gives each event its own error,
|
|
422
|
+
// and Linux's `do_pollfd` marks the descriptor `POLLNVAL`, which wasi-libc reads
|
|
423
|
+
// back from an event's EBADF.
|
|
424
|
+
// @behavior RT-295
|
|
425
|
+
#[test]
|
|
426
|
+
fn a_wait_on_a_descriptor_not_open_reports_it_in_its_event() {
|
|
427
|
+
let read = through_kobako("poll_oneoff_read", 3, None);
|
|
428
|
+
let write = through_kobako("poll_oneoff_write", 3, None);
|
|
429
|
+
let event = |seen: &Observation| {
|
|
430
|
+
(
|
|
431
|
+
seen.errno,
|
|
432
|
+
u64::from_le_bytes(seen.memory[896..904].try_into().expect("eight bytes")),
|
|
433
|
+
u16::from_le_bytes([seen.memory[904], seen.memory[905]]),
|
|
434
|
+
u32::from_le_bytes(seen.memory[128..132].try_into().expect("four bytes")),
|
|
435
|
+
)
|
|
436
|
+
};
|
|
437
|
+
assert_eq!(
|
|
438
|
+
(event(&read), event(&write)),
|
|
439
|
+
((Some(0), 7, 8, 1), (Some(0), 7, 8, 1)),
|
|
440
|
+
"poll_oneoff on descriptor 3, not open, through kobako's preview1 imports must succeed \
|
|
441
|
+
with one event whose error is EBADF, as Linux's poll marks it POLLNVAL"
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// Linux's `ksys_ftruncate`, `ksys_pread64`, and `ksys_pwrite64` read the
|
|
446
|
+
// length or offset as a signed `loff_t` and refuse a negative one before they
|
|
447
|
+
// look for the descriptor.
|
|
448
|
+
// @behavior RT-296
|
|
449
|
+
#[test]
|
|
450
|
+
fn a_size_or_offset_no_file_can_take_answers_before_the_descriptor_is_found() {
|
|
451
|
+
let errno = |call| through_kobako(call, 3, None).errno;
|
|
452
|
+
assert_eq!(
|
|
453
|
+
[
|
|
454
|
+
errno("fd_filestat_set_size_huge"),
|
|
455
|
+
errno("fd_pread_huge"),
|
|
456
|
+
errno("fd_pwrite_huge"),
|
|
457
|
+
],
|
|
458
|
+
[Some(28), Some(28), Some(28)],
|
|
459
|
+
"fd_filestat_set_size, fd_pread, and fd_pwrite at 2^64 - 1 on descriptor 3, not open, \
|
|
460
|
+
through kobako's preview1 imports must answer EINVAL, as ftruncate, pread, and pwrite \
|
|
461
|
+
check it before the descriptor"
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// wasmtime-wasi answers EBADF for the end a call cannot use; Linux reads
|
|
466
|
+
// `FMODE_PREAD` first, and a pipe has none on either end.
|
|
467
|
+
// @behavior RT-178
|
|
468
|
+
#[test]
|
|
469
|
+
fn a_standard_stream_takes_no_offset() {
|
|
470
|
+
let errno = |call, fd| through_kobako(call, fd, None).errno;
|
|
471
|
+
assert_eq!(
|
|
472
|
+
[
|
|
473
|
+
errno("fd_pread", 0),
|
|
474
|
+
errno("fd_pread", 1),
|
|
475
|
+
errno("fd_pwrite", 0),
|
|
476
|
+
errno("fd_pwrite", 1),
|
|
477
|
+
],
|
|
478
|
+
[Some(70), Some(70), Some(70), Some(70)],
|
|
479
|
+
"fd_pread and fd_pwrite on standard input and output through kobako's preview1 imports \
|
|
480
|
+
must answer ESPIPE, as Linux answers for a pipe's either end"
|
|
481
|
+
);
|
|
482
|
+
}
|