kobako 0.12.1 → 0.12.2
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 +11 -0
- data/Cargo.lock +15 -2
- data/Cargo.toml +6 -2
- data/README.md +1 -1
- data/crates/kobako-runtime/CHANGELOG.md +8 -0
- data/crates/kobako-runtime/Cargo.toml +23 -0
- data/crates/kobako-runtime/README.md +34 -0
- data/crates/kobako-runtime/src/dispatch.rs +22 -0
- data/crates/kobako-runtime/src/error.rs +64 -0
- data/crates/kobako-runtime/src/lib.rs +16 -0
- data/crates/kobako-runtime/src/runtime.rs +50 -0
- data/crates/kobako-runtime/src/snapshot.rs +46 -0
- data/crates/kobako-runtime/src/yielder.rs +22 -0
- data/crates/kobako-wasmtime/CHANGELOG.md +8 -0
- data/crates/kobako-wasmtime/Cargo.toml +62 -0
- data/crates/kobako-wasmtime/README.md +32 -0
- data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/ambient.rs +3 -3
- data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/cache.rs +30 -41
- data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/capture.rs +2 -2
- data/crates/kobako-wasmtime/src/config.rs +25 -0
- data/crates/kobako-wasmtime/src/dispatch.rs +110 -0
- data/crates/kobako-wasmtime/src/driver.rs +285 -0
- data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/exports.rs +5 -6
- data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/frames.rs +70 -82
- data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/guest_mem.rs +38 -15
- data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/instance_pre.rs +13 -21
- data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/invocation.rs +54 -49
- data/crates/kobako-wasmtime/src/lib.rs +47 -0
- data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/trap.rs +29 -35
- data/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +9 -32
- data/ext/kobako/src/runtime/bridge.rs +150 -0
- data/ext/kobako/src/runtime/errors.rs +45 -13
- data/ext/kobako/src/runtime.rs +156 -406
- data/ext/kobako/src/snapshot.rs +27 -62
- data/lib/kobako/catalog/handles.rb +3 -3
- data/lib/kobako/catalog/namespaces.rb +4 -0
- data/lib/kobako/catalog/snippets.rb +4 -0
- data/lib/kobako/codec/encoder.rb +5 -1
- data/lib/kobako/codec/factory.rb +41 -13
- data/lib/kobako/codec/handle_walk.rb +4 -0
- data/lib/kobako/errors.rb +18 -16
- data/lib/kobako/sandbox.rb +20 -18
- data/lib/kobako/sandbox_options.rb +25 -9
- data/lib/kobako/snapshot.rb +7 -13
- data/lib/kobako/transport/dispatcher.rb +2 -2
- data/lib/kobako/transport/response.rb +14 -14
- data/lib/kobako/transport/run.rb +2 -6
- data/lib/kobako/transport/yield.rb +1 -1
- data/lib/kobako/transport/yielder.rb +2 -2
- data/lib/kobako/version.rb +1 -1
- data/release-please-config.json +48 -3
- data/sig/kobako/codec/factory.rbs +3 -0
- data/sig/kobako/errors.rbs +7 -14
- data/sig/kobako/runtime.rbs +8 -3
- data/sig/kobako/sandbox.rbs +2 -2
- data/sig/kobako/sandbox_options.rbs +4 -2
- data/sig/kobako/snapshot.rbs +0 -3
- data/sig/kobako/transport/dispatcher.rbs +1 -1
- data/sig/kobako/transport/run.rbs +2 -2
- data/sig/kobako/transport/yielder.rbs +2 -2
- data/sig/kobako/transport.rbs +8 -0
- metadata +27 -12
- data/ext/kobako/src/runtime/config.rs +0 -25
- data/ext/kobako/src/runtime/dispatch.rs +0 -211
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
use magnus::value::Lazy;
|
|
12
12
|
use magnus::{prelude::*, Error as MagnusError, ExceptionClass, RModule, Ruby};
|
|
13
13
|
|
|
14
|
+
use kobako_runtime::error::{Error, SetupError, Trap};
|
|
15
|
+
|
|
14
16
|
/// Resolve `Kobako::<name>` as an `ExceptionClass` — the shared body of
|
|
15
17
|
/// every error-class `Lazy` below, which differ only in the constant
|
|
16
18
|
/// name. The constants are guaranteed present by the time any of these
|
|
@@ -22,22 +24,20 @@ fn kobako_error_class(ruby: &Ruby, name: &str) -> ExceptionClass {
|
|
|
22
24
|
kobako.const_get(name).unwrap()
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
Lazy::new(|ruby| kobako_error_class(ruby, "SetupError"));
|
|
27
|
+
static SETUP_ERROR: Lazy<ExceptionClass> = Lazy::new(|ruby| kobako_error_class(ruby, "SetupError"));
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
static MODULE_NOT_BUILT_ERROR: Lazy<ExceptionClass> =
|
|
29
30
|
Lazy::new(|ruby| kobako_error_class(ruby, "ModuleNotBuiltError"));
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
Lazy::new(|ruby| kobako_error_class(ruby, "TrapError"));
|
|
32
|
+
static TRAP_ERROR: Lazy<ExceptionClass> = Lazy::new(|ruby| kobako_error_class(ruby, "TrapError"));
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
static TIMEOUT_ERROR: Lazy<ExceptionClass> =
|
|
35
35
|
Lazy::new(|ruby| kobako_error_class(ruby, "TimeoutError"));
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
static MEMORY_LIMIT_ERROR: Lazy<ExceptionClass> =
|
|
38
38
|
Lazy::new(|ruby| kobako_error_class(ruby, "MemoryLimitError"));
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
static SANDBOX_ERROR: Lazy<ExceptionClass> =
|
|
41
41
|
Lazy::new(|ruby| kobako_error_class(ruby, "SandboxError"));
|
|
42
42
|
|
|
43
43
|
/// Build a `MagnusError` in `class` carrying `msg` — the shared body of
|
|
@@ -51,7 +51,7 @@ fn error_in(ruby: &Ruby, class: &Lazy<ExceptionClass>, msg: impl Into<String>) -
|
|
|
51
51
|
/// invocation-time wasmtime engine failure that is not a configured-cap
|
|
52
52
|
/// trap — missing exports, allocation faults, memory write/read failures.
|
|
53
53
|
/// Construction-time setup failures use `setup_err`, not this.
|
|
54
|
-
pub(
|
|
54
|
+
pub(super) fn trap_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
|
|
55
55
|
error_in(ruby, &TRAP_ERROR, msg)
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -61,21 +61,21 @@ pub(crate) fn trap_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
|
|
|
61
61
|
/// module, or engine / linker / instantiation setup failure. The
|
|
62
62
|
/// `ModuleNotBuiltError` subclass (artifact absent) is
|
|
63
63
|
/// raised through `MODULE_NOT_BUILT_ERROR` directly.
|
|
64
|
-
pub(
|
|
64
|
+
pub(super) fn setup_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
|
|
65
65
|
error_in(ruby, &SETUP_ERROR, msg)
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/// Construct a `Kobako::TimeoutError` magnus error. Surfaces the
|
|
69
69
|
/// wall-clock cap path with the verb prefix added
|
|
70
70
|
/// by `Kobako::Sandbox#invoke!`.
|
|
71
|
-
|
|
71
|
+
fn timeout_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
|
|
72
72
|
error_in(ruby, &TIMEOUT_ERROR, msg)
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/// Construct a `Kobako::MemoryLimitError` magnus error. Surfaces the
|
|
76
76
|
/// linear-memory cap path with the verb prefix
|
|
77
77
|
/// added by `Kobako::Sandbox#invoke!`.
|
|
78
|
-
|
|
78
|
+
fn memory_limit_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
|
|
79
79
|
error_in(ruby, &MEMORY_LIMIT_ERROR, msg)
|
|
80
80
|
}
|
|
81
81
|
|
|
@@ -85,6 +85,38 @@ pub(crate) fn memory_limit_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusErr
|
|
|
85
85
|
/// envelope reservation failure (`__kobako_alloc` returns 0).
|
|
86
86
|
/// The runtime is intact, so this must not be a
|
|
87
87
|
/// `TrapError`: no discard-and-recreate recovery is owed to the caller.
|
|
88
|
-
|
|
88
|
+
fn sandbox_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
|
|
89
89
|
error_in(ruby, &SANDBOX_ERROR, msg)
|
|
90
90
|
}
|
|
91
|
+
|
|
92
|
+
/// Map a neutral `Trap` onto its `Kobako::TrapError`-family Ruby exception.
|
|
93
|
+
/// The boundary between the magnus-free run mechanics and the Ruby surface:
|
|
94
|
+
/// the run path classifies a fault into a `Trap`, and this is where it
|
|
95
|
+
/// becomes a raised exception.
|
|
96
|
+
pub(super) fn trap_to_magnus(ruby: &Ruby, trap: Trap) -> MagnusError {
|
|
97
|
+
match trap {
|
|
98
|
+
Trap::Timeout(msg) => timeout_err(ruby, msg),
|
|
99
|
+
Trap::MemoryLimit(msg) => memory_limit_err(ruby, msg),
|
|
100
|
+
Trap::Other(msg) => trap_err(ruby, msg),
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/// Map a neutral `SetupError` onto the `Kobako::*` class the SPEC assigns
|
|
105
|
+
/// to each runtime state — artifact-absent, runtime-dead, runtime-intact.
|
|
106
|
+
pub(super) fn setup_to_magnus(ruby: &Ruby, err: SetupError) -> MagnusError {
|
|
107
|
+
match err {
|
|
108
|
+
SetupError::ModuleNotBuilt(msg) => error_in(ruby, &MODULE_NOT_BUILT_ERROR, msg),
|
|
109
|
+
SetupError::Dead(msg) => setup_err(ruby, msg),
|
|
110
|
+
SetupError::Intact(msg) => sandbox_err(ruby, msg),
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/// Map either run-path channel onto its Ruby exception. The single
|
|
115
|
+
/// translation point the run-path entry methods funnel their `Result`
|
|
116
|
+
/// through.
|
|
117
|
+
pub(super) fn to_magnus(ruby: &Ruby, err: Error) -> MagnusError {
|
|
118
|
+
match err {
|
|
119
|
+
Error::Trap(trap) => trap_to_magnus(ruby, trap),
|
|
120
|
+
Error::Setup(err) => setup_to_magnus(ruby, err),
|
|
121
|
+
}
|
|
122
|
+
}
|