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
data/ext/kobako/src/runtime.rs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
//!
|
|
1
|
+
//! The Ruby handle of the contract `Runtime` a Sandbox runs each
|
|
2
|
+
//! invocation on.
|
|
2
3
|
//!
|
|
3
4
|
//! The Ruby-visible classes are
|
|
4
5
|
//!
|
|
5
|
-
//! Kobako::Runtime —
|
|
6
|
+
//! Kobako::Runtime — holds one contract `Runtime`
|
|
6
7
|
//! Kobako::Snapshot — one invocation's completion + captures + usage
|
|
7
8
|
//!
|
|
8
9
|
//! `Kobako::Runtime` is constructed via `Kobako::Runtime.from_path(path,
|
|
@@ -11,24 +12,18 @@
|
|
|
11
12
|
//! argument, instantiates a fresh instance, and returns a `Snapshot` — the
|
|
12
13
|
//! whole per-invocation result — so the Runtime holds no per-invocation
|
|
13
14
|
//! state and one Runtime is safe to drive concurrently. The run mechanics —
|
|
14
|
-
//! engine/module caches, caps, trap classification — live in the
|
|
15
|
-
//! `
|
|
15
|
+
//! engine/module caches, caps, trap classification — live in the Wasm
|
|
16
|
+
//! Driver `from_path` builds, behind the `kobako_runtime` contract; no wasm
|
|
16
17
|
//! engine type reaches this crate or the Host App.
|
|
17
18
|
//!
|
|
18
19
|
//! Each module holds one responsibility and opens with its own doc.
|
|
19
20
|
|
|
20
21
|
mod bridge;
|
|
21
|
-
mod errors;
|
|
22
|
-
mod escape;
|
|
23
|
-
mod filesystem;
|
|
24
|
-
mod gvl;
|
|
25
|
-
mod pinned_value;
|
|
26
22
|
mod snapshot;
|
|
27
23
|
|
|
28
24
|
use magnus::{
|
|
29
|
-
function, method, prelude::*,
|
|
30
|
-
|
|
31
|
-
Value,
|
|
25
|
+
function, method, prelude::*, typed_data::DataTypeFunctions, value::Opaque,
|
|
26
|
+
Error as MagnusError, RArray, RHash, RModule, RString, Ruby, Symbol, TypedData, Value,
|
|
32
27
|
};
|
|
33
28
|
|
|
34
29
|
use std::path::Path;
|
|
@@ -36,23 +31,18 @@ use std::sync::Arc;
|
|
|
36
31
|
use std::time::Duration;
|
|
37
32
|
|
|
38
33
|
use kobako_runtime::dispatch::DispatchHandler;
|
|
34
|
+
use kobako_runtime::limits::{Cap, Limits};
|
|
35
|
+
use kobako_runtime::net::Backends;
|
|
39
36
|
use kobako_runtime::profile::Profile;
|
|
40
37
|
use kobako_runtime::runtime::{Entry, Runtime as ContractRuntime};
|
|
41
38
|
use kobako_transport::envelope::{Bindings, Flag, Preamble, Snippet, Snippets};
|
|
42
39
|
use kobako_wasmtime::{Config, Driver};
|
|
43
40
|
|
|
41
|
+
use crate::{errors, filesystem, gvl, name_of, network, symbol_name_of, to_bytes, value_by_name};
|
|
44
42
|
use snapshot::Snapshot;
|
|
45
43
|
|
|
46
|
-
/// The one place the boundary borrows an RString's bytes: the borrow does
|
|
47
|
-
/// not outlive this call, so no Ruby allocation can move the RString
|
|
48
|
-
/// between the borrow and the copy.
|
|
49
|
-
fn rstring_to_vec(s: RString) -> Vec<u8> {
|
|
50
|
-
// SAFETY: see item doc.
|
|
51
|
-
unsafe { s.as_slice() }.to_vec()
|
|
52
|
-
}
|
|
53
|
-
|
|
54
44
|
/// `kind` arrives as a Symbol so the registry never names the wire's
|
|
55
|
-
/// discriminant; an
|
|
45
|
+
/// discriminant; an unknown kind raises rather than defaulting.
|
|
56
46
|
fn to_snippets(ruby: &Ruby, entries: RArray) -> Result<Snippets, MagnusError> {
|
|
57
47
|
let mut snippets = Snippets {
|
|
58
48
|
entries: Vec::with_capacity(entries.len()),
|
|
@@ -66,7 +56,7 @@ fn to_snippets(ruby: &Ruby, entries: RArray) -> Result<Snippets, MagnusError> {
|
|
|
66
56
|
body: entry.entry(2)?,
|
|
67
57
|
},
|
|
68
58
|
"bytecode" => Snippet::Bytecode {
|
|
69
|
-
body:
|
|
59
|
+
body: to_bytes(entry.entry(2)?),
|
|
70
60
|
},
|
|
71
61
|
other => {
|
|
72
62
|
return Err(MagnusError::new(
|
|
@@ -106,23 +96,20 @@ fn to_preamble(ruby: &Ruby, parts: RArray) -> Result<Preamble, MagnusError> {
|
|
|
106
96
|
// Ruby init
|
|
107
97
|
// ---------------------------------------------------------------------------
|
|
108
98
|
|
|
109
|
-
pub fn
|
|
110
|
-
// Error hierarchy lives in `lib/kobako/errors.rb`; the ext raises
|
|
111
|
-
// directly into those classes through the constructors and mappers
|
|
112
|
-
// in `runtime/errors.rs` — no intermediate hierarchy is registered.
|
|
113
|
-
|
|
99
|
+
pub(crate) fn register(ruby: &Ruby, kobako: RModule) -> Result<(), MagnusError> {
|
|
114
100
|
let runtime = kobako.define_class("Runtime", ruby.class_object())?;
|
|
115
101
|
runtime.define_singleton_method("from_path", function!(Runtime::from_path, 2))?;
|
|
102
|
+
runtime.define_singleton_method("default_options", function!(Runtime::default_options, 0))?;
|
|
103
|
+
runtime.define_singleton_method("normalize_caps", function!(normalize_caps, 1))?;
|
|
104
|
+
runtime.define_singleton_method("value_budget_of", function!(value_budget_of, 1))?;
|
|
116
105
|
runtime.define_method("eval", method!(Runtime::eval, 3))?;
|
|
117
106
|
runtime.define_method("run", method!(Runtime::run, 4))?;
|
|
118
107
|
runtime.define_method("profile", method!(Runtime::profile, 0))?;
|
|
119
108
|
runtime.define_method("compile", method!(Runtime::compile, 1))?;
|
|
120
|
-
runtime.define_singleton_method("validate_mount!", function!(filesystem::validate_mount, 3))?;
|
|
121
109
|
// The guest re-enters for a block yield through a frame-scoped
|
|
122
110
|
// `Kobako::GuestYielder` the dispatcher hands the Proc, not a method on
|
|
123
111
|
// Runtime.
|
|
124
112
|
bridge::register(kobako)?;
|
|
125
|
-
filesystem::register(ruby, kobako)?;
|
|
126
113
|
|
|
127
114
|
// Snapshot — the per-invocation result object each entry point returns.
|
|
128
115
|
snapshot::register(ruby, kobako)?;
|
|
@@ -137,16 +124,133 @@ pub fn init(ruby: &Ruby, kobako: RModule) -> Result<(), MagnusError> {
|
|
|
137
124
|
Ok(())
|
|
138
125
|
}
|
|
139
126
|
|
|
127
|
+
/// Each cap in `caps`, read as `to_limits` reads it and keyed as
|
|
128
|
+
/// `Kobako::SandboxOptions` names it.
|
|
129
|
+
fn normalize_caps(caps: RHash) -> Result<RHash, MagnusError> {
|
|
130
|
+
let ruby = Ruby::get().expect("Ruby thread");
|
|
131
|
+
caps_of(&ruby, &to_limits(&ruby, caps)?)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/// The most values a guest payload may make the host build under
|
|
135
|
+
/// `memory_limit`, as the runtime's caps count them.
|
|
136
|
+
fn value_budget_of(memory_limit: Option<usize>) -> Option<usize> {
|
|
137
|
+
let mut limits = Limits::default();
|
|
138
|
+
limits.memory_limit = memory_limit;
|
|
139
|
+
limits.value_budget()
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/// The caps in `caps`, keyed as `Kobako::SandboxOptions` names them, each read
|
|
143
|
+
/// as its kind: a deadline as seconds, a positive finite Numeric, and every
|
|
144
|
+
/// other cap as a positive Integer, `nil` asking for none. One outside its
|
|
145
|
+
/// kind is refused as an argument error, and a zero by the runtime's own
|
|
146
|
+
/// check, which the Rust SDK asks too.
|
|
147
|
+
fn to_limits(ruby: &Ruby, caps: RHash) -> Result<Limits, MagnusError> {
|
|
148
|
+
let mut limits = Limits::default();
|
|
149
|
+
for (name, cap) in limits.caps_mut() {
|
|
150
|
+
let value = caps.fetch(ruby.to_symbol(name))?;
|
|
151
|
+
match cap {
|
|
152
|
+
Cap::Deadline(deadline) => *deadline = to_deadline(ruby, name, value)?,
|
|
153
|
+
Cap::Count(count) => *count = to_count(ruby, name, value)?,
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
limits
|
|
157
|
+
.check()
|
|
158
|
+
.map_err(|zero| MagnusError::new(ruby.exception_arg_error(), zero.to_string()))?;
|
|
159
|
+
Ok(limits)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/// Each cap `limits` holds, keyed as `Kobako::SandboxOptions` names it, a
|
|
163
|
+
/// deadline in seconds.
|
|
164
|
+
fn caps_of(ruby: &Ruby, limits: &Limits) -> Result<RHash, MagnusError> {
|
|
165
|
+
let caps = ruby.hash_new();
|
|
166
|
+
let mut limits = *limits;
|
|
167
|
+
for (name, cap) in limits.caps_mut() {
|
|
168
|
+
let key = ruby.to_symbol(name);
|
|
169
|
+
match cap {
|
|
170
|
+
Cap::Deadline(deadline) => caps.aset(key, deadline.map(|d| d.as_secs_f64()))?,
|
|
171
|
+
Cap::Count(count) => caps.aset(key, *count)?,
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
Ok(caps)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/// The deadline `value` names in seconds for `name`, none for `nil`. A
|
|
178
|
+
/// deadline that never arrives, is past what a `Duration` counts, or is not a
|
|
179
|
+
/// number, is refused: the way to ask for none is `nil`.
|
|
180
|
+
fn to_deadline(ruby: &Ruby, name: &str, value: Value) -> Result<Option<Duration>, MagnusError> {
|
|
181
|
+
if value.is_nil() {
|
|
182
|
+
return Ok(None);
|
|
183
|
+
}
|
|
184
|
+
if !value.is_kind_of(ruby.class_numeric()) {
|
|
185
|
+
return Err(MagnusError::new(
|
|
186
|
+
ruby.exception_type_error(),
|
|
187
|
+
format!(
|
|
188
|
+
"{name} must be Numeric or nil, got {}",
|
|
189
|
+
value.class().inspect()
|
|
190
|
+
),
|
|
191
|
+
));
|
|
192
|
+
}
|
|
193
|
+
let seconds: f64 = value.funcall("to_f", ())?;
|
|
194
|
+
let refusal = if seconds > 0.0 && seconds.is_finite() {
|
|
195
|
+
ruby.exception_range_error()
|
|
196
|
+
} else {
|
|
197
|
+
ruby.exception_arg_error()
|
|
198
|
+
};
|
|
199
|
+
match Duration::try_from_secs_f64(seconds) {
|
|
200
|
+
Ok(deadline) if seconds.is_finite() => Ok(Some(deadline)),
|
|
201
|
+
_ => Err(MagnusError::new(
|
|
202
|
+
refusal,
|
|
203
|
+
format!(
|
|
204
|
+
"{name} must be > 0 and at most {} seconds (got {})",
|
|
205
|
+
Duration::MAX.as_secs(),
|
|
206
|
+
value.inspect()
|
|
207
|
+
),
|
|
208
|
+
)),
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/// The count `value` names for the cap `name`, none for `nil`; anything but
|
|
213
|
+
/// an Integer a `usize` holds is refused.
|
|
214
|
+
fn to_count(ruby: &Ruby, name: &str, value: Value) -> Result<Option<usize>, MagnusError> {
|
|
215
|
+
if value.is_nil() {
|
|
216
|
+
return Ok(None);
|
|
217
|
+
}
|
|
218
|
+
let Some(integer) = magnus::Integer::from_value(value) else {
|
|
219
|
+
return Err(MagnusError::new(
|
|
220
|
+
ruby.exception_type_error(),
|
|
221
|
+
format!(
|
|
222
|
+
"{name} must be an Integer or nil, got {}",
|
|
223
|
+
value.class().inspect()
|
|
224
|
+
),
|
|
225
|
+
));
|
|
226
|
+
};
|
|
227
|
+
let refusal = if value.funcall::<_, _, bool>("negative?", ())? {
|
|
228
|
+
ruby.exception_arg_error()
|
|
229
|
+
} else {
|
|
230
|
+
ruby.exception_range_error()
|
|
231
|
+
};
|
|
232
|
+
match integer.to_usize().ok() {
|
|
233
|
+
Some(count) => Ok(Some(count)),
|
|
234
|
+
None => Err(MagnusError::new(
|
|
235
|
+
refusal,
|
|
236
|
+
format!(
|
|
237
|
+
"{name} must be a positive Integer or nil, got {}",
|
|
238
|
+
value.inspect()
|
|
239
|
+
),
|
|
240
|
+
)),
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
140
244
|
#[derive(TypedData)]
|
|
141
245
|
#[magnus(class = "Kobako::Runtime", free_immediately, size)]
|
|
142
246
|
struct Runtime {
|
|
143
|
-
// The
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
|
|
247
|
+
// The runtime every invocation runs on, held behind the contract so the
|
|
248
|
+
// driver is named only where it is built. The Runtime holds no
|
|
249
|
+
// per-invocation state — each `#eval` / `#run` takes its dispatch
|
|
250
|
+
// handler as an argument and returns its whole result as a `Snapshot`
|
|
251
|
+
// — so the contract's `Send + Sync` carries the type with no interior
|
|
252
|
+
// mutability to guard.
|
|
253
|
+
runtime: Box<dyn ContractRuntime + Send + Sync>,
|
|
150
254
|
// Whether each invocation releases Ruby's GVL for its guest span
|
|
151
255
|
// (`gvl: :release`) or holds it throughout (`gvl: :hold`). Fixed at
|
|
152
256
|
// construction; a `bool` carries no interior mutability, so the type
|
|
@@ -157,99 +261,69 @@ struct Runtime {
|
|
|
157
261
|
impl DataTypeFunctions for Runtime {}
|
|
158
262
|
|
|
159
263
|
impl Runtime {
|
|
264
|
+
/// Each option `from_path` takes, keyed as `Kobako::SandboxOptions` names
|
|
265
|
+
/// it, at the runtime's default, so every frontend applies one set. A
|
|
266
|
+
/// run holds the GVL unless the Host App asks to release it.
|
|
267
|
+
fn default_options() -> Result<RHash, MagnusError> {
|
|
268
|
+
let ruby = Ruby::get().expect("Ruby thread");
|
|
269
|
+
let options = caps_of(&ruby, &Limits::default())?;
|
|
270
|
+
options.aset(
|
|
271
|
+
ruby.to_symbol("profile"),
|
|
272
|
+
to_profile_name(&ruby, Profile::default()),
|
|
273
|
+
)?;
|
|
274
|
+
options.aset(ruby.to_symbol("gvl"), ruby.to_symbol("hold"))?;
|
|
275
|
+
options.aset(ruby.to_symbol("network"), ruby.qnil())?;
|
|
276
|
+
Ok(options)
|
|
277
|
+
}
|
|
278
|
+
|
|
160
279
|
/// The only Ruby-facing constructor, so Engine and Module are never
|
|
161
|
-
/// visible to Ruby. Every option is a required keyword
|
|
162
|
-
///
|
|
280
|
+
/// visible to Ruby. Every option is a required keyword, as
|
|
281
|
+
/// `default_options` answers each.
|
|
163
282
|
fn from_path(path: String, options: RHash) -> Result<Self, MagnusError> {
|
|
164
283
|
let ruby = Ruby::get().expect("Ruby thread");
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
);
|
|
175
|
-
let options = get_kwargs::<_, Options, (), ()>(
|
|
176
|
-
options,
|
|
177
|
-
&[
|
|
178
|
-
"timeout",
|
|
179
|
-
"setup_timeout",
|
|
180
|
-
"memory_limit",
|
|
181
|
-
"stdout_limit",
|
|
182
|
-
"stderr_limit",
|
|
183
|
-
"open_file_limit",
|
|
184
|
-
"profile",
|
|
185
|
-
"gvl",
|
|
186
|
-
],
|
|
187
|
-
&[],
|
|
188
|
-
)?;
|
|
189
|
-
let (
|
|
190
|
-
timeout_seconds,
|
|
191
|
-
setup_timeout_seconds,
|
|
192
|
-
memory_limit,
|
|
193
|
-
stdout_limit,
|
|
194
|
-
stderr_limit,
|
|
195
|
-
open_file_limit,
|
|
196
|
-
profile,
|
|
197
|
-
gvl,
|
|
198
|
-
) = options.required;
|
|
199
|
-
// An invalid cap argument is a Host App programming error and
|
|
200
|
-
// raises `ArgumentError`, outside the construction-failure
|
|
201
|
-
// `SetupError` branch. `SandboxOptions` is the primary guard (it
|
|
202
|
-
// never lets a bad timeout reach here); this is defence-in-depth
|
|
203
|
-
// for direct `from_path` calls.
|
|
204
|
-
let to_duration = |seconds: Option<f64>, name: &str| match seconds {
|
|
205
|
-
None => Ok(None),
|
|
206
|
-
Some(secs) if secs.is_finite() && secs > 0.0 => Ok(Some(Duration::from_secs_f64(secs))),
|
|
207
|
-
Some(secs) => Err(MagnusError::new(
|
|
284
|
+
let limits = to_limits(&ruby, options)?;
|
|
285
|
+
let profile: Value = options.fetch(ruby.to_symbol("profile"))?;
|
|
286
|
+
let gvl: Value = options.fetch(ruby.to_symbol("gvl"))?;
|
|
287
|
+
// A value kobako does not name a profile has no profile to stand
|
|
288
|
+
// for, so it is refused rather than read as a weaker one.
|
|
289
|
+
let Some(profile) =
|
|
290
|
+
symbol_name_of(profile)?.and_then(|name| value_by_name(&PROFILE_NAMES, &name))
|
|
291
|
+
else {
|
|
292
|
+
return Err(MagnusError::new(
|
|
208
293
|
ruby.exception_arg_error(),
|
|
209
|
-
format!(
|
|
210
|
-
|
|
294
|
+
format!(
|
|
295
|
+
"profile must be :permissive or :hermetic, got {}",
|
|
296
|
+
profile.inspect()
|
|
297
|
+
),
|
|
298
|
+
));
|
|
211
299
|
};
|
|
212
|
-
|
|
213
|
-
let
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
let profile = match profile.name()?.as_ref() {
|
|
218
|
-
"hermetic" => Profile::Hermetic,
|
|
219
|
-
"permissive" => Profile::Permissive,
|
|
220
|
-
other => {
|
|
300
|
+
// A mode kobako does not name is refused as a profile is.
|
|
301
|
+
let release_gvl = match symbol_name_of(gvl)?.as_deref() {
|
|
302
|
+
Some("hold") => false,
|
|
303
|
+
Some("release") => true,
|
|
304
|
+
_ => {
|
|
221
305
|
return Err(MagnusError::new(
|
|
222
306
|
ruby.exception_arg_error(),
|
|
223
|
-
format!("
|
|
307
|
+
format!("gvl must be :hold or :release, got {}", gvl.inspect()),
|
|
224
308
|
));
|
|
225
309
|
}
|
|
226
310
|
};
|
|
227
|
-
|
|
228
|
-
//
|
|
229
|
-
|
|
230
|
-
let
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
other => {
|
|
234
|
-
return Err(MagnusError::new(
|
|
235
|
-
ruby.exception_arg_error(),
|
|
236
|
-
format!("gvl must be :hold or :release, got :{other}"),
|
|
237
|
-
));
|
|
238
|
-
}
|
|
311
|
+
|
|
312
|
+
// `nil` is the host's own network; anything else must be a Mock.
|
|
313
|
+
let mock: Value = options.fetch(ruby.to_symbol("network"))?;
|
|
314
|
+
let backends = match mock.is_nil() {
|
|
315
|
+
true => Backends::default(),
|
|
316
|
+
false => <&network::MockNet>::try_convert(mock)?.backends(),
|
|
239
317
|
};
|
|
240
318
|
|
|
241
319
|
let mut config = Config::default();
|
|
242
|
-
config.
|
|
243
|
-
config.setup_timeout = setup_timeout;
|
|
244
|
-
config.memory_limit = memory_limit;
|
|
245
|
-
config.stdout_limit = stdout_limit;
|
|
246
|
-
config.stderr_limit = stderr_limit;
|
|
247
|
-
config.open_file_limit = open_file_limit;
|
|
320
|
+
config.limits = limits;
|
|
248
321
|
config.profile = profile;
|
|
249
|
-
|
|
250
|
-
|
|
322
|
+
config.network = backends;
|
|
323
|
+
let driver = Driver::from_file(Path::new(&path), config)
|
|
324
|
+
.map_err(|e| errors::from_setup(&ruby, e))?;
|
|
251
325
|
Ok(Self {
|
|
252
|
-
driver,
|
|
326
|
+
runtime: Box::new(driver),
|
|
253
327
|
release_gvl,
|
|
254
328
|
})
|
|
255
329
|
}
|
|
@@ -259,11 +333,12 @@ impl Runtime {
|
|
|
259
333
|
// argument and returns a `Snapshot` for any completed invocation —
|
|
260
334
|
// success or trap alike. Only a could-not-start fault (a missing export
|
|
261
335
|
// or a fault before the export call) raises directly, as the class
|
|
262
|
-
// `errors::
|
|
336
|
+
// `errors::from_invoke` gives its cause, since it yields no `Snapshot`.
|
|
263
337
|
//
|
|
264
|
-
// `setup` is the invocation's `[paths, snippets, flags, mounts
|
|
265
|
-
// Preamble's three parts, then the Mounts as
|
|
266
|
-
// `filesystem::to_grants` reads them
|
|
338
|
+
// `setup` is the invocation's `[paths, snippets, flags, mounts,
|
|
339
|
+
// networks]`: the Preamble's three parts, then the Mounts as
|
|
340
|
+
// `filesystem::to_grants` reads them and the network entries as
|
|
341
|
+
// `network::to_grants` reads them.
|
|
267
342
|
// -----------------------------------------------------------------
|
|
268
343
|
|
|
269
344
|
fn eval(
|
|
@@ -272,7 +347,7 @@ impl Runtime {
|
|
|
272
347
|
setup: RArray,
|
|
273
348
|
source: RString,
|
|
274
349
|
) -> Result<Snapshot, MagnusError> {
|
|
275
|
-
let source =
|
|
350
|
+
let source = to_bytes(source);
|
|
276
351
|
self.invoke(dispatch, setup, Entry::Eval { source: &source })
|
|
277
352
|
}
|
|
278
353
|
|
|
@@ -288,7 +363,7 @@ impl Runtime {
|
|
|
288
363
|
setup,
|
|
289
364
|
Entry::Run {
|
|
290
365
|
entrypoint: &entrypoint,
|
|
291
|
-
payload:
|
|
366
|
+
payload: to_bytes(payload),
|
|
292
367
|
},
|
|
293
368
|
)
|
|
294
369
|
}
|
|
@@ -308,29 +383,30 @@ impl Runtime {
|
|
|
308
383
|
};
|
|
309
384
|
let handler = build_handler(dispatch);
|
|
310
385
|
let preamble = to_preamble(&ruby, setup)?;
|
|
311
|
-
let (grants,
|
|
386
|
+
let (mut grants, mut pins) = filesystem::to_grants(&ruby, setup.entry(3)?)?;
|
|
387
|
+
let (networks, network_pins) = network::to_grants(&ruby, setup.entry(4)?)?;
|
|
388
|
+
grants.extend(networks);
|
|
389
|
+
pins.extend(network_pins);
|
|
312
390
|
// Release the GVL around the guest span iff this Sandbox asks for it;
|
|
313
|
-
// the closure touches no Ruby VALUE (the
|
|
391
|
+
// the closure touches no Ruby VALUE (the runtime is magnus-free, and a
|
|
314
392
|
// guest→host dispatch, or a mount's block, re-acquires the GVL).
|
|
315
|
-
|
|
316
|
-
self.
|
|
317
|
-
})
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
.map(|snapshot| Snapshot::new(snapshot, verb))
|
|
321
|
-
.map_err(|e| errors::to_magnus(&ruby, e))
|
|
393
|
+
gvl::run(&ruby, self.release_gvl, || {
|
|
394
|
+
self.runtime.invoke(entry, &preamble, handler, &grants)
|
|
395
|
+
})?
|
|
396
|
+
.map(|snapshot| Snapshot::new(snapshot, verb))
|
|
397
|
+
.map_err(|e| errors::from_invoke(&ruby, e))
|
|
322
398
|
}
|
|
323
399
|
|
|
324
400
|
/// The bytecode of the source snippets, one binary String each in
|
|
325
401
|
/// order, or `nil` when the guest compiled nothing; no failure raises,
|
|
326
402
|
/// since the Sandbox keeps the source either way. Takes the Preamble an
|
|
327
|
-
/// invocation sends, `paths` included, so the
|
|
403
|
+
/// invocation sends, `paths` included, so the runtime can tell whether
|
|
328
404
|
/// the bytecode still fits it; no dispatch handler is bound, since
|
|
329
405
|
/// compiling runs no script.
|
|
330
406
|
fn compile(&self, preamble: RArray) -> Result<Option<RArray>, MagnusError> {
|
|
331
407
|
let ruby = Ruby::get().expect("Ruby thread");
|
|
332
408
|
let preamble = to_preamble(&ruby, preamble)?;
|
|
333
|
-
let bytecodes = gvl::
|
|
409
|
+
let bytecodes = gvl::run(&ruby, self.release_gvl, || self.runtime.compile(&preamble))?;
|
|
334
410
|
Ok(bytecodes.map(|bytecodes| {
|
|
335
411
|
ruby.ary_from_iter(
|
|
336
412
|
bytecodes
|
|
@@ -340,19 +416,26 @@ impl Runtime {
|
|
|
340
416
|
}))
|
|
341
417
|
}
|
|
342
418
|
|
|
343
|
-
/// The
|
|
344
|
-
/// posture its `profile:` option requested.
|
|
419
|
+
/// The isolation profile the runtime declares it built.
|
|
345
420
|
fn profile(&self) -> Symbol {
|
|
346
421
|
let ruby = Ruby::get().expect("Ruby thread");
|
|
347
|
-
|
|
348
|
-
Profile::Hermetic => ruby.to_symbol("hermetic"),
|
|
349
|
-
Profile::Permissive => ruby.to_symbol("permissive"),
|
|
350
|
-
}
|
|
422
|
+
to_profile_name(&ruby, self.runtime.profile())
|
|
351
423
|
}
|
|
352
424
|
}
|
|
353
425
|
|
|
426
|
+
/// Each profile beside the name the `profile:` option takes it by.
|
|
427
|
+
const PROFILE_NAMES: [(Profile, &str); 2] = [
|
|
428
|
+
(Profile::Hermetic, "hermetic"),
|
|
429
|
+
(Profile::Permissive, "permissive"),
|
|
430
|
+
];
|
|
431
|
+
|
|
432
|
+
/// `profile` as the Symbol the `profile:` option names it by.
|
|
433
|
+
fn to_profile_name(ruby: &Ruby, profile: Profile) -> Symbol {
|
|
434
|
+
ruby.to_symbol(name_of(&PROFILE_NAMES, &profile).expect("every profile has a name"))
|
|
435
|
+
}
|
|
436
|
+
|
|
354
437
|
/// The Proc stays GC-rooted for the synchronous `#eval` / `#run` call as a
|
|
355
|
-
/// live method argument on the Ruby stack, so the
|
|
438
|
+
/// live method argument on the Ruby stack, so the runtime only borrows it
|
|
356
439
|
/// (the safety contract on `kobako_runtime::runtime::Runtime`).
|
|
357
440
|
fn build_handler(dispatch: Value) -> Option<Arc<dyn DispatchHandler>> {
|
|
358
441
|
if dispatch.is_nil() {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//! The Wire's rules a Ruby frontend asks before it writes a name the guest
|
|
2
|
+
//! interns or issues a Capability Handle id, so both frontends hold to the
|
|
3
|
+
//! one rule the Envelope tier keeps.
|
|
4
|
+
|
|
5
|
+
use magnus::{function, prelude::*, Error as MagnusError, RModule, RString};
|
|
6
|
+
|
|
7
|
+
use kobako_transport::envelope::name::{collides, is_constant_name, is_constant_path, is_reserved};
|
|
8
|
+
use kobako_transport::envelope::MAX_HANDLE_ID;
|
|
9
|
+
|
|
10
|
+
pub(crate) fn register(kobako: RModule) -> Result<(), MagnusError> {
|
|
11
|
+
kobako.define_singleton_method("max_handle_id", function!(|| MAX_HANDLE_ID, 0))?;
|
|
12
|
+
kobako.define_singleton_method(
|
|
13
|
+
"constant_name?",
|
|
14
|
+
function!(|name: RString| holds(name, is_constant_name), 1),
|
|
15
|
+
)?;
|
|
16
|
+
kobako.define_singleton_method(
|
|
17
|
+
"constant_path?",
|
|
18
|
+
function!(|path: RString| holds(path, is_constant_path), 1),
|
|
19
|
+
)?;
|
|
20
|
+
kobako.define_singleton_method(
|
|
21
|
+
"reserved_path?",
|
|
22
|
+
function!(|path: RString| holds(path, is_reserved), 1),
|
|
23
|
+
)?;
|
|
24
|
+
kobako.define_singleton_method("paths_collide?", function!(paths_collide, 2))?;
|
|
25
|
+
Ok(())
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// Whether the paths `path` and `bound` spell cannot both be bound; bytes
|
|
29
|
+
/// that spell no text are no name at all, so they collide with nothing.
|
|
30
|
+
fn paths_collide(path: RString, bound: RString) -> bool {
|
|
31
|
+
let (path, bound) = (crate::to_bytes(path), crate::to_bytes(bound));
|
|
32
|
+
match (std::str::from_utf8(&path), std::str::from_utf8(&bound)) {
|
|
33
|
+
(Ok(path), Ok(bound)) => collides(path, bound),
|
|
34
|
+
_ => false,
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// Whether `rule` holds for the text `s` spells; bytes that spell no text
|
|
39
|
+
/// are no name at all.
|
|
40
|
+
fn holds(s: RString, rule: fn(&str) -> bool) -> bool {
|
|
41
|
+
std::str::from_utf8(&crate::to_bytes(s)).is_ok_and(rule)
|
|
42
|
+
}
|
|
@@ -16,10 +16,10 @@ module Kobako
|
|
|
16
16
|
# The Extension readers are duck-typed, so a malformed +name+ or
|
|
17
17
|
# +backend.path+ surfaces through the registry it routes to.
|
|
18
18
|
def install(extension, snippets:, services:)
|
|
19
|
-
validate
|
|
19
|
+
validate(extension)
|
|
20
20
|
snippets.register(code: extension.source, name: extension.name)
|
|
21
21
|
backend = extension.backend
|
|
22
|
-
services.bind(backend.path,
|
|
22
|
+
services.bind(backend.path, object_of(backend)) if backend
|
|
23
23
|
@entries << extension
|
|
24
24
|
self
|
|
25
25
|
end
|
|
@@ -27,7 +27,7 @@ module Kobako
|
|
|
27
27
|
# The asserted flag flips only on success, so a check that failed
|
|
28
28
|
# re-runs on the next invocation rather than silently passing a broken
|
|
29
29
|
# Sandbox.
|
|
30
|
-
def assert_dependencies
|
|
30
|
+
def assert_dependencies
|
|
31
31
|
return self if @asserted
|
|
32
32
|
|
|
33
33
|
extension, dependency = unmet_dependency
|
|
@@ -52,7 +52,7 @@ module Kobako
|
|
|
52
52
|
|
|
53
53
|
private
|
|
54
54
|
|
|
55
|
-
def
|
|
55
|
+
def object_of(backend) = backend.object.nil? ? Kobako::Unresolved : backend.object
|
|
56
56
|
|
|
57
57
|
def resolve_backend(extension, resolved, by_provider)
|
|
58
58
|
backend = extension.backend
|
|
@@ -64,15 +64,27 @@ module Kobako
|
|
|
64
64
|
resolved[backend.path.to_s] = by_provider.fetch(provider) { by_provider[provider] = provider.call }
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
-
def validate
|
|
67
|
+
def validate(extension)
|
|
68
68
|
source = extension.source
|
|
69
|
-
raise
|
|
69
|
+
raise TypeError, "Extension #source must be a String, got #{source.class}" unless source.is_a?(String)
|
|
70
70
|
|
|
71
|
+
validate_dependencies(extension.depends_on)
|
|
71
72
|
backend = extension.backend
|
|
72
73
|
return if backend.nil?
|
|
73
74
|
return if backend.respond_to?(:path) && backend.respond_to?(:object) && backend.respond_to?(:provider)
|
|
74
75
|
|
|
75
|
-
raise
|
|
76
|
+
raise TypeError, "Extension #backend must expose #path, #object, and #provider"
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Each dependency names an Extension as its +name+ does.
|
|
80
|
+
def validate_dependencies(dependencies)
|
|
81
|
+
return if dependencies.nil?
|
|
82
|
+
unless dependencies.is_a?(Array)
|
|
83
|
+
raise TypeError,
|
|
84
|
+
"Extension #depends_on must be an Array, got #{dependencies.class}"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
dependencies.each { |dependency| Kobako.to_name(dependency, "Extension #depends_on entry") }
|
|
76
88
|
end
|
|
77
89
|
|
|
78
90
|
def unmet_dependency
|
data/lib/kobako/catalog/flags.rb
CHANGED
|
@@ -13,15 +13,13 @@ module Kobako
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def register(name, value, advisory:)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
end
|
|
19
|
-
raise ArgumentError, "flag value must be a String, got #{value.class}" unless value.is_a?(String)
|
|
16
|
+
name = Kobako.to_name(name, "flag name")
|
|
17
|
+
raise TypeError, "flag value must be a String, got #{value.class}" unless value.is_a?(String)
|
|
20
18
|
|
|
21
|
-
key = Catalog.to_utf8
|
|
19
|
+
key = Catalog.to_utf8(name, "flag name")
|
|
22
20
|
raise ArgumentError, "flag #{key.inspect} already set" if @entries.key?(key)
|
|
23
21
|
|
|
24
|
-
@entries[key] = [Catalog.to_utf8
|
|
22
|
+
@entries[key] = [Catalog.to_utf8(value, "flag value"), !advisory]
|
|
25
23
|
nil
|
|
26
24
|
end
|
|
27
25
|
end
|
|
@@ -4,7 +4,7 @@ module Kobako
|
|
|
4
4
|
module Catalog
|
|
5
5
|
class Grants # :nodoc:
|
|
6
6
|
def initialize
|
|
7
|
-
@entries = {} # : Hash[
|
|
7
|
+
@entries = {} # : Hash[key, Mount | Network]
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
# Each Grant decides what it cannot stand beside.
|
|
@@ -20,10 +20,11 @@ module Kobako
|
|
|
20
20
|
@entries.key?(grant.key)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
#
|
|
24
|
-
# the Grant it shares a key with.
|
|
23
|
+
# The Mounts, then the network entries, each as the native side reads
|
|
24
|
+
# it, an override standing in for the Grant it shares a key with.
|
|
25
25
|
def entries(overrides = {})
|
|
26
|
-
@entries.merge(overrides).values
|
|
26
|
+
grants = @entries.merge(overrides).values
|
|
27
|
+
[grants.grep(Mount).map(&:to_native), grants.grep(Network).map(&:to_native)]
|
|
27
28
|
end
|
|
28
29
|
end
|
|
29
30
|
end
|