1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright (c) 2026 Erik Lening (hollowpointer) and Contributors
//
// This file is part of Zond Engine, licensed under the GNU Affero General
// Public License, version 3 or later. See the LICENSE file for details, or
// <https://www.gnu.org/licenses/agpl-3.0.html>.
//
// SPDX-License-Identifier: AGPL-3.0-or-later
//! # The runtime seam, one trait over every compute backend
//!
//! [`ComputeRuntime`] is the contract a compute backend serves, and the reason
//! there is a contract at all: WebAssembly is the destination and [Rhai] the
//! pure-Rust on-ramp, so a runtime is chosen behind this trait rather than in the
//! detection stage, and choosing Rhai first forecloses nothing, a WebAssembly
//! backend is a second `impl`, not a redesign.
//!
//! [Rhai]: super::RhaiRuntime
//!
//! ## Three stages, because a module is compiled once and run often
//!
//! A detection is validated and compiled once, then run against every open port
//! it is interested in, so the lifecycle is three stages:
//! [`load`](ComputeRuntime::load) turns a body into a shared, reusable module;
//! [`instantiate`](ComputeRuntime::instantiate) draws a cheap per-port instance
//! from it under a [grant](super::Grant); and [`run`](ComputeRuntime::run) runs
//! that instance to completion against one port, serving every capability through
//! the [seam](super::Capabilities). The module is `Send + Sync` and shared behind
//! an `Arc`; an instance is not, and is owned by the one task that runs it.
//!
//! ## The body is bytes the host hands in
//!
//! A [`ModuleBody`] is source or a compiled blob a caller supplies, never a path
//! the engine reads, per the library boundary, the engine hunts no filesystem
//! for detections. Accepting one is safe because it grants nothing: the
//! capability model is what lets a detection be accepted from anywhere.
use cratePortContext;
use RunOutcome;
use ;
use crateFinding;
/// A detection's body, as the host hands it in.
///
/// Non-exhaustive because the compiled-WebAssembly variant joins the source one
/// as the second backend lands, and a caller matching on it should not have to
/// change when it does.
/// Why a module could not be loaded or instantiated.
///
/// A failure before any port is touched, a refusal with a cause, never a run
/// that is quietly clamped. A body that will not compile, or one a given backend
/// cannot serve, is rejected here.
/// A compute backend: loads a module once, instantiates it per port, runs it per
/// port. The one trait a WebAssembly backend and the Rhai one both satisfy.