kobako 0.30.0 → 0.32.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/.githooks/linux-tests.sh +29 -0
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +460 -0
- data/Cargo.lock +868 -447
- data/README.md +43 -4
- data/ROADMAP.md +1 -2
- data/crates/kobako-runtime/CHANGELOG.md +309 -0
- data/crates/kobako-runtime/Cargo.toml +58 -11
- data/crates/kobako-runtime/README.md +7 -4
- data/crates/kobako-runtime/src/cred.rs +136 -0
- data/crates/kobako-runtime/src/dispatch.rs +4 -5
- data/crates/kobako-runtime/src/endpoint/buffer.rs +153 -44
- data/crates/kobako-runtime/src/endpoint/dispatch.rs +80 -41
- data/crates/kobako-runtime/src/endpoint/invoke.rs +23 -36
- data/crates/kobako-runtime/src/endpoint.rs +137 -36
- 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 +300 -22
- data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +101 -29
- data/crates/kobako-runtime/src/filesystem/bind/unicode.rs +109 -0
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +52 -34
- data/crates/kobako-runtime/src/filesystem/bind.rs +812 -447
- data/crates/kobako-runtime/src/filesystem/overlay/file.rs +6 -6
- data/crates/kobako-runtime/src/filesystem/overlay/path.rs +43 -65
- data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +11 -16
- data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +47 -72
- data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +12 -12
- data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +4 -7
- data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +120 -37
- data/crates/kobako-runtime/src/filesystem/overlay.rs +578 -388
- data/crates/kobako-runtime/src/filesystem/pipe.rs +12 -9
- data/crates/kobako-runtime/src/filesystem/rdir.rs +14 -50
- data/crates/kobako-runtime/src/filesystem/testing.rs +31 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +3 -3
- data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +57 -35
- data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +2 -2
- data/crates/kobako-runtime/src/filesystem/tmpfs.rs +219 -173
- data/crates/kobako-runtime/src/filesystem/wrap.rs +36 -52
- data/crates/kobako-runtime/src/filesystem.rs +8 -3
- data/crates/kobako-runtime/src/fork.rs +319 -0
- data/crates/kobako-runtime/src/grant.rs +3 -0
- data/crates/kobako-runtime/src/hashtable.rs +4 -2
- data/crates/kobako-runtime/src/lib.rs +18 -7
- data/crates/kobako-runtime/src/limits.rs +171 -0
- data/crates/kobako-runtime/src/locking/seqlock.rs +29 -3
- data/crates/kobako-runtime/src/locking.rs +518 -113
- data/crates/kobako-runtime/src/memcg.rs +306 -0
- data/crates/kobako-runtime/src/mount.rs +37 -9
- data/crates/kobako-runtime/src/net/backends.rs +43 -0
- data/crates/kobako-runtime/src/net/connections.rs +219 -0
- data/crates/kobako-runtime/src/net/credential.rs +125 -0
- data/crates/kobako-runtime/src/net/egress.rs +180 -0
- data/crates/kobako-runtime/src/net/family.rs +181 -0
- data/crates/kobako-runtime/src/net/http.rs +3165 -0
- data/crates/kobako-runtime/src/net/lookup.rs +385 -0
- data/crates/kobako-runtime/src/net/mock.rs +251 -0
- data/crates/kobako-runtime/src/net/namespace.rs +1368 -0
- data/crates/kobako-runtime/src/net/reactor.rs +626 -0
- data/crates/kobako-runtime/src/net/resolv/darwin.rs +280 -0
- data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +519 -0
- data/crates/kobako-runtime/src/net/resolv/stub.rs +542 -0
- data/crates/kobako-runtime/src/net/resolv/windows.rs +218 -0
- data/crates/kobako-runtime/src/net/resolv.rs +251 -0
- data/crates/kobako-runtime/src/net/skbuff.rs +109 -0
- data/crates/kobako-runtime/src/net/socket.rs +869 -0
- data/crates/kobako-runtime/src/net/task.rs +223 -0
- data/crates/kobako-runtime/src/net/tcp.rs +1840 -0
- data/crates/kobako-runtime/src/net/tls.rs +120 -0
- data/crates/kobako-runtime/src/net/transport.rs +304 -0
- data/crates/kobako-runtime/src/net/udp.rs +1105 -0
- data/crates/kobako-runtime/src/net.rs +45 -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 +29 -144
- data/crates/kobako-runtime/src/runtime.rs +3 -5
- data/crates/kobako-runtime/src/sched.rs +338 -51
- data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
- data/crates/kobako-runtime/src/{vfs/cred.rs → security/hooks.rs} +52 -144
- data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
- data/crates/kobako-runtime/src/security.rs +125 -209
- data/crates/kobako-runtime/src/snapshot.rs +121 -2
- data/crates/kobako-runtime/src/vfs/attr.rs +5 -5
- data/crates/kobako-runtime/src/vfs/dentry.rs +210 -117
- data/crates/kobako-runtime/src/vfs/file.rs +243 -248
- data/crates/kobako-runtime/src/vfs/inode.rs +41 -45
- data/crates/kobako-runtime/src/vfs/kern_path.rs +62 -53
- data/crates/kobako-runtime/src/vfs/mount.rs +10 -9
- data/crates/kobako-runtime/src/vfs/namei.rs +1162 -818
- data/crates/kobako-runtime/src/vfs/namespace.rs +245 -0
- data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
- data/crates/kobako-runtime/src/vfs/openat2.rs +3 -3
- data/crates/kobako-runtime/src/vfs/path.rs +6 -6
- data/crates/kobako-runtime/src/vfs/readdir.rs +6 -6
- data/crates/kobako-runtime/src/vfs/stat.rs +248 -23
- data/crates/kobako-runtime/src/vfs/super_block.rs +18 -14
- data/crates/kobako-runtime/src/vfs/utimes.rs +37 -27
- data/crates/kobako-runtime/src/vfs.rs +10 -6
- data/crates/kobako-runtime/src/wait.rs +381 -0
- data/crates/kobako-transport/CHANGELOG.md +38 -0
- data/crates/kobako-transport/Cargo.toml +1 -1
- data/crates/kobako-transport/README.md +3 -4
- data/crates/kobako-transport/src/abi.rs +78 -72
- data/crates/kobako-transport/src/envelope/bytes.rs +17 -6
- data/crates/kobako-transport/src/envelope/call.rs +32 -4
- data/crates/kobako-transport/src/envelope/error_record.rs +21 -0
- data/crates/kobako-transport/src/envelope/name.rs +99 -0
- data/crates/kobako-transport/src/envelope/outcome.rs +9 -9
- data/crates/kobako-transport/src/envelope/preamble.rs +24 -21
- data/crates/kobako-transport/src/envelope/reply.rs +27 -27
- data/crates/kobako-transport/src/envelope/unsupported.rs +10 -10
- data/crates/kobako-transport/src/envelope.rs +13 -8
- data/crates/kobako-wasmtime/CHANGELOG.md +208 -0
- data/crates/kobako-wasmtime/Cargo.toml +47 -7
- data/crates/kobako-wasmtime/README.md +4 -3
- data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
- data/crates/kobako-wasmtime/build.rs +16 -0
- data/crates/kobako-wasmtime/src/abi.rs +18 -37
- data/crates/kobako-wasmtime/src/ambient.rs +43 -19
- data/crates/kobako-wasmtime/src/cache/unix.rs +95 -0
- data/crates/kobako-wasmtime/src/cache/windows.rs +359 -0
- data/crates/kobako-wasmtime/src/cache.rs +106 -113
- data/crates/kobako-wasmtime/src/config.rs +52 -68
- data/crates/kobako-wasmtime/src/driver.rs +80 -82
- data/crates/kobako-wasmtime/src/exports.rs +143 -17
- data/crates/kobako-wasmtime/src/guest.rs +12 -6
- data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
- data/crates/kobako-wasmtime/src/imports.rs +42 -18
- data/crates/kobako-wasmtime/src/instance_pre.rs +4 -4
- data/crates/kobako-wasmtime/src/invocation.rs +91 -15
- data/crates/kobako-wasmtime/src/lib.rs +7 -3
- data/crates/kobako-wasmtime/src/limiter.rs +130 -12
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +305 -0
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +9 -20
- data/crates/kobako-wasmtime/src/preview1/differential.rs +27 -31
- data/crates/kobako-wasmtime/src/preview1/errno.rs +55 -66
- data/crates/kobako-wasmtime/src/preview1/fd.rs +347 -312
- data/crates/kobako-wasmtime/src/preview1/memory.rs +21 -12
- data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +34 -53
- data/crates/kobako-wasmtime/src/preview1/mount_view.rs +335 -388
- data/crates/kobako-wasmtime/src/preview1/path.rs +56 -121
- data/crates/kobako-wasmtime/src/preview1/poll.rs +255 -125
- data/crates/kobako-wasmtime/src/preview1/random.rs +125 -0
- data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -8
- data/crates/kobako-wasmtime/src/preview1/testing.rs +31 -0
- data/crates/kobako-wasmtime/src/preview1/testsuite.rs +5 -15
- data/crates/kobako-wasmtime/src/preview1.rs +131 -51
- 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 +4319 -0
- data/crates/kobako-wasmtime/src/preview2/http.rs +1587 -0
- data/crates/kobako-wasmtime/src/preview2/io.rs +328 -0
- data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
- data/crates/kobako-wasmtime/src/preview2/table.rs +257 -0
- data/crates/kobako-wasmtime/src/preview2.rs +57 -0
- data/crates/kobako-wasmtime/src/trap.rs +88 -28
- data/crates/kobako-wasmtime/src/waits.rs +59 -0
- data/crates/kobako-wasmtime/src/wasi.rs +291 -81
- 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/wasi_snapshot_preview1.witx +13 -0
- data/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +6 -2
- data/ext/kobako/src/{runtime/errors.rs → errors.rs} +34 -26
- data/ext/kobako/src/escape.rs +404 -0
- data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +34 -32
- data/ext/kobako/src/{runtime/filesystem → filesystem}/ruby.rs +158 -170
- data/ext/kobako/src/{runtime/filesystem.rs → filesystem.rs} +71 -23
- data/ext/kobako/src/fork.rs +72 -0
- data/ext/kobako/src/gvl.rs +729 -0
- data/ext/kobako/src/handoff.rs +490 -0
- data/ext/kobako/src/lib.rs +74 -3
- data/ext/kobako/src/network/mock.rs +187 -0
- data/ext/kobako/src/network.rs +593 -0
- data/ext/kobako/src/pinned_value.rs +44 -0
- data/ext/kobako/src/runtime/bridge.rs +58 -50
- data/ext/kobako/src/runtime/snapshot.rs +4 -4
- data/ext/kobako/src/runtime.rs +272 -163
- data/ext/kobako/src/wire.rs +42 -0
- data/lib/kobako/catalog/extensions.rb +14 -2
- data/lib/kobako/catalog/flags.rb +3 -5
- data/lib/kobako/catalog/grants.rb +5 -4
- data/lib/kobako/catalog/handles.rb +14 -32
- data/lib/kobako/catalog/mount.rb +11 -3
- data/lib/kobako/catalog/network.rb +35 -0
- data/lib/kobako/catalog/replacements.rb +28 -0
- data/lib/kobako/catalog/services.rb +5 -19
- data/lib/kobako/catalog/snippets.rb +3 -18
- data/lib/kobako/catalog.rb +3 -0
- data/lib/kobako/codec/{utils.rb → boundary.rb} +4 -2
- data/lib/kobako/codec/decoder.rb +5 -5
- data/lib/kobako/codec/ext_types.rb +3 -3
- data/lib/kobako/codec/handle_walk.rb +3 -43
- data/lib/kobako/codec/state.rb +2 -18
- data/lib/kobako/codec/value_budget.rb +133 -41
- data/lib/kobako/codec.rb +6 -7
- data/lib/kobako/context.rb +24 -11
- data/lib/kobako/errors.rb +18 -18
- data/lib/kobako/extension.rb +3 -2
- data/lib/kobako/filesystem.rb +10 -3
- data/lib/kobako/fork.rb +42 -0
- data/lib/kobako/handle.rb +2 -3
- data/lib/kobako/names.rb +28 -0
- data/lib/kobako/network.rb +210 -0
- data/lib/kobako/outcome.rb +7 -7
- data/lib/kobako/runtime.rb +3 -2
- data/lib/kobako/sandbox.rb +73 -35
- data/lib/kobako/sandbox_options.rb +42 -109
- data/lib/kobako/transport/argument_wrap.rb +64 -0
- data/lib/kobako/transport/block_failure.rb +1 -1
- data/lib/kobako/transport/dispatcher.rb +6 -6
- data/lib/kobako/transport/exposure.rb +26 -15
- data/lib/kobako/transport/reflection.rb +21 -4
- data/lib/kobako/transport/run.rb +8 -23
- data/lib/kobako/transport/yielder.rb +2 -9
- data/lib/kobako/transport.rb +1 -0
- data/lib/kobako/usage.rb +4 -2
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +8 -4
- data/release-please-config.json +15 -0
- data/sig/kobako/catalog/extensions.rbs +2 -0
- data/sig/kobako/catalog/grants.rbs +7 -4
- data/sig/kobako/catalog/handles.rbs +2 -2
- data/sig/kobako/catalog/mount.rbs +3 -1
- data/sig/kobako/catalog/network.rbs +20 -0
- data/sig/kobako/catalog/replacements.rbs +14 -0
- data/sig/kobako/catalog/services.rbs +0 -4
- data/sig/kobako/catalog/snippets.rbs +0 -2
- data/sig/kobako/codec/{utils.rbs → boundary.rbs} +2 -2
- data/sig/kobako/codec/handle_walk.rbs +0 -6
- data/sig/kobako/codec/state.rbs +0 -4
- data/sig/kobako/codec/value_budget.rbs +48 -5
- data/sig/kobako/codec.rbs +2 -2
- data/sig/kobako/context.rbs +3 -1
- data/sig/kobako/errors.rbs +4 -7
- data/sig/kobako/filesystem.rbs +21 -3
- data/sig/kobako/fork.rbs +17 -0
- data/sig/kobako/network.rbs +115 -0
- data/sig/kobako/outcome.rbs +1 -1
- data/sig/kobako/runtime.rbs +32 -3
- data/sig/kobako/sandbox.rbs +10 -2
- data/sig/kobako/sandbox_options.rbs +29 -40
- data/sig/kobako/transport/argument_wrap.rbs +15 -0
- data/sig/kobako/transport/error.rbs +1 -1
- data/sig/kobako/transport/exposure.rbs +2 -4
- data/sig/kobako/transport/reflection.rbs +10 -0
- data/sig/kobako/transport/run.rbs +0 -2
- data/sig/kobako/transport/yielder.rbs +0 -3
- data/sig/kobako/transport.rbs +1 -1
- data/sig/kobako.rbs +13 -0
- metadata +97 -37
- data/crates/kobako-runtime/src/endpoint/capture.rs +0 -115
- data/crates/kobako-runtime/src/endpoint/memory_cap.rs +0 -238
- data/crates/kobako-runtime/src/filesystem/path.rs +0 -21
- data/crates/kobako-runtime/src/vfs/errno.rs +0 -153
- data/crates/kobako-runtime/tests/linux_baseline/calls.rs +0 -171
- data/crates/kobako-runtime/tests/linux_baseline/concurrent.rs +0 -276
- data/crates/kobako-runtime/tests/linux_baseline/kobako.rs +0 -323
- data/crates/kobako-runtime/tests/linux_baseline/linux-baseline-expected.txt +0 -16
- data/crates/kobako-runtime/tests/linux_baseline/linux.rs +0 -449
- data/crates/kobako-runtime/tests/linux_baseline/main.rs +0 -611
- data/crates/kobako-runtime/tests/linux_baseline/permissions.rs +0 -236
- data/crates/kobako-wasmtime/src/descriptors.rs +0 -200
- data/crates/kobako-wasmtime/tests/integration/compile_posture.rs +0 -43
- data/crates/kobako-wasmtime/tests/integration/guest_file.rs +0 -1085
- data/crates/kobako-wasmtime/tests/integration/main.rs +0 -29
- data/crates/kobako-wasmtime/tests/integration/preamble_flags.rs +0 -70
- data/crates/kobako-wasmtime/tests/integration/snippet_compile.rs +0 -95
- data/crates/kobako-wasmtime/tests/integration/support/mod.rs +0 -30
- data/crates/kobako-wasmtime/tests/integration/unanswered_call.rs +0 -86
- data/crates/kobako-wasmtime/tests/integration/unsupported_call.rs +0 -51
- data/ext/kobako/src/runtime/escape.rs +0 -67
- data/ext/kobako/src/runtime/gvl.rs +0 -147
- data/ext/kobako/src/runtime/pinned_value.rs +0 -31
- data/lib/kobako/constant_name.rb +0 -8
- data/lib/kobako/pool.rb +0 -140
- data/sig/kobako/constant_name.rbs +0 -3
- data/sig/kobako/pool.rbs +0 -42
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//! Host links the preview1 tests stage beneath a Bind Mount.
|
|
2
|
+
|
|
3
|
+
use std::path::Path;
|
|
4
|
+
|
|
5
|
+
/// Make a host link at `at` leading to `target`, spelled as a unix path.
|
|
6
|
+
/// Windows makes a link to a directory apart from one to a file, so there
|
|
7
|
+
/// the kind follows what `target` names now, a file where nothing stands,
|
|
8
|
+
/// and `target` takes the host's separator.
|
|
9
|
+
pub(super) fn symlink(target: impl AsRef<Path>, at: impl AsRef<Path>) {
|
|
10
|
+
let (target, at) = (target.as_ref(), at.as_ref());
|
|
11
|
+
#[cfg(unix)]
|
|
12
|
+
let made = std::os::unix::fs::symlink(target, at);
|
|
13
|
+
#[cfg(windows)]
|
|
14
|
+
let made = {
|
|
15
|
+
let target = std::path::PathBuf::from(target.to_string_lossy().replace('/', "\\"));
|
|
16
|
+
let beside = at.parent().unwrap_or(Path::new(""));
|
|
17
|
+
if beside.join(&target).is_dir() {
|
|
18
|
+
std::os::windows::fs::symlink_dir(&target, at)
|
|
19
|
+
} else {
|
|
20
|
+
std::os::windows::fs::symlink_file(&target, at)
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
made.unwrap_or_else(|err| {
|
|
24
|
+
panic!(
|
|
25
|
+
"the host must make a link at {} to {}: {err}; a Windows host makes one only \
|
|
26
|
+
in Developer Mode or with the privilege to create symbolic links",
|
|
27
|
+
at.display(),
|
|
28
|
+
target.display()
|
|
29
|
+
)
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
use std::collections::BTreeMap;
|
|
11
11
|
use std::fs;
|
|
12
12
|
use std::path::{Path, PathBuf};
|
|
13
|
-
use std::sync::Arc;
|
|
14
13
|
use std::time::Duration;
|
|
15
14
|
|
|
16
15
|
use kobako_runtime::filesystem::Bind;
|
|
@@ -55,21 +54,12 @@ fn copy_tree(from: &Path, to: &Path) {
|
|
|
55
54
|
fn run(wasm: &Path, root: &Path) -> Result<i32, String> {
|
|
56
55
|
let engine = load_engine().map_err(|err| err.to_string())?;
|
|
57
56
|
let bind = Bind::new(root).map_err(|err| err.to_string())?;
|
|
58
|
-
let filesystem = Filesystem::new(
|
|
57
|
+
let filesystem = Filesystem::new(bind).map_err(|err| format!("{err:?}"))?;
|
|
59
58
|
let mount = Mount::new("/", filesystem, Access::ReadWrite).map_err(|err| err.to_string())?;
|
|
60
|
-
let config = Config
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
stdout_limit: None,
|
|
65
|
-
stderr_limit: None,
|
|
66
|
-
open_file_limit: None,
|
|
67
|
-
profile: Profile::Permissive,
|
|
68
|
-
security: Vec::new(),
|
|
69
|
-
};
|
|
70
|
-
let wasi = Wasi::for_invocation(&config, Vec::new(), &[Grant::Mount(mount)])
|
|
71
|
-
.map_err(|err| err.to_string())?;
|
|
72
|
-
let mut store = Store::new(engine, Invocation::new(None, wasi));
|
|
59
|
+
let config = Config::for_profile(Profile::Permissive);
|
|
60
|
+
let wasi =
|
|
61
|
+
Wasi::for_invocation(&config, &[Grant::Mount(mount)]).map_err(|err| err.to_string())?;
|
|
62
|
+
let mut store = Store::new(engine, Invocation::new(wasi));
|
|
73
63
|
arm_deadline(&mut store, Some(Duration::from_secs(30)));
|
|
74
64
|
let module = Module::from_file(engine, wasm).map_err(|err| err.to_string())?;
|
|
75
65
|
let instance = imports::linker()
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
//! kobako's own answers to the
|
|
2
|
-
//! descriptor table
|
|
1
|
+
//! kobako's own answers to the 37 preview1 imports that read the
|
|
2
|
+
//! descriptor table, `fd_*`, `path_*`, `sock_*`, and `poll_oneoff`, and to
|
|
3
|
+
//! `random_get`.
|
|
3
4
|
//!
|
|
4
5
|
//! wasmtime-wasi keeps its table private, so a descriptor kobako places
|
|
5
6
|
//! there would stay invisible to its calls. Answering every call that reads
|
|
6
|
-
//! a descriptor keeps the guest on one table, `
|
|
7
|
-
//! each Mount is a preopen.
|
|
8
|
-
//!
|
|
9
|
-
//!
|
|
10
|
-
//!
|
|
11
|
-
//!
|
|
12
|
-
|
|
7
|
+
//! a descriptor keeps the guest on one table, `descriptors`, where
|
|
8
|
+
//! each outermost Mount is a preopen. wasmtime-wasi draws all the entropy
|
|
9
|
+
//! `random_get` asks for before it checks the buffer, so kobako answers it a
|
|
10
|
+
//! page at a time. The other nine imports — arguments, environment, clocks,
|
|
11
|
+
//! process, and scheduling — stay wasmtime-wasi's, so `witx/` declares only
|
|
12
|
+
//! these 37. wiggle generates their glue as it generates wasmtime-wasi's, so a
|
|
13
|
+
//! value outside what the witx defines traps there before a call starts.
|
|
14
|
+
|
|
15
|
+
pub(crate) mod descriptors;
|
|
13
16
|
mod errno;
|
|
14
17
|
mod fd;
|
|
15
18
|
mod memory;
|
|
16
19
|
mod path;
|
|
17
20
|
mod poll;
|
|
21
|
+
mod random;
|
|
18
22
|
mod sock;
|
|
19
23
|
|
|
20
24
|
#[cfg(test)]
|
|
@@ -22,12 +26,13 @@ mod differential;
|
|
|
22
26
|
#[cfg(test)]
|
|
23
27
|
mod mount_view;
|
|
24
28
|
#[cfg(test)]
|
|
29
|
+
mod testing;
|
|
30
|
+
#[cfg(test)]
|
|
25
31
|
mod testsuite;
|
|
26
32
|
|
|
27
33
|
use wasmtime::Linker;
|
|
28
34
|
use wiggle::GuestPtr;
|
|
29
35
|
|
|
30
|
-
use crate::descriptors::Descriptors;
|
|
31
36
|
use crate::invocation::Invocation;
|
|
32
37
|
use errno::Answer;
|
|
33
38
|
use memory::GuestMemory;
|
|
@@ -70,13 +75,11 @@ pub(crate) fn shadow(linker: &mut Linker<Invocation>) -> wasmtime::Result<()> {
|
|
|
70
75
|
Ok(())
|
|
71
76
|
}
|
|
72
77
|
|
|
73
|
-
fn table(invocation: &mut Invocation) -> &mut Descriptors {
|
|
74
|
-
invocation.wasi_mut().descriptors_mut()
|
|
75
|
-
}
|
|
76
|
-
|
|
77
78
|
impl Invocation {
|
|
78
79
|
/// Run one call against the calling instance's memory, answering what it
|
|
79
|
-
/// answers unless its host has given the invocation up by then
|
|
80
|
+
/// answers unless its host has given the invocation up by then, or the
|
|
81
|
+
/// run is to stop as the call returns: that ends the run there, as Linux's
|
|
82
|
+
/// `exit_to_user_mode` ends a task before it reads what the call answered.
|
|
80
83
|
fn answer<T>(
|
|
81
84
|
&mut self,
|
|
82
85
|
memory: &mut wiggle::GuestMemory<'_>,
|
|
@@ -84,7 +87,7 @@ impl Invocation {
|
|
|
84
87
|
) -> Answer<T> {
|
|
85
88
|
let fuel = self.hostcall_fuel();
|
|
86
89
|
let answer = call(&mut GuestMemory::new(memory, fuel), self);
|
|
87
|
-
match self.abandonment() {
|
|
90
|
+
match self.abandonment().or_else(crate::trap::fatal_signal_trap) {
|
|
88
91
|
Some(trap) => Err(types::Error::trap(trap)),
|
|
89
92
|
None => answer,
|
|
90
93
|
}
|
|
@@ -105,7 +108,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
105
108
|
_advice: types::Advice,
|
|
106
109
|
) -> Answer {
|
|
107
110
|
self.answer(memory, |_, inv| {
|
|
108
|
-
fd::advise(
|
|
111
|
+
fd::advise(inv.wasi_mut(), fd.into(), offset, len)
|
|
109
112
|
})
|
|
110
113
|
}
|
|
111
114
|
|
|
@@ -117,16 +120,16 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
117
120
|
len: types::Filesize,
|
|
118
121
|
) -> Answer {
|
|
119
122
|
self.answer(memory, |_, inv| {
|
|
120
|
-
fd::allocate(
|
|
123
|
+
fd::allocate(inv.wasi_mut(), fd.into(), offset, len)
|
|
121
124
|
})
|
|
122
125
|
}
|
|
123
126
|
|
|
124
127
|
fn fd_close(&mut self, memory: &mut wiggle::GuestMemory<'_>, fd: types::Fd) -> Answer {
|
|
125
|
-
self.answer(memory, |_, inv| fd::close(
|
|
128
|
+
self.answer(memory, |_, inv| fd::close(inv.wasi_mut(), fd.into()))
|
|
126
129
|
}
|
|
127
130
|
|
|
128
131
|
fn fd_datasync(&mut self, memory: &mut wiggle::GuestMemory<'_>, fd: types::Fd) -> Answer {
|
|
129
|
-
self.answer(memory, |_, inv| fd::sync(
|
|
132
|
+
self.answer(memory, |_, inv| fd::sync(inv.wasi_mut(), fd.into(), true))
|
|
130
133
|
}
|
|
131
134
|
|
|
132
135
|
fn fd_fdstat_get(
|
|
@@ -134,7 +137,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
134
137
|
memory: &mut wiggle::GuestMemory<'_>,
|
|
135
138
|
fd: types::Fd,
|
|
136
139
|
) -> Answer<types::Fdstat> {
|
|
137
|
-
self.answer(memory, |_, inv| fd::fdstat_get(
|
|
140
|
+
self.answer(memory, |_, inv| fd::fdstat_get(inv.wasi_mut(), fd.into()))
|
|
138
141
|
}
|
|
139
142
|
|
|
140
143
|
fn fd_fdstat_set_flags(
|
|
@@ -144,7 +147,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
144
147
|
flags: types::Fdflags,
|
|
145
148
|
) -> Answer {
|
|
146
149
|
self.answer(memory, |_, inv| {
|
|
147
|
-
fd::fdstat_set_flags(
|
|
150
|
+
fd::fdstat_set_flags(inv.wasi_mut(), fd.into(), flags)
|
|
148
151
|
})
|
|
149
152
|
}
|
|
150
153
|
|
|
@@ -156,7 +159,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
156
159
|
_fs_rights_inheriting: types::Rights,
|
|
157
160
|
) -> Answer {
|
|
158
161
|
self.answer(memory, |_, inv| {
|
|
159
|
-
fd::fdstat_set_rights(
|
|
162
|
+
fd::fdstat_set_rights(inv.wasi_mut(), fd.into())
|
|
160
163
|
})
|
|
161
164
|
}
|
|
162
165
|
|
|
@@ -165,7 +168,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
165
168
|
memory: &mut wiggle::GuestMemory<'_>,
|
|
166
169
|
fd: types::Fd,
|
|
167
170
|
) -> Answer<types::Filestat> {
|
|
168
|
-
self.answer(memory, |_, inv| fd::filestat_get(
|
|
171
|
+
self.answer(memory, |_, inv| fd::filestat_get(inv.wasi(), fd.into()))
|
|
169
172
|
}
|
|
170
173
|
|
|
171
174
|
fn fd_filestat_set_size(
|
|
@@ -175,7 +178,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
175
178
|
size: types::Filesize,
|
|
176
179
|
) -> Answer {
|
|
177
180
|
self.answer(memory, |_, inv| {
|
|
178
|
-
fd::filestat_set_size(
|
|
181
|
+
fd::filestat_set_size(inv.wasi_mut(), fd.into(), size)
|
|
179
182
|
})
|
|
180
183
|
}
|
|
181
184
|
|
|
@@ -189,7 +192,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
189
192
|
) -> Answer {
|
|
190
193
|
self.answer(memory, |_, inv| {
|
|
191
194
|
fd::utimensat(atim, mtim, fst_flags, |times| {
|
|
192
|
-
fd::filestat_set_times(
|
|
195
|
+
fd::filestat_set_times(inv.wasi(), fd.into(), times)
|
|
193
196
|
})
|
|
194
197
|
})
|
|
195
198
|
}
|
|
@@ -202,7 +205,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
202
205
|
offset: types::Filesize,
|
|
203
206
|
) -> Answer<types::Size> {
|
|
204
207
|
self.answer(memory, |mem, inv| {
|
|
205
|
-
fd::pread(
|
|
208
|
+
fd::pread(inv.wasi_mut(), mem, fd.into(), iovs, offset)
|
|
206
209
|
})
|
|
207
210
|
}
|
|
208
211
|
|
|
@@ -211,7 +214,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
211
214
|
memory: &mut wiggle::GuestMemory<'_>,
|
|
212
215
|
fd: types::Fd,
|
|
213
216
|
) -> Answer<types::Prestat> {
|
|
214
|
-
self.answer(memory, |_, inv| fd::prestat_get(
|
|
217
|
+
self.answer(memory, |_, inv| fd::prestat_get(inv.wasi_mut(), fd.into()))
|
|
215
218
|
}
|
|
216
219
|
|
|
217
220
|
fn fd_prestat_dir_name(
|
|
@@ -222,7 +225,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
222
225
|
path_max_len: types::Size,
|
|
223
226
|
) -> Answer {
|
|
224
227
|
self.answer(memory, |mem, inv| {
|
|
225
|
-
fd::prestat_dir_name(
|
|
228
|
+
fd::prestat_dir_name(inv.wasi_mut(), mem, fd.into(), path, path_max_len)
|
|
226
229
|
})
|
|
227
230
|
}
|
|
228
231
|
|
|
@@ -234,7 +237,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
234
237
|
offset: types::Filesize,
|
|
235
238
|
) -> Answer<types::Size> {
|
|
236
239
|
self.answer(memory, |mem, inv| {
|
|
237
|
-
fd::pwrite(
|
|
240
|
+
fd::pwrite(inv.wasi_mut(), mem, fd.into(), ciovs, offset)
|
|
238
241
|
})
|
|
239
242
|
}
|
|
240
243
|
|
|
@@ -245,7 +248,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
245
248
|
iovs: types::IovecArray,
|
|
246
249
|
) -> Answer<types::Size> {
|
|
247
250
|
self.answer(memory, |mem, inv| {
|
|
248
|
-
fd::read(
|
|
251
|
+
fd::read(inv.wasi_mut(), mem, fd.into(), iovs)
|
|
249
252
|
})
|
|
250
253
|
}
|
|
251
254
|
|
|
@@ -258,7 +261,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
258
261
|
cookie: types::Dircookie,
|
|
259
262
|
) -> Answer<types::Size> {
|
|
260
263
|
self.answer(memory, |mem, inv| {
|
|
261
|
-
fd::readdir(
|
|
264
|
+
fd::readdir(inv.wasi_mut(), mem, fd.into(), buf, buf_len, cookie)
|
|
262
265
|
})
|
|
263
266
|
}
|
|
264
267
|
|
|
@@ -269,7 +272,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
269
272
|
to: types::Fd,
|
|
270
273
|
) -> Answer {
|
|
271
274
|
self.answer(memory, |_, inv| {
|
|
272
|
-
fd::renumber(
|
|
275
|
+
fd::renumber(inv.wasi_mut(), from.into(), to.into())
|
|
273
276
|
})
|
|
274
277
|
}
|
|
275
278
|
|
|
@@ -281,12 +284,12 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
281
284
|
whence: types::Whence,
|
|
282
285
|
) -> Answer<types::Filesize> {
|
|
283
286
|
self.answer(memory, |_, inv| {
|
|
284
|
-
fd::seek(
|
|
287
|
+
fd::seek(inv.wasi_mut(), fd.into(), offset, whence)
|
|
285
288
|
})
|
|
286
289
|
}
|
|
287
290
|
|
|
288
291
|
fn fd_sync(&mut self, memory: &mut wiggle::GuestMemory<'_>, fd: types::Fd) -> Answer {
|
|
289
|
-
self.answer(memory, |_, inv| fd::sync(
|
|
292
|
+
self.answer(memory, |_, inv| fd::sync(inv.wasi_mut(), fd.into(), false))
|
|
290
293
|
}
|
|
291
294
|
|
|
292
295
|
fn fd_tell(
|
|
@@ -294,7 +297,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
294
297
|
memory: &mut wiggle::GuestMemory<'_>,
|
|
295
298
|
fd: types::Fd,
|
|
296
299
|
) -> Answer<types::Filesize> {
|
|
297
|
-
self.answer(memory, |_, inv| fd::tell(
|
|
300
|
+
self.answer(memory, |_, inv| fd::tell(inv.wasi_mut(), fd.into()))
|
|
298
301
|
}
|
|
299
302
|
|
|
300
303
|
fn fd_write(
|
|
@@ -304,7 +307,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
304
307
|
ciovs: types::CiovecArray,
|
|
305
308
|
) -> Answer<types::Size> {
|
|
306
309
|
self.answer(memory, |mem, inv| {
|
|
307
|
-
fd::write(
|
|
310
|
+
fd::write(inv.wasi_mut(), mem, fd.into(), ciovs)
|
|
308
311
|
})
|
|
309
312
|
}
|
|
310
313
|
|
|
@@ -315,7 +318,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
315
318
|
path: GuestPtr<str>,
|
|
316
319
|
) -> Answer {
|
|
317
320
|
self.answer(memory, |mem, inv| {
|
|
318
|
-
path::create_directory(
|
|
321
|
+
path::create_directory(inv.wasi(), mem, fd.into(), path)
|
|
319
322
|
})
|
|
320
323
|
}
|
|
321
324
|
|
|
@@ -327,7 +330,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
327
330
|
path: GuestPtr<str>,
|
|
328
331
|
) -> Answer<types::Filestat> {
|
|
329
332
|
self.answer(memory, |mem, inv| {
|
|
330
|
-
path::filestat_get(
|
|
333
|
+
path::filestat_get(inv.wasi(), mem, fd.into(), flags, path)
|
|
331
334
|
})
|
|
332
335
|
}
|
|
333
336
|
|
|
@@ -343,7 +346,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
343
346
|
) -> Answer {
|
|
344
347
|
self.answer(memory, |mem, inv| {
|
|
345
348
|
fd::utimensat(atim, mtim, fst_flags, |times| {
|
|
346
|
-
path::filestat_set_times(
|
|
349
|
+
path::filestat_set_times(inv.wasi(), mem, fd.into(), flags, path, times)
|
|
347
350
|
})
|
|
348
351
|
})
|
|
349
352
|
}
|
|
@@ -359,7 +362,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
359
362
|
) -> Answer {
|
|
360
363
|
self.answer(memory, |mem, inv| {
|
|
361
364
|
path::link(
|
|
362
|
-
|
|
365
|
+
inv.wasi_mut(),
|
|
363
366
|
mem,
|
|
364
367
|
(old_fd.into(), old_path),
|
|
365
368
|
(new_fd.into(), new_path),
|
|
@@ -381,7 +384,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
381
384
|
) -> Answer<types::Fd> {
|
|
382
385
|
self.answer(memory, |mem, inv| {
|
|
383
386
|
path::open(
|
|
384
|
-
|
|
387
|
+
inv.wasi_mut(),
|
|
385
388
|
mem,
|
|
386
389
|
fd.into(),
|
|
387
390
|
path,
|
|
@@ -404,7 +407,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
404
407
|
buf_len: types::Size,
|
|
405
408
|
) -> Answer<types::Size> {
|
|
406
409
|
self.answer(memory, |mem, inv| {
|
|
407
|
-
path::readlink(
|
|
410
|
+
path::readlink(inv.wasi(), mem, fd.into(), path, buf, buf_len)
|
|
408
411
|
})
|
|
409
412
|
}
|
|
410
413
|
|
|
@@ -415,7 +418,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
415
418
|
path: GuestPtr<str>,
|
|
416
419
|
) -> Answer {
|
|
417
420
|
self.answer(memory, |mem, inv| {
|
|
418
|
-
path::remove_directory(
|
|
421
|
+
path::remove_directory(inv.wasi(), mem, fd.into(), path)
|
|
419
422
|
})
|
|
420
423
|
}
|
|
421
424
|
|
|
@@ -429,7 +432,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
429
432
|
) -> Answer {
|
|
430
433
|
self.answer(memory, |mem, inv| {
|
|
431
434
|
path::rename(
|
|
432
|
-
|
|
435
|
+
inv.wasi_mut(),
|
|
433
436
|
mem,
|
|
434
437
|
(old_fd.into(), old_path),
|
|
435
438
|
(new_fd.into(), new_path),
|
|
@@ -445,7 +448,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
445
448
|
new_path: GuestPtr<str>,
|
|
446
449
|
) -> Answer {
|
|
447
450
|
self.answer(memory, |mem, inv| {
|
|
448
|
-
path::symlink(
|
|
451
|
+
path::symlink(inv.wasi(), mem, old_path, fd.into(), new_path)
|
|
449
452
|
})
|
|
450
453
|
}
|
|
451
454
|
|
|
@@ -456,7 +459,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
456
459
|
path: GuestPtr<str>,
|
|
457
460
|
) -> Answer {
|
|
458
461
|
self.answer(memory, |mem, inv| {
|
|
459
|
-
path::unlink_file(
|
|
462
|
+
path::unlink_file(inv.wasi(), mem, fd.into(), path)
|
|
460
463
|
})
|
|
461
464
|
}
|
|
462
465
|
|
|
@@ -472,13 +475,26 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
472
475
|
})
|
|
473
476
|
}
|
|
474
477
|
|
|
478
|
+
fn random_get(
|
|
479
|
+
&mut self,
|
|
480
|
+
memory: &mut wiggle::GuestMemory<'_>,
|
|
481
|
+
buf: GuestPtr<u8>,
|
|
482
|
+
len: types::Size,
|
|
483
|
+
) -> Answer {
|
|
484
|
+
self.answer(memory, |mem, inv| {
|
|
485
|
+
random::get(mem, inv.wasi_mut(), buf, len)
|
|
486
|
+
})
|
|
487
|
+
}
|
|
488
|
+
|
|
475
489
|
fn sock_accept(
|
|
476
490
|
&mut self,
|
|
477
491
|
memory: &mut wiggle::GuestMemory<'_>,
|
|
478
492
|
fd: types::Fd,
|
|
479
493
|
_flags: types::Fdflags,
|
|
480
494
|
) -> Answer<types::Fd> {
|
|
481
|
-
self.answer(memory, |_, inv|
|
|
495
|
+
self.answer(memory, |_, inv| {
|
|
496
|
+
sock::refuse_socket_call(inv.wasi_mut(), fd.into())
|
|
497
|
+
})
|
|
482
498
|
}
|
|
483
499
|
|
|
484
500
|
fn sock_recv(
|
|
@@ -488,7 +504,9 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
488
504
|
_ri_data: types::IovecArray,
|
|
489
505
|
_ri_flags: types::Riflags,
|
|
490
506
|
) -> Answer<(types::Size, types::Roflags)> {
|
|
491
|
-
self.answer(memory, |_, inv|
|
|
507
|
+
self.answer(memory, |_, inv| {
|
|
508
|
+
sock::refuse_socket_call(inv.wasi_mut(), fd.into())
|
|
509
|
+
})
|
|
492
510
|
}
|
|
493
511
|
|
|
494
512
|
fn sock_send(
|
|
@@ -498,7 +516,9 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
498
516
|
_si_data: types::CiovecArray,
|
|
499
517
|
_si_flags: types::Siflags,
|
|
500
518
|
) -> Answer<types::Size> {
|
|
501
|
-
self.answer(memory, |_, inv|
|
|
519
|
+
self.answer(memory, |_, inv| {
|
|
520
|
+
sock::refuse_socket_call(inv.wasi_mut(), fd.into())
|
|
521
|
+
})
|
|
502
522
|
}
|
|
503
523
|
|
|
504
524
|
fn sock_shutdown(
|
|
@@ -507,6 +527,66 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for Invocation {
|
|
|
507
527
|
fd: types::Fd,
|
|
508
528
|
_how: types::Sdflags,
|
|
509
529
|
) -> Answer {
|
|
510
|
-
self.answer(memory, |_, inv|
|
|
530
|
+
self.answer(memory, |_, inv| {
|
|
531
|
+
sock::refuse_socket_call(inv.wasi_mut(), fd.into())
|
|
532
|
+
})
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
#[cfg(test)]
|
|
537
|
+
mod tests {
|
|
538
|
+
use std::time::Instant;
|
|
539
|
+
|
|
540
|
+
use wasmtime::{Module, Store};
|
|
541
|
+
|
|
542
|
+
use crate::cache::load_engine;
|
|
543
|
+
use crate::config::Config;
|
|
544
|
+
use crate::imports;
|
|
545
|
+
use crate::invocation::Invocation;
|
|
546
|
+
use crate::trap::NO_TIMEOUT_EPOCH_DELTA;
|
|
547
|
+
use crate::wasi::Wasi;
|
|
548
|
+
use kobako_runtime::profile::Profile;
|
|
549
|
+
use kobako_runtime::sched::run_task;
|
|
550
|
+
|
|
551
|
+
/// Ask for no entropy, then answer 7 once the guest reads what the call
|
|
552
|
+
/// answered.
|
|
553
|
+
const CALL_WAT: &str = r#"
|
|
554
|
+
(module
|
|
555
|
+
(import "wasi_snapshot_preview1" "random_get"
|
|
556
|
+
(func $random (param i32 i32) (result i32)))
|
|
557
|
+
(memory (export "memory") 1)
|
|
558
|
+
(func (export "read_nothing") (result i32)
|
|
559
|
+
(drop (call $random (i32.const 0) (i32.const 0)))
|
|
560
|
+
(i32.const 7)))
|
|
561
|
+
"#;
|
|
562
|
+
|
|
563
|
+
// @behavior RT-426
|
|
564
|
+
#[test]
|
|
565
|
+
fn a_host_call_returning_past_its_runs_deadline_ends_the_run_there() {
|
|
566
|
+
let engine = load_engine().expect("shared engine must be constructible");
|
|
567
|
+
let config = Config::for_profile(Profile::Hermetic);
|
|
568
|
+
let wasi = Wasi::for_invocation(&config, &[]).expect("WASI context must build");
|
|
569
|
+
let mut store = Store::new(engine, Invocation::new(wasi));
|
|
570
|
+
store.set_epoch_deadline(NO_TIMEOUT_EPOCH_DELTA);
|
|
571
|
+
let module = Module::new(engine, CALL_WAT).expect("call module must compile");
|
|
572
|
+
let instance = imports::linker()
|
|
573
|
+
.expect("host imports must link")
|
|
574
|
+
.instantiate(&mut store, &module)
|
|
575
|
+
.expect("call module must instantiate");
|
|
576
|
+
let read = instance
|
|
577
|
+
.get_typed_func::<(), i32>(&mut store, "read_nothing")
|
|
578
|
+
.expect("call export must resolve");
|
|
579
|
+
let deadline = Some(Instant::now());
|
|
580
|
+
store.data_mut().set_deadline(deadline);
|
|
581
|
+
let ended = run_task(deadline, || read.call(&mut store, ()));
|
|
582
|
+
assert!(
|
|
583
|
+
ended
|
|
584
|
+
.as_ref()
|
|
585
|
+
.err()
|
|
586
|
+
.is_some_and(|trap| trap.is::<crate::trap::TimeoutTrap>()),
|
|
587
|
+
"a random_get returning once its run's deadline passed must end the run as timed \
|
|
588
|
+
out before the guest reads what it answered; got {:?}",
|
|
589
|
+
ended.map_err(|trap| trap.to_string())
|
|
590
|
+
);
|
|
511
591
|
}
|
|
512
592
|
}
|