kobako 0.29.0 → 0.30.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 +217 -10
- data/Cargo.lock +139 -141
- data/README.md +96 -574
- data/ROADMAP.md +2 -1
- data/crates/kobako-runtime/CHANGELOG.md +269 -1
- data/crates/kobako-runtime/Cargo.toml +25 -15
- data/crates/kobako-runtime/README.md +7 -3
- data/crates/kobako-runtime/src/dispatch.rs +1 -1
- data/crates/kobako-runtime/src/endpoint/buffer.rs +192 -0
- data/crates/kobako-runtime/src/endpoint/capture.rs +115 -0
- data/crates/kobako-runtime/src/endpoint/dispatch.rs +253 -0
- data/crates/kobako-runtime/src/endpoint/invoke.rs +194 -0
- data/crates/kobako-runtime/src/endpoint/memory_cap.rs +238 -0
- data/crates/kobako-runtime/src/endpoint.rs +166 -0
- data/crates/kobako-runtime/src/filesystem/bind/fid.rs +82 -0
- data/crates/kobako-runtime/src/filesystem/{directory/spelling.rs → bind/lookup.rs} +91 -49
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +249 -0
- data/crates/kobako-runtime/src/filesystem/bind.rs +2665 -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 +285 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +135 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +263 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +135 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +57 -0
- data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +227 -734
- data/crates/kobako-runtime/src/filesystem/overlay.rs +2649 -1135
- data/crates/kobako-runtime/src/filesystem/path.rs +2 -41
- data/crates/kobako-runtime/src/filesystem/pipe.rs +221 -0
- data/crates/kobako-runtime/src/filesystem/rdir.rs +101 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +85 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +22 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs.rs +1985 -0
- data/crates/kobako-runtime/src/filesystem/wrap.rs +224 -0
- data/crates/kobako-runtime/src/filesystem.rs +21 -387
- data/crates/kobako-runtime/src/hashtable.rs +44 -0
- data/crates/kobako-runtime/src/lib.rs +11 -6
- data/crates/kobako-runtime/src/locking/seqlock.rs +66 -0
- data/crates/kobako-runtime/src/locking.rs +218 -0
- data/crates/kobako-runtime/src/mount.rs +31 -104
- data/crates/kobako-runtime/src/profile.rs +137 -1
- data/crates/kobako-runtime/src/sched.rs +210 -0
- data/crates/kobako-runtime/src/security.rs +696 -0
- data/crates/kobako-runtime/src/vfs/attr.rs +162 -0
- data/crates/kobako-runtime/src/vfs/cred.rs +334 -0
- data/crates/kobako-runtime/src/vfs/dentry.rs +1412 -0
- data/crates/kobako-runtime/src/vfs/errno.rs +153 -0
- data/crates/kobako-runtime/src/vfs/file.rs +1915 -0
- data/crates/kobako-runtime/src/vfs/inode.rs +429 -0
- data/crates/kobako-runtime/src/vfs/kern_path.rs +217 -0
- data/crates/kobako-runtime/src/vfs/mount.rs +59 -0
- data/crates/kobako-runtime/src/vfs/namei.rs +5708 -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 +157 -0
- data/crates/kobako-runtime/src/vfs/super_block.rs +122 -0
- data/crates/kobako-runtime/src/vfs/utimes.rs +289 -0
- data/crates/kobako-runtime/src/vfs.rs +60 -0
- data/crates/kobako-runtime/tests/linux_baseline/calls.rs +171 -0
- data/crates/kobako-runtime/tests/linux_baseline/concurrent.rs +276 -0
- data/crates/kobako-runtime/tests/linux_baseline/kobako.rs +323 -0
- data/crates/kobako-runtime/tests/linux_baseline/linux-baseline-expected.txt +16 -0
- data/crates/kobako-runtime/tests/linux_baseline/linux.rs +449 -0
- data/crates/kobako-runtime/tests/linux_baseline/main.rs +611 -0
- data/crates/kobako-runtime/tests/linux_baseline/permissions.rs +236 -0
- data/crates/kobako-transport/CHANGELOG.md +8 -2
- data/crates/kobako-transport/Cargo.toml +3 -3
- data/crates/kobako-transport/README.md +6 -5
- data/crates/kobako-transport/src/envelope/bytes.rs +33 -25
- data/crates/kobako-transport/src/envelope/call.rs +5 -5
- data/crates/kobako-transport/src/envelope/compile_reply.rs +2 -2
- data/crates/kobako-transport/src/envelope/error_record.rs +3 -3
- data/crates/kobako-transport/src/envelope/fault.rs +2 -2
- data/crates/kobako-transport/src/envelope/outcome.rs +3 -3
- data/crates/kobako-transport/src/envelope/preamble.rs +12 -12
- data/crates/kobako-transport/src/envelope/reply.rs +2 -2
- 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 +2 -2
- data/crates/kobako-transport/src/envelope.rs +2 -2
- data/crates/kobako-wasmtime/CHANGELOG.md +154 -8
- data/crates/kobako-wasmtime/Cargo.toml +15 -14
- data/crates/kobako-wasmtime/README.md +9 -5
- data/crates/kobako-wasmtime/src/abi.rs +12 -20
- data/crates/kobako-wasmtime/src/ambient.rs +1 -2
- data/crates/kobako-wasmtime/src/cache.rs +5 -5
- data/crates/kobako-wasmtime/src/config.rs +22 -7
- data/crates/kobako-wasmtime/src/descriptors.rs +133 -100
- data/crates/kobako-wasmtime/src/driver.rs +29 -96
- data/crates/kobako-wasmtime/src/exports.rs +5 -16
- data/crates/kobako-wasmtime/src/guest.rs +38 -0
- data/crates/kobako-wasmtime/src/imports.rs +14 -8
- data/crates/kobako-wasmtime/src/instance_pre.rs +3 -3
- data/crates/kobako-wasmtime/src/invocation.rs +26 -46
- data/crates/kobako-wasmtime/src/lib.rs +1 -4
- data/crates/kobako-wasmtime/src/limiter.rs +6 -230
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +69 -46
- data/crates/kobako-wasmtime/src/preview1/differential.rs +121 -7
- data/crates/kobako-wasmtime/src/preview1/errno.rs +74 -206
- data/crates/kobako-wasmtime/src/preview1/fd.rs +1248 -500
- data/crates/kobako-wasmtime/src/preview1/memory.rs +117 -150
- data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +211 -0
- data/crates/kobako-wasmtime/src/preview1/mount_view.rs +1939 -672
- data/crates/kobako-wasmtime/src/preview1/path.rs +230 -349
- data/crates/kobako-wasmtime/src/preview1/poll.rs +148 -100
- data/crates/kobako-wasmtime/src/preview1/sock.rs +6 -23
- data/crates/kobako-wasmtime/src/preview1/testsuite-expected.txt +6 -0
- data/crates/kobako-wasmtime/src/preview1/testsuite.rs +157 -0
- data/crates/kobako-wasmtime/src/preview1.rs +464 -413
- data/crates/kobako-wasmtime/src/trap.rs +9 -9
- data/crates/kobako-wasmtime/src/wasi.rs +53 -37
- data/crates/kobako-wasmtime/tests/{guest_file.rs → integration/guest_file.rs} +232 -201
- data/crates/kobako-wasmtime/tests/integration/main.rs +29 -0
- data/crates/kobako-wasmtime/tests/{preamble_flags.rs → integration/preamble_flags.rs} +1 -1
- data/crates/kobako-wasmtime/tests/{snippet_compile.rs → integration/snippet_compile.rs} +1 -1
- data/crates/kobako-wasmtime/tests/{unanswered_call.rs → integration/unanswered_call.rs} +1 -1
- data/crates/kobako-wasmtime/tests/{unsupported_call.rs → integration/unsupported_call.rs} +1 -1
- 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/bridge.rs +1 -1
- data/ext/kobako/src/runtime/errors.rs +1 -1
- data/ext/kobako/src/runtime/escape.rs +28 -14
- data/ext/kobako/src/runtime/filesystem/grants.rs +21 -5
- data/ext/kobako/src/runtime/filesystem/ruby.rs +464 -156
- data/ext/kobako/src/runtime/filesystem.rs +109 -137
- data/ext/kobako/src/runtime/gvl.rs +43 -8
- data/ext/kobako/src/runtime/snapshot.rs +1 -1
- data/ext/kobako/src/runtime.rs +6 -1
- data/lib/kobako/catalog/extensions.rb +5 -5
- data/lib/kobako/catalog/flags.rb +2 -2
- data/lib/kobako/catalog/handles.rb +6 -6
- data/lib/kobako/catalog/mount.rb +2 -10
- data/lib/kobako/catalog/services.rb +2 -2
- data/lib/kobako/catalog/snippets.rb +7 -7
- data/lib/kobako/catalog.rb +1 -1
- data/lib/kobako/codec/decoder.rb +10 -10
- data/lib/kobako/codec/ext_types.rb +3 -5
- data/lib/kobako/codec/handle_walk.rb +4 -6
- data/lib/kobako/codec/nesting.rb +7 -7
- data/lib/kobako/codec/utils.rb +1 -1
- data/lib/kobako/codec/value_budget.rb +3 -3
- data/lib/kobako/context.rb +5 -5
- data/lib/kobako/filesystem.rb +44 -13
- data/lib/kobako/payload/arguments.rb +2 -2
- data/lib/kobako/pool.rb +4 -4
- data/lib/kobako/sandbox.rb +28 -28
- data/lib/kobako/sandbox_options.rb +2 -3
- data/lib/kobako/snippet/bytecode.rb +1 -1
- data/lib/kobako/snippet/source.rb +1 -1
- data/lib/kobako/transport/dispatcher.rb +5 -5
- data/lib/kobako/transport/exposure.rb +2 -2
- data/lib/kobako/transport/reflection.rb +7 -7
- data/lib/kobako/transport/run.rb +5 -5
- data/lib/kobako/transport/yielder.rb +1 -1
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +34 -0
- data/release-please-config.json +1 -0
- data/sig/kobako/catalog/extensions.rbs +3 -3
- data/sig/kobako/catalog/handles.rbs +3 -3
- data/sig/kobako/catalog/mount.rbs +0 -4
- data/sig/kobako/catalog/services.rbs +1 -1
- data/sig/kobako/catalog/snippets.rbs +3 -3
- data/sig/kobako/catalog.rbs +1 -1
- data/sig/kobako/codec/decoder.rbs +1 -1
- data/sig/kobako/codec/handle_walk.rbs +1 -1
- data/sig/kobako/codec/nesting.rbs +2 -2
- data/sig/kobako/codec/utils.rbs +1 -1
- data/sig/kobako/codec/value_budget.rbs +1 -1
- data/sig/kobako/codec.rbs +1 -2
- data/sig/kobako/context.rbs +1 -1
- data/sig/kobako/filesystem.rbs +19 -14
- data/sig/kobako/guest_yielder.rbs +1 -1
- data/sig/kobako/payload/arguments.rbs +1 -1
- data/sig/kobako/pool.rbs +2 -2
- data/sig/kobako/runtime.rbs +1 -1
- data/sig/kobako/sandbox.rbs +3 -5
- data/sig/kobako/sandbox_options.rbs +1 -1
- data/sig/kobako/transport/dispatcher.rbs +2 -2
- data/sig/kobako/transport/exposure.rbs +1 -1
- data/sig/kobako/transport/reflection.rbs +2 -2
- data/sig/kobako/transport/run.rbs +3 -3
- data/sig/kobako/transport.rbs +1 -1
- metadata +67 -19
- 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/temporary.rs +0 -167
- data/crates/kobako-wasmtime/src/capture.rs +0 -96
- 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 → integration/compile_posture.rs} +0 -0
- /data/crates/kobako-wasmtime/tests/{support → integration/support}/mod.rs +0 -0
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
|
|
10
10
|
use std::time::{Duration, Instant};
|
|
11
11
|
|
|
12
|
-
use wasmtime::{Store,
|
|
12
|
+
use wasmtime::{Store, StoreHookState, UpdateDeadline};
|
|
13
13
|
|
|
14
14
|
use crate::invocation::Invocation;
|
|
15
|
-
use
|
|
15
|
+
use kobako_runtime::endpoint::MemoryLimitExceeded;
|
|
16
16
|
use kobako_runtime::error::{SetupError, Trap};
|
|
17
17
|
|
|
18
18
|
/// Marker error returned from the epoch-deadline callback when the
|
|
@@ -41,7 +41,7 @@ pub(crate) const NO_TIMEOUT_EPOCH_DELTA: u64 = u64::MAX / 2;
|
|
|
41
41
|
/// firing; returning the same long extension keeps it inert as a defence
|
|
42
42
|
/// in depth.
|
|
43
43
|
pub(crate) fn epoch_deadline_callback(
|
|
44
|
-
ctx:
|
|
44
|
+
ctx: StoreHookState<'_, Invocation>,
|
|
45
45
|
) -> wasmtime::Result<UpdateDeadline> {
|
|
46
46
|
match ctx.data().deadline() {
|
|
47
47
|
Some(deadline) if Instant::now() >= deadline => Err(wasmtime::Error::new(TimeoutTrap)),
|
|
@@ -78,7 +78,7 @@ pub(crate) fn cap_trap(err: &wasmtime::Error) -> Option<Trap> {
|
|
|
78
78
|
if let Some(t) = err.downcast_ref::<TimeoutTrap>() {
|
|
79
79
|
Some(Trap::Timeout(t.to_string()))
|
|
80
80
|
} else {
|
|
81
|
-
err.downcast_ref::<
|
|
81
|
+
err.downcast_ref::<MemoryLimitExceeded>()
|
|
82
82
|
.map(|t| Trap::MemoryLimit(t.to_string()))
|
|
83
83
|
}
|
|
84
84
|
}
|
|
@@ -107,12 +107,12 @@ pub(crate) fn instantiate_err(err: wasmtime::Error) -> SetupError {
|
|
|
107
107
|
#[cfg(test)]
|
|
108
108
|
mod tests {
|
|
109
109
|
use super::{other_trap_message, to_trap, TimeoutTrap, NO_TIMEOUT_EPOCH_DELTA};
|
|
110
|
-
use
|
|
110
|
+
use kobako_runtime::endpoint::MemoryLimitExceeded;
|
|
111
111
|
use kobako_runtime::error::Trap;
|
|
112
112
|
|
|
113
113
|
// The no-timeout priming delta is added to the engine's current
|
|
114
114
|
// epoch inside wasmtime, and the process-wide ticker advances that
|
|
115
|
-
// epoch from the first `
|
|
115
|
+
// epoch from the first `load_engine` call on — so the sum must
|
|
116
116
|
// stay in range for a long-lived engine, not just a fresh one.
|
|
117
117
|
// `increment_epoch` stands in for the ticker to make the ticked
|
|
118
118
|
// state deterministic; under debug overflow checks an overflowing
|
|
@@ -120,7 +120,7 @@ mod tests {
|
|
|
120
120
|
// @behavior S-119
|
|
121
121
|
#[test]
|
|
122
122
|
fn no_timeout_delta_survives_a_ticked_engine_epoch() {
|
|
123
|
-
let engine = crate::cache::
|
|
123
|
+
let engine = crate::cache::load_engine().expect("shared engine must be constructible");
|
|
124
124
|
engine.increment_epoch();
|
|
125
125
|
let mut store = wasmtime::Store::new(engine, ());
|
|
126
126
|
store.set_epoch_deadline(NO_TIMEOUT_EPOCH_DELTA);
|
|
@@ -136,8 +136,8 @@ mod tests {
|
|
|
136
136
|
|
|
137
137
|
// @behavior OC-033
|
|
138
138
|
#[test]
|
|
139
|
-
fn
|
|
140
|
-
let trap =
|
|
139
|
+
fn to_trap_routes_memory_limit_exceeded_to_memory_limit() {
|
|
140
|
+
let trap = MemoryLimitExceeded::new(1 << 20, 1 << 19);
|
|
141
141
|
let expected = trap.to_string();
|
|
142
142
|
let err = wasmtime::Error::new(trap);
|
|
143
143
|
assert!(matches!(to_trap(err), Trap::MemoryLimit(msg) if msg == expected));
|
|
@@ -4,18 +4,29 @@
|
|
|
4
4
|
//! invocation was handed.
|
|
5
5
|
|
|
6
6
|
use wasmtime_wasi::p1::WasiP1Ctx;
|
|
7
|
-
use wasmtime_wasi::p2::pipe::{MemoryInputPipe, MemoryOutputPipe};
|
|
8
7
|
use wasmtime_wasi::WasiCtxBuilder;
|
|
9
8
|
|
|
10
9
|
use crate::ambient::{self, Clocks};
|
|
11
10
|
use crate::config::Config;
|
|
12
11
|
use crate::descriptors::Descriptors;
|
|
13
|
-
use
|
|
12
|
+
use kobako_runtime::endpoint;
|
|
14
13
|
use kobako_runtime::error::Trap;
|
|
14
|
+
use std::sync::Arc;
|
|
15
|
+
|
|
16
|
+
use kobako_runtime::filesystem::{create_pipe_files, PipeInodeInfo};
|
|
15
17
|
use kobako_runtime::grant::Grant;
|
|
16
18
|
use kobako_runtime::mount::Mount;
|
|
17
19
|
use kobako_runtime::profile::Profile;
|
|
18
|
-
use
|
|
20
|
+
use kobako_runtime::security::prepare_creds_within;
|
|
21
|
+
use kobako_runtime::vfs::Cred;
|
|
22
|
+
|
|
23
|
+
/// The Cred an invocation's Mounts open as: kobako's own rules, then each
|
|
24
|
+
/// module the Driver was built with, its Filesystems holding at most the
|
|
25
|
+
/// memory the Driver allots, as Linux's `prepare_creds` gives a task the
|
|
26
|
+
/// LSMs it booted with.
|
|
27
|
+
fn prepare_creds(config: &Config) -> Arc<Cred> {
|
|
28
|
+
prepare_creds_within(&config.security, config.memory_limit)
|
|
29
|
+
}
|
|
19
30
|
|
|
20
31
|
/// One instance's WASI context: its descriptor table, the clocks its
|
|
21
32
|
/// waits pass on, and the capture pipes stdout and stderr write into, so
|
|
@@ -24,8 +35,8 @@ pub(crate) struct Wasi {
|
|
|
24
35
|
ctx: WasiP1Ctx,
|
|
25
36
|
descriptors: Descriptors,
|
|
26
37
|
clocks: Clocks,
|
|
27
|
-
stdout:
|
|
28
|
-
stderr:
|
|
38
|
+
stdout: Arc<PipeInodeInfo>,
|
|
39
|
+
stderr: Arc<PipeInodeInfo>,
|
|
29
40
|
}
|
|
30
41
|
|
|
31
42
|
impl Wasi {
|
|
@@ -34,14 +45,15 @@ impl Wasi {
|
|
|
34
45
|
/// descriptor 3 in order.
|
|
35
46
|
pub(crate) fn for_invocation(
|
|
36
47
|
config: &Config,
|
|
37
|
-
|
|
48
|
+
stdin: Vec<u8>,
|
|
38
49
|
grants: &[Grant],
|
|
39
50
|
) -> Result<Self, Trap> {
|
|
40
51
|
Self::new(
|
|
41
|
-
|
|
52
|
+
stdin,
|
|
42
53
|
config.stdout_limit,
|
|
43
54
|
config.stderr_limit,
|
|
44
55
|
config.open_file_limit,
|
|
56
|
+
prepare_creds(config),
|
|
45
57
|
config.profile,
|
|
46
58
|
grants.iter().filter_map(to_mount).collect(),
|
|
47
59
|
)
|
|
@@ -50,58 +62,61 @@ impl Wasi {
|
|
|
50
62
|
/// A compile's context, at the strongest posture whatever the Sandbox
|
|
51
63
|
/// requested: compiling the Snippets needs no ambient authority, so
|
|
52
64
|
/// it is granted none.
|
|
53
|
-
pub(crate) fn for_compile(config: &Config,
|
|
65
|
+
pub(crate) fn for_compile(config: &Config, stdin: Vec<u8>) -> Result<Self, Trap> {
|
|
54
66
|
Self::new(
|
|
55
|
-
|
|
67
|
+
stdin,
|
|
56
68
|
config.stdout_limit,
|
|
57
69
|
config.stderr_limit,
|
|
58
70
|
config.open_file_limit,
|
|
71
|
+
prepare_creds(config),
|
|
59
72
|
Profile::Hermetic,
|
|
60
73
|
Vec::new(),
|
|
61
74
|
)
|
|
62
75
|
}
|
|
63
76
|
|
|
64
77
|
/// The ABI version probe's context. Instantiating it runs the
|
|
65
|
-
/// artifact's start section, yet reading a version needs no
|
|
66
|
-
/// authority and no output: the probe takes
|
|
67
|
-
/// pipes sized to keep nothing.
|
|
78
|
+
/// artifact's start section, yet reading a version needs no input, no
|
|
79
|
+
/// ambient authority, and no output: the probe takes an empty stdin, the
|
|
80
|
+
/// strongest posture, and pipes sized to keep nothing.
|
|
68
81
|
pub(crate) fn for_probe() -> Result<Self, Trap> {
|
|
69
|
-
Self::new(
|
|
82
|
+
Self::new(
|
|
83
|
+
Vec::new(),
|
|
84
|
+
Some(0),
|
|
85
|
+
Some(0),
|
|
86
|
+
None,
|
|
87
|
+
prepare_creds_within(&[], None),
|
|
88
|
+
Profile::Hermetic,
|
|
89
|
+
Vec::new(),
|
|
90
|
+
)
|
|
70
91
|
}
|
|
71
92
|
|
|
72
93
|
/// An uncapped output channel has no ceiling on the host: a guest
|
|
73
|
-
/// rewriting one buffer grows the pipe, not its own memory.
|
|
74
|
-
/// cap keeps the Preamble's `u32` length prefix from wrapping.
|
|
94
|
+
/// rewriting one buffer grows the pipe, not its own memory.
|
|
75
95
|
fn new(
|
|
76
|
-
|
|
96
|
+
stdin: Vec<u8>,
|
|
77
97
|
stdout_limit: Option<usize>,
|
|
78
98
|
stderr_limit: Option<usize>,
|
|
79
99
|
open_file_limit: Option<usize>,
|
|
100
|
+
opener: Arc<Cred>,
|
|
80
101
|
profile: Profile,
|
|
81
102
|
mounts: Vec<Mount>,
|
|
82
103
|
) -> Result<Self, Trap> {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
guest_mem::checked_payload_len(preamble.len())
|
|
86
|
-
.map_err(|msg| Trap::Other(msg.to_string()))?;
|
|
87
|
-
|
|
88
|
-
let mut stdin_content: Vec<u8> = Vec::with_capacity(FRAME_LEN_SIZE + preamble.len());
|
|
89
|
-
stdin_content.extend_from_slice(&(preamble.len() as u32).to_be_bytes());
|
|
90
|
-
stdin_content.extend_from_slice(preamble);
|
|
91
|
-
|
|
92
|
-
let stdout = MemoryOutputPipe::new(capture::pipe_capacity(stdout_limit));
|
|
93
|
-
let stderr = MemoryOutputPipe::new(capture::pipe_capacity(stderr_limit));
|
|
104
|
+
let stdout = PipeInodeInfo::new(endpoint::pipe_capacity(stdout_limit));
|
|
105
|
+
let stderr = PipeInodeInfo::new(endpoint::pipe_capacity(stderr_limit));
|
|
94
106
|
|
|
95
107
|
// stdio lives in kobako's descriptor table, which answers every
|
|
96
108
|
// call that reads a descriptor (`crate::preview1`); the builder
|
|
97
109
|
// keeps only what the remaining imports read.
|
|
98
110
|
let descriptors = Descriptors::new(
|
|
99
|
-
|
|
100
|
-
stdout.
|
|
101
|
-
stderr.
|
|
111
|
+
create_pipe_files(&PipeInodeInfo::from_bytes(stdin), &opener).0,
|
|
112
|
+
create_pipe_files(&stdout, &opener).1,
|
|
113
|
+
create_pipe_files(&stderr, &opener).1,
|
|
102
114
|
mounts,
|
|
103
115
|
open_file_limit,
|
|
104
|
-
|
|
116
|
+
opener,
|
|
117
|
+
profile,
|
|
118
|
+
)
|
|
119
|
+
.map_err(|err| Trap::Other(format!("a Mount's root did not open: {err:?}")))?;
|
|
105
120
|
|
|
106
121
|
let mut builder = WasiCtxBuilder::new();
|
|
107
122
|
// The profile decides the ambient authority granted: the
|
|
@@ -151,11 +166,11 @@ impl Wasi {
|
|
|
151
166
|
}
|
|
152
167
|
|
|
153
168
|
pub(crate) fn stdout_bytes(&self) -> Vec<u8> {
|
|
154
|
-
self.stdout.contents()
|
|
169
|
+
self.stdout.contents()
|
|
155
170
|
}
|
|
156
171
|
|
|
157
172
|
pub(crate) fn stderr_bytes(&self) -> Vec<u8> {
|
|
158
|
-
self.stderr.contents()
|
|
173
|
+
self.stderr.contents()
|
|
159
174
|
}
|
|
160
175
|
}
|
|
161
176
|
|
|
@@ -164,7 +179,7 @@ impl Wasi {
|
|
|
164
179
|
/// frontend from handing one over.
|
|
165
180
|
fn to_mount(grant: &Grant) -> Option<Mount> {
|
|
166
181
|
match grant {
|
|
167
|
-
Grant::Mount(mount) => Some(mount.
|
|
182
|
+
Grant::Mount(mount) => Some(mount.clone()),
|
|
168
183
|
_ => None,
|
|
169
184
|
}
|
|
170
185
|
}
|
|
@@ -178,7 +193,7 @@ mod tests {
|
|
|
178
193
|
use wasmtime::{AsContextMut, Module, Store};
|
|
179
194
|
|
|
180
195
|
use super::*;
|
|
181
|
-
use crate::cache::
|
|
196
|
+
use crate::cache::load_engine;
|
|
182
197
|
use crate::imports;
|
|
183
198
|
use crate::invocation::Invocation;
|
|
184
199
|
|
|
@@ -222,7 +237,7 @@ mod tests {
|
|
|
222
237
|
/// Instantiate the probe over an invocation's WASI context built at
|
|
223
238
|
/// `profile` and return a reader for its exports.
|
|
224
239
|
fn probe(profile: Profile) -> impl FnMut(&str) -> i64 {
|
|
225
|
-
let engine =
|
|
240
|
+
let engine = load_engine().expect("shared engine must be constructible");
|
|
226
241
|
let config = Config {
|
|
227
242
|
timeout: None,
|
|
228
243
|
setup_timeout: None,
|
|
@@ -231,8 +246,9 @@ mod tests {
|
|
|
231
246
|
stderr_limit: None,
|
|
232
247
|
open_file_limit: None,
|
|
233
248
|
profile,
|
|
249
|
+
security: Vec::new(),
|
|
234
250
|
};
|
|
235
|
-
let wasi = Wasi::for_invocation(&config,
|
|
251
|
+
let wasi = Wasi::for_invocation(&config, Vec::new(), &[]).expect("WASI context must build");
|
|
236
252
|
let mut store = Store::new(engine, Invocation::new(None, wasi));
|
|
237
253
|
store.set_epoch_deadline(crate::trap::NO_TIMEOUT_EPOCH_DELTA);
|
|
238
254
|
|