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
|
@@ -4,35 +4,34 @@
|
|
|
4
4
|
//! A `Driver` is the engine half of a kobako host — the pre-linked
|
|
5
5
|
//! `InstancePre` plus the per-Driver caps — and implements the contract
|
|
6
6
|
//! `Runtime` trait over it. It is free of any frontend type; a frontend
|
|
7
|
-
//!
|
|
8
|
-
//! host-language values across the contract boundary.
|
|
7
|
+
//! only shuttles its host-language values across the contract boundary.
|
|
9
8
|
|
|
10
9
|
use std::path::Path;
|
|
11
10
|
use std::sync::Arc;
|
|
12
11
|
|
|
13
|
-
use wasmtime::{
|
|
14
|
-
AsContextMut, InstancePre as WtInstancePre, ResourceLimiter, Store as WtStore, TypedFunc,
|
|
15
|
-
};
|
|
12
|
+
use wasmtime::{AsContextMut, InstancePre as WtInstancePre, ResourceLimiter, Store as WtStore};
|
|
16
13
|
|
|
17
|
-
use crate::cache::
|
|
14
|
+
use crate::cache::load_engine;
|
|
18
15
|
use crate::config::Config;
|
|
19
16
|
use crate::exports::{self, Exports};
|
|
17
|
+
use crate::guest::Guest;
|
|
20
18
|
use crate::invocation::Invocation;
|
|
21
19
|
use crate::wasi::Wasi;
|
|
22
|
-
use crate::{
|
|
20
|
+
use crate::{instance_pre, trap};
|
|
23
21
|
use kobako_runtime::dispatch::DispatchHandler;
|
|
22
|
+
use kobako_runtime::endpoint;
|
|
24
23
|
use kobako_runtime::error::{InvokeError, SetupError, Trap};
|
|
25
24
|
use kobako_runtime::grant::{Grant, GrantKind};
|
|
26
25
|
use kobako_runtime::profile::Profile;
|
|
27
26
|
use kobako_runtime::runtime::{Entry, Runtime as ContractRuntime};
|
|
28
27
|
use kobako_runtime::snapshot::{Capture, Completion, Snapshot, Usage};
|
|
29
|
-
use kobako_transport::envelope::
|
|
28
|
+
use kobako_transport::envelope::Preamble;
|
|
30
29
|
|
|
31
30
|
/// The wasmtime execution unit behind one sandbox runtime.
|
|
32
31
|
pub struct Driver {
|
|
33
32
|
// Pre-linked instantiation template (import wiring, type checks,
|
|
34
33
|
// and the ABI version check done once in
|
|
35
|
-
// `instance_pre::
|
|
34
|
+
// `instance_pre::load_instance_pre`). Every invocation
|
|
36
35
|
// instantiates a fresh instance from it and discards the whole
|
|
37
36
|
// Store afterwards — the per-invocation instance discipline.
|
|
38
37
|
instance_pre: WtInstancePre<Invocation>,
|
|
@@ -44,9 +43,9 @@ impl Driver {
|
|
|
44
43
|
/// Load the Guest Binary at `path` and verify its ABI version. The
|
|
45
44
|
/// Engine is shared by the process and the Module cached per path;
|
|
46
45
|
/// neither leaves the driver.
|
|
47
|
-
pub fn
|
|
46
|
+
pub fn from_file(path: &Path, config: Config) -> Result<Self, SetupError> {
|
|
48
47
|
Ok(Self {
|
|
49
|
-
instance_pre: instance_pre::
|
|
48
|
+
instance_pre: instance_pre::load_instance_pre(path, config.limits.setup_timeout)?,
|
|
50
49
|
config,
|
|
51
50
|
})
|
|
52
51
|
}
|
|
@@ -55,12 +54,9 @@ impl Driver {
|
|
|
55
54
|
/// instantiating the guest and writing its request count against the
|
|
56
55
|
/// `timeout` as the export call does.
|
|
57
56
|
fn new_store(&self, wasi: Wasi) -> Result<WtStore<Invocation>, SetupError> {
|
|
58
|
-
let mut store = WtStore::new(
|
|
59
|
-
shared_engine()?,
|
|
60
|
-
Invocation::new(self.config.memory_limit, wasi),
|
|
61
|
-
);
|
|
57
|
+
let mut store = WtStore::new(load_engine()?, Invocation::new(wasi));
|
|
62
58
|
store.limiter(|state: &mut Invocation| -> &mut dyn ResourceLimiter { state.limiter_mut() });
|
|
63
|
-
trap::arm_deadline(&mut store, self.config.timeout);
|
|
59
|
+
trap::arm_deadline(&mut store, self.config.limits.timeout);
|
|
64
60
|
store.data_mut().start_wall_clock();
|
|
65
61
|
Ok(store)
|
|
66
62
|
}
|
|
@@ -72,7 +68,7 @@ impl Driver {
|
|
|
72
68
|
.instance_pre
|
|
73
69
|
.instantiate(store.as_context_mut())
|
|
74
70
|
.map_err(|e| {
|
|
75
|
-
trap::
|
|
71
|
+
trap::cap_trap_of(&e).unwrap_or_else(|| {
|
|
76
72
|
Trap::Other(format!("failed to instantiate the Sandbox runtime: {e}"))
|
|
77
73
|
})
|
|
78
74
|
})?;
|
|
@@ -81,35 +77,39 @@ impl Driver {
|
|
|
81
77
|
Ok(exports)
|
|
82
78
|
}
|
|
83
79
|
|
|
84
|
-
///
|
|
85
|
-
///
|
|
86
|
-
///
|
|
87
|
-
|
|
80
|
+
/// Instantiate the guest in `store`, write `request` into it, and call
|
|
81
|
+
/// the downcall under the invocation's caps, answering the return area
|
|
82
|
+
/// that names its answer. A fault before the call starts is the outer
|
|
83
|
+
/// `Err`, the call's own the inner one. Disarm runs whether the call returns or traps, so
|
|
84
|
+
/// the `wall_time` bracket and the memory budget always close.
|
|
85
|
+
fn downcall(
|
|
88
86
|
&self,
|
|
89
87
|
store: &mut WtStore<Invocation>,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
let result =
|
|
88
|
+
request: &[u8],
|
|
89
|
+
) -> Result<wasmtime::Result<u32>, InvokeError> {
|
|
90
|
+
let exports = self.instantiate(store)?;
|
|
91
|
+
let downcall = exports::require(exports.downcall.as_ref())?;
|
|
92
|
+
let (ptr, len) = endpoint::write_request(&mut guest_of(store), request)?;
|
|
93
|
+
self.arm_memory_budget(store, &exports);
|
|
94
|
+
// A wait for a lock the call meets ends at the same deadline the guest's
|
|
95
|
+
// code does, so another Sandbox holding it cannot keep this one past it.
|
|
96
|
+
let deadline = store.data().deadline();
|
|
97
|
+
let result = kobako_runtime::sched::run_task(deadline, || {
|
|
98
|
+
downcall.call(store.as_context_mut(), (ptr, len))
|
|
99
|
+
});
|
|
100
100
|
disarm_caps(store);
|
|
101
|
-
result
|
|
101
|
+
Ok(result)
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
/// The pre-initialized image's allocation is folded into the memory
|
|
105
|
-
/// baseline rather than the budget, so the
|
|
105
|
+
/// baseline rather than the budget, so the budget arms only once the
|
|
106
106
|
/// image is in place.
|
|
107
|
-
fn
|
|
107
|
+
fn arm_memory_budget(&self, store: &mut WtStore<Invocation>, exports: &Exports) {
|
|
108
108
|
let baseline = match exports.memory {
|
|
109
109
|
Some(m) => m.data_size(store.as_context_mut()),
|
|
110
110
|
None => 0,
|
|
111
111
|
};
|
|
112
|
-
store.data_mut().
|
|
112
|
+
store.data_mut().arm_memory_budget(baseline);
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
/// Built the same for every `completion`: captures and usage must
|
|
@@ -119,15 +119,10 @@ impl Driver {
|
|
|
119
119
|
let mut usage = Usage::default();
|
|
120
120
|
usage.wall_time = data.wall_time().as_secs_f64();
|
|
121
121
|
usage.memory_peak = data.memory_peak();
|
|
122
|
-
let clip = |bytes, limit| {
|
|
123
|
-
let mut capture = Capture::default();
|
|
124
|
-
(capture.bytes, capture.truncated) = capture::clip_capture(bytes, limit);
|
|
125
|
-
capture
|
|
126
|
-
};
|
|
127
122
|
Snapshot::new(
|
|
128
123
|
completion,
|
|
129
|
-
|
|
130
|
-
|
|
124
|
+
Capture::new(data.wasi().stdout_bytes(), self.config.limits.stdout_limit),
|
|
125
|
+
Capture::new(data.wasi().stderr_bytes(), self.config.limits.stderr_limit),
|
|
131
126
|
usage,
|
|
132
127
|
)
|
|
133
128
|
}
|
|
@@ -145,28 +140,17 @@ impl ContractRuntime for Driver {
|
|
|
145
140
|
handler: Option<Arc<dyn DispatchHandler>>,
|
|
146
141
|
grants: &[Grant],
|
|
147
142
|
) -> Result<Snapshot, InvokeError> {
|
|
148
|
-
let
|
|
143
|
+
let preamble =
|
|
144
|
+
endpoint::preamble_bytes(preamble).map_err(|msg| Trap::Other(msg.to_string()))?;
|
|
145
|
+
let wasi = Wasi::for_invocation(&self.config, grants)?;
|
|
149
146
|
let mut store = self.new_store(wasi)?;
|
|
147
|
+
store.data_mut().set_preamble(preamble);
|
|
150
148
|
if let Some(handler) = handler {
|
|
151
149
|
store.data_mut().bind_on_dispatch(handler);
|
|
152
150
|
}
|
|
153
|
-
let
|
|
154
|
-
let downcall = exports::require(exports.downcall.as_ref())?;
|
|
155
|
-
let request = match entry {
|
|
156
|
-
Entry::Eval { source } => Downcall::Eval(source.to_vec()),
|
|
157
|
-
Entry::Run {
|
|
158
|
-
entrypoint,
|
|
159
|
-
payload,
|
|
160
|
-
} => Downcall::Run(Run {
|
|
161
|
-
entrypoint: entrypoint.to_owned(),
|
|
162
|
-
payload,
|
|
163
|
-
}),
|
|
164
|
-
}
|
|
165
|
-
.encode();
|
|
166
|
-
let (ptr, len) = io::write_request(&mut store, &exports, &request)?;
|
|
167
|
-
let called = self.call_with_caps(&mut store, &exports, downcall, (ptr, len));
|
|
151
|
+
let called = self.downcall(&mut store, &endpoint::request_of(entry))?;
|
|
168
152
|
let completion = match called {
|
|
169
|
-
Ok(
|
|
153
|
+
Ok(ret) => match endpoint::read_outcome(&mut guest_of(&mut store), ret) {
|
|
170
154
|
Ok(outcome) => Completion::Outcome(outcome),
|
|
171
155
|
Err(t) => Completion::Trap(t),
|
|
172
156
|
},
|
|
@@ -175,110 +159,44 @@ impl ContractRuntime for Driver {
|
|
|
175
159
|
Ok(self.build_snapshot(&store, completion))
|
|
176
160
|
}
|
|
177
161
|
|
|
178
|
-
/// Exactly the
|
|
179
|
-
/// and entropy; both
|
|
180
|
-
/// and the linker adds only `
|
|
162
|
+
/// Exactly the profile `Config` requested. `Hermetic` freezes ambient time
|
|
163
|
+
/// and entropy; both profiles wire no ambient filesystem, environment, or network,
|
|
164
|
+
/// and the linker adds only the kobako ABI's `upcall` and `preamble`
|
|
165
|
+
/// beyond that WASI surface.
|
|
181
166
|
fn profile(&self) -> Profile {
|
|
182
167
|
self.config.profile
|
|
183
168
|
}
|
|
184
169
|
|
|
185
|
-
///
|
|
186
|
-
/// answers every preview1 call beneath it
|
|
170
|
+
/// An outermost Mount becomes a preopen of kobako's own descriptor table,
|
|
171
|
+
/// which answers every preview1 call beneath it; the network entries become one
|
|
172
|
+
/// network the preview2 sockets reach.
|
|
187
173
|
fn supports(&self, kind: GrantKind) -> bool {
|
|
188
|
-
matches!(kind, GrantKind::Mount)
|
|
174
|
+
matches!(kind, GrantKind::Mount | GrantKind::Network)
|
|
189
175
|
}
|
|
190
176
|
|
|
191
177
|
/// Bounded by the same caps as an invocation, on an instance of its
|
|
192
178
|
/// own that no script ever runs on, so what it answers carries
|
|
193
179
|
/// nothing a script could have written.
|
|
194
180
|
fn compile(&self, preamble: &Preamble) -> Option<Vec<Vec<u8>>> {
|
|
195
|
-
let
|
|
181
|
+
let bytes = endpoint::preamble_bytes(preamble).ok()?;
|
|
182
|
+
let wasi = Wasi::for_compile(&self.config).ok()?;
|
|
196
183
|
let mut store = self.new_store(wasi).ok()?;
|
|
197
|
-
|
|
198
|
-
let
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
let packed = self
|
|
202
|
-
.call_with_caps(&mut store, &exports, downcall, (ptr, len))
|
|
184
|
+
store.data_mut().set_preamble(bytes);
|
|
185
|
+
let ret = self
|
|
186
|
+
.downcall(&mut store, &endpoint::compile_request())
|
|
187
|
+
.ok()?
|
|
203
188
|
.ok()?;
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
.filter(|bytecodes| replay_fits(preamble, bytecodes)),
|
|
207
|
-
CompileReply::Error(_) | CompileReply::Unsupported(_) => None,
|
|
208
|
-
}
|
|
189
|
+
let reply = endpoint::read_compile_reply(&mut guest_of(&mut store), ret).ok()?;
|
|
190
|
+
endpoint::compiled_bytecodes(preamble, reply)
|
|
209
191
|
}
|
|
210
192
|
}
|
|
211
193
|
|
|
212
|
-
///
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
fn replay_fits(preamble: &Preamble, bytecodes: &[Vec<u8>]) -> bool {
|
|
216
|
-
let mut replay = preamble.clone();
|
|
217
|
-
let sources = replay
|
|
218
|
-
.snippets
|
|
219
|
-
.entries
|
|
220
|
-
.iter_mut()
|
|
221
|
-
.filter(|entry| matches!(entry, Snippet::Source { .. }));
|
|
222
|
-
for (entry, body) in sources.zip(bytecodes) {
|
|
223
|
-
*entry = Snippet::Bytecode { body: body.clone() };
|
|
224
|
-
}
|
|
225
|
-
guest_mem::checked_payload_len(replay.encode().len()).is_ok()
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/// A frontend replays each bytecode in place of one source snippet, in
|
|
229
|
-
/// order, so an answer of any other length leaves nothing to replay.
|
|
230
|
-
fn one_per_source(preamble: &Preamble, bytecodes: Vec<Vec<u8>>) -> Option<Vec<Vec<u8>>> {
|
|
231
|
-
let sources = preamble
|
|
232
|
-
.snippets
|
|
233
|
-
.entries
|
|
234
|
-
.iter()
|
|
235
|
-
.filter(|entry| matches!(entry, Snippet::Source { .. }))
|
|
236
|
-
.count();
|
|
237
|
-
(bytecodes.len() == sources).then_some(bytecodes)
|
|
194
|
+
/// The instance the runtime's host ABI endpoint drives, through `store`.
|
|
195
|
+
fn guest_of(store: &mut WtStore<Invocation>) -> Guest<'_> {
|
|
196
|
+
Guest(store.as_context_mut())
|
|
238
197
|
}
|
|
239
198
|
|
|
240
199
|
fn disarm_caps(store: &mut WtStore<Invocation>) {
|
|
241
200
|
store.data_mut().stop_wall_clock();
|
|
242
|
-
store.data_mut().
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
#[cfg(test)]
|
|
246
|
-
mod tests {
|
|
247
|
-
use kobako_transport::envelope::Snippets;
|
|
248
|
-
|
|
249
|
-
use super::*;
|
|
250
|
-
|
|
251
|
-
/// One source between two bytecode snippets: a compile answers one
|
|
252
|
-
/// bytecode for it.
|
|
253
|
-
fn one_source() -> Preamble {
|
|
254
|
-
let mut preamble = Preamble::default();
|
|
255
|
-
preamble.snippets = Snippets {
|
|
256
|
-
entries: vec![
|
|
257
|
-
Snippet::Bytecode { body: vec![0xaa] },
|
|
258
|
-
Snippet::Source {
|
|
259
|
-
name: "Only".into(),
|
|
260
|
-
body: "1".into(),
|
|
261
|
-
},
|
|
262
|
-
Snippet::Bytecode { body: vec![0xbb] },
|
|
263
|
-
],
|
|
264
|
-
};
|
|
265
|
-
preamble
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// @behavior WE-089
|
|
269
|
-
#[test]
|
|
270
|
-
fn a_compiled_answer_of_another_length_leaves_nothing_compiled() {
|
|
271
|
-
let preamble = one_source();
|
|
272
|
-
|
|
273
|
-
assert_eq!(
|
|
274
|
-
[
|
|
275
|
-
one_per_source(&preamble, Vec::new()),
|
|
276
|
-
one_per_source(&preamble, vec![vec![0x01], vec![0x02]]),
|
|
277
|
-
one_per_source(&preamble, vec![vec![0x01]]),
|
|
278
|
-
],
|
|
279
|
-
[None, None, Some(vec![vec![0x01]])],
|
|
280
|
-
"a compiled answer through Driver#compile must be kept only when it carries one \
|
|
281
|
-
bytecode per source snippet"
|
|
282
|
-
);
|
|
283
|
-
}
|
|
201
|
+
store.data_mut().disarm_memory_budget();
|
|
284
202
|
}
|
|
@@ -10,19 +10,14 @@
|
|
|
10
10
|
|
|
11
11
|
use wasmtime::{AsContextMut, Instance as WtInstance, Memory, TypedFunc};
|
|
12
12
|
|
|
13
|
-
use
|
|
13
|
+
use kobako_runtime::endpoint::RUNTIME_INCOMPATIBLE;
|
|
14
14
|
use kobako_runtime::error::Trap;
|
|
15
|
-
|
|
16
|
-
/// For a required guest export that is absent or mistyped, wherever it is
|
|
17
|
-
/// looked up. Names neither the export nor a frontend's artifact path;
|
|
18
|
-
/// what a caller can do is rebuild the runtime.
|
|
19
|
-
pub(crate) const RUNTIME_INCOMPATIBLE: &str =
|
|
20
|
-
"the Sandbox runtime is incompatible; rebuild it against the kobako version in use";
|
|
15
|
+
use kobako_transport::abi::DOWNCALL_EXPORT;
|
|
21
16
|
|
|
22
17
|
/// The resolved host-driven export handles. Each is `Option` because test
|
|
23
18
|
/// fixtures (a minimal "ping" module) need not provide them; real
|
|
24
|
-
/// `kobako.wasm` always does, and the run path surfaces a `Trap`
|
|
25
|
-
///
|
|
19
|
+
/// `kobako.wasm` always does, and the run path surfaces a `Trap` when a
|
|
20
|
+
/// handle is `None`.
|
|
26
21
|
///
|
|
27
22
|
/// The handles are indices into the owning Store, not borrows of the
|
|
28
23
|
/// `Instance` — they stay valid for the Store's lifetime, which is why
|
|
@@ -30,8 +25,8 @@ pub(crate) const RUNTIME_INCOMPATIBLE: &str =
|
|
|
30
25
|
/// own data for the host imports to reach.
|
|
31
26
|
#[derive(Clone)]
|
|
32
27
|
pub(crate) struct Exports {
|
|
33
|
-
pub(crate) downcall: Option<TypedFunc<(i32, i32),
|
|
34
|
-
pub(crate)
|
|
28
|
+
pub(crate) downcall: Option<TypedFunc<(i32, i32), u32>>,
|
|
29
|
+
pub(crate) realloc: Option<TypedFunc<(u32, u32, u32, u32), u32>>,
|
|
35
30
|
pub(crate) memory: Option<Memory>,
|
|
36
31
|
}
|
|
37
32
|
|
|
@@ -41,19 +36,14 @@ impl Exports {
|
|
|
41
36
|
pub(crate) fn resolve(instance: &WtInstance, mut ctx: impl AsContextMut) -> Self {
|
|
42
37
|
Self {
|
|
43
38
|
downcall: instance
|
|
44
|
-
.get_typed_func::<(i32, i32),
|
|
39
|
+
.get_typed_func::<(i32, i32), u32>(&mut ctx, DOWNCALL_EXPORT)
|
|
45
40
|
.ok(),
|
|
46
|
-
|
|
47
|
-
.get_typed_func::<u32, u32>(&mut ctx, "
|
|
41
|
+
realloc: instance
|
|
42
|
+
.get_typed_func::<(u32, u32, u32, u32), u32>(&mut ctx, "cabi_realloc")
|
|
48
43
|
.ok(),
|
|
49
44
|
memory: instance.get_memory(&mut ctx, "memory"),
|
|
50
45
|
}
|
|
51
46
|
}
|
|
52
|
-
|
|
53
|
-
pub(crate) fn require_memory(&self) -> Result<Memory, Trap> {
|
|
54
|
-
self.memory
|
|
55
|
-
.ok_or_else(|| Trap::Other(SANDBOX_RUNTIME_NOT_KOBAKO.to_string()))
|
|
56
|
-
}
|
|
57
47
|
}
|
|
58
48
|
|
|
59
49
|
pub(crate) fn require<Params, Results>(
|
|
@@ -75,30 +65,30 @@ mod tests {
|
|
|
75
65
|
//! CI (which always builds it) and a silent skip locally.
|
|
76
66
|
use std::path::Path;
|
|
77
67
|
|
|
78
|
-
use
|
|
68
|
+
use kobako_runtime::profile::Profile;
|
|
69
|
+
use kobako_transport::abi::DOWNCALL_EXPORT;
|
|
70
|
+
use wasmtime::{ExternType, Store};
|
|
79
71
|
|
|
80
|
-
use crate::cache::
|
|
72
|
+
use crate::cache::{load_engine, load_module};
|
|
73
|
+
use crate::config::Config;
|
|
74
|
+
use crate::guest_binary;
|
|
75
|
+
use crate::imports;
|
|
76
|
+
use crate::invocation::Invocation;
|
|
77
|
+
use crate::trap::NO_TIMEOUT_EPOCH_DELTA;
|
|
78
|
+
use crate::wasi::Wasi;
|
|
81
79
|
|
|
82
80
|
const WASM: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../data/kobako.wasm");
|
|
83
81
|
|
|
84
|
-
const ABI_EXPORTS: [&str;
|
|
85
|
-
"__kobako_abi_version",
|
|
86
|
-
"__kobako_alloc",
|
|
87
|
-
"__kobako_downcall",
|
|
88
|
-
];
|
|
82
|
+
const ABI_EXPORTS: [&str; 2] = ["cabi_realloc", DOWNCALL_EXPORT];
|
|
89
83
|
|
|
90
84
|
// @behavior RT-068
|
|
91
85
|
#[test]
|
|
92
86
|
fn the_guest_binary_exports_the_abi_functions_and_nothing_else() {
|
|
93
87
|
let path = Path::new(WASM);
|
|
94
|
-
if !path.exists() {
|
|
95
|
-
assert!(
|
|
96
|
-
std::env::var_os("CI").is_none(),
|
|
97
|
-
"data/kobako.wasm missing under CI — run `bundle exec rake wasm:build`"
|
|
98
|
-
);
|
|
88
|
+
if !guest_binary::built(path.exists(), "data/kobako.wasm") {
|
|
99
89
|
return;
|
|
100
90
|
}
|
|
101
|
-
let module =
|
|
91
|
+
let module = load_module(path).expect("the Guest Binary must load");
|
|
102
92
|
|
|
103
93
|
let mut functions: Vec<&str> = module
|
|
104
94
|
.exports()
|
|
@@ -112,4 +102,129 @@ mod tests {
|
|
|
112
102
|
"data/kobako.wasm read through its export section must export exactly the ABI's functions"
|
|
113
103
|
);
|
|
114
104
|
}
|
|
105
|
+
|
|
106
|
+
// @behavior RT-375
|
|
107
|
+
#[test]
|
|
108
|
+
fn the_guest_binary_hands_an_empty_list_no_room_and_traps_with_none_left() {
|
|
109
|
+
let path = Path::new(WASM);
|
|
110
|
+
if !guest_binary::built(path.exists(), "data/kobako.wasm") {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
let module = load_module(path).expect("the Guest Binary must load");
|
|
114
|
+
let config = Config::for_profile(Profile::Hermetic);
|
|
115
|
+
let wasi = Wasi::for_invocation(&config, &[]).expect("WASI context must build");
|
|
116
|
+
let mut store = Store::new(
|
|
117
|
+
load_engine().expect("shared engine must be constructible"),
|
|
118
|
+
Invocation::new(wasi),
|
|
119
|
+
);
|
|
120
|
+
store.set_epoch_deadline(NO_TIMEOUT_EPOCH_DELTA);
|
|
121
|
+
let instance = imports::linker()
|
|
122
|
+
.expect("host imports must link")
|
|
123
|
+
.instantiate(&mut store, &module)
|
|
124
|
+
.expect("the Guest Binary must instantiate");
|
|
125
|
+
let realloc = instance
|
|
126
|
+
.get_typed_func::<(i32, i32, i32, i32), i32>(&mut store, "cabi_realloc")
|
|
127
|
+
.expect("the Guest Binary exports cabi_realloc");
|
|
128
|
+
let empty = [
|
|
129
|
+
realloc.call(&mut store, (0, 0, 4, 0)).ok(),
|
|
130
|
+
realloc.call(&mut store, (0, 0, 4, 0)).ok(),
|
|
131
|
+
];
|
|
132
|
+
let past = realloc.call(&mut store, (0, 0, 1, i32::MAX)).is_err();
|
|
133
|
+
assert_eq!(
|
|
134
|
+
(empty, past),
|
|
135
|
+
([Some(4), Some(4)], true),
|
|
136
|
+
"cabi_realloc asked twice for an empty list on 4 must answer 4 and take no room, and \
|
|
137
|
+
asked for more room than the Guest Binary has must trap rather than answer 0"
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/// Where a function's calls can lead: the imports it reaches, and whether
|
|
142
|
+
/// it reaches a call through the function table, which could be any.
|
|
143
|
+
#[derive(Debug, Default, PartialEq)]
|
|
144
|
+
struct Reach {
|
|
145
|
+
imports: Vec<String>,
|
|
146
|
+
indirect: bool,
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/// What the export `name` of the module in `bytes` can reach through its
|
|
150
|
+
/// direct calls.
|
|
151
|
+
fn reach_of(bytes: &[u8], name: &str) -> Reach {
|
|
152
|
+
use wasmparser::{ExternalKind, Operator, Parser, Payload, TypeRef};
|
|
153
|
+
|
|
154
|
+
let (mut imports, mut start) = (Vec::new(), None);
|
|
155
|
+
let mut bodies: Vec<(Vec<u32>, bool)> = Vec::new();
|
|
156
|
+
for payload in Parser::new(0).parse_all(bytes) {
|
|
157
|
+
match payload.expect("the Guest Binary parses") {
|
|
158
|
+
Payload::ImportSection(section) => {
|
|
159
|
+
for import in section.into_imports() {
|
|
160
|
+
let import = import.expect("an import parses");
|
|
161
|
+
if matches!(import.ty, TypeRef::Func(_)) {
|
|
162
|
+
imports.push(format!("{}.{}", import.module, import.name));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
Payload::ExportSection(section) => {
|
|
167
|
+
for export in section {
|
|
168
|
+
let export = export.expect("an export parses");
|
|
169
|
+
if export.name == name && export.kind == ExternalKind::Func {
|
|
170
|
+
start = Some(export.index);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
Payload::CodeSectionEntry(body) => {
|
|
175
|
+
let (mut calls, mut indirect) = (Vec::new(), false);
|
|
176
|
+
let mut reader = body.get_operators_reader().expect("a body parses");
|
|
177
|
+
while !reader.eof() {
|
|
178
|
+
match reader.read().expect("an operator parses") {
|
|
179
|
+
Operator::Call { function_index }
|
|
180
|
+
| Operator::ReturnCall { function_index } => calls.push(function_index),
|
|
181
|
+
Operator::CallIndirect { .. }
|
|
182
|
+
| Operator::ReturnCallIndirect { .. }
|
|
183
|
+
| Operator::CallRef { .. }
|
|
184
|
+
| Operator::ReturnCallRef { .. } => indirect = true,
|
|
185
|
+
_ => {}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
bodies.push((calls, indirect));
|
|
189
|
+
}
|
|
190
|
+
_ => {}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
let mut reach = Reach::default();
|
|
195
|
+
let mut seen = std::collections::HashSet::new();
|
|
196
|
+
let mut pending = vec![start.unwrap_or_else(|| panic!("the module exports {name}"))];
|
|
197
|
+
while let Some(index) = pending.pop() {
|
|
198
|
+
if !seen.insert(index) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
match imports.get(index as usize) {
|
|
202
|
+
Some(import) => reach.imports.push(import.clone()),
|
|
203
|
+
None => {
|
|
204
|
+
let (calls, indirect) = &bodies[index as usize - imports.len()];
|
|
205
|
+
reach.indirect |= indirect;
|
|
206
|
+
pending.extend(calls);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
reach.imports.sort_unstable();
|
|
211
|
+
reach
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// @behavior RT-397
|
|
215
|
+
#[test]
|
|
216
|
+
fn the_guest_binarys_allocator_calls_into_no_host_import() {
|
|
217
|
+
let path = Path::new(WASM);
|
|
218
|
+
if !guest_binary::built(path.exists(), "data/kobako.wasm") {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
let bytes = std::fs::read(path).expect("the Guest Binary must read");
|
|
222
|
+
|
|
223
|
+
assert_eq!(
|
|
224
|
+
reach_of(&bytes, "cabi_realloc"),
|
|
225
|
+
Reach::default(),
|
|
226
|
+
"cabi_realloc in data/kobako.wasm, followed through its calls, must reach no host \
|
|
227
|
+
import and no call through the function table"
|
|
228
|
+
);
|
|
229
|
+
}
|
|
115
230
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//! One wasmtime instance as the runtime's host ABI endpoint drives it, from the
|
|
2
|
+
//! invocation body's `Store` and from a host import's `Caller` alike.
|
|
3
|
+
|
|
4
|
+
use kobako_runtime::endpoint::{Calls, GuestInstance};
|
|
5
|
+
use kobako_runtime::error::Trap;
|
|
6
|
+
use wasmtime::StoreContextMut;
|
|
7
|
+
|
|
8
|
+
use crate::invocation::Invocation;
|
|
9
|
+
use crate::trap;
|
|
10
|
+
|
|
11
|
+
pub(crate) struct Guest<'a>(pub(crate) StoreContextMut<'a, Invocation>);
|
|
12
|
+
|
|
13
|
+
impl GuestInstance for Guest<'_> {
|
|
14
|
+
type Fault = wasmtime::Error;
|
|
15
|
+
|
|
16
|
+
fn calls(&mut self) -> &mut Calls<wasmtime::Error> {
|
|
17
|
+
self.0.data_mut().calls_mut()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fn memory(&mut self) -> Option<&mut [u8]> {
|
|
21
|
+
let memory = self.0.data().exports()?.memory?;
|
|
22
|
+
Some(memory.data_mut(&mut self.0))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
fn realloc(
|
|
26
|
+
&mut self,
|
|
27
|
+
old_ptr: u32,
|
|
28
|
+
old_len: u32,
|
|
29
|
+
align: u32,
|
|
30
|
+
new_len: u32,
|
|
31
|
+
) -> Option<wasmtime::Result<u32>> {
|
|
32
|
+
let realloc = self.0.data().exports()?.realloc?;
|
|
33
|
+
Some(realloc.call(&mut self.0, (old_ptr, old_len, align, new_len)))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fn downcall(&mut self, ptr: i32, len: i32) -> Option<wasmtime::Result<u32>> {
|
|
37
|
+
let downcall = self.0.data().exports()?.downcall?;
|
|
38
|
+
Some(downcall.call(&mut self.0, (ptr, len)))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fn cap_trap_of(fault: &wasmtime::Error) -> Option<Trap> {
|
|
42
|
+
trap::cap_trap_of(fault)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//! Whether a test reading the built Guest Binaries may go on. The unit tests
|
|
2
|
+
//! here and the integration tests of this crate and the SDK each compile
|
|
3
|
+
//! apart, so each reads this one file.
|
|
4
|
+
|
|
5
|
+
/// Whether a test reading the Guest Binaries at `what` may go on, `present`
|
|
6
|
+
/// saying they were built: one missing skips the test locally and fails it
|
|
7
|
+
/// under CI, which always builds them.
|
|
8
|
+
pub(crate) fn built(present: bool, what: &str) -> bool {
|
|
9
|
+
assert!(
|
|
10
|
+
present || std::env::var_os("CI").is_none(),
|
|
11
|
+
"{what} missing under CI — run `bundle exec rake wasm:build`"
|
|
12
|
+
);
|
|
13
|
+
present
|
|
14
|
+
}
|