Plug-ins: read the manifest from a custom section before running any code

A module may carry its manifest in a `vc_manifest` custom section, with
`"abi": 1` in place of the `vc_abi_version` export. When it does,
Plugin::load parses the manifest from the section and does not
instantiate the module: its start function, data segments,
`vc_abi_version` and `vc_manifest` do not run when it is inspected,
installed or loaded at startup. The host checks the imports against the
manifest's permissions, the exports `memory`, `vc_alloc` and `vc_run`
by type, and the initial memory and the tables against the limits a run
has (at most 4 tables of 100,000 elements). A module with more than one
such section is refused, and so is a section over 64 KiB, before its
contents are decoded, and a manifest in the section without `"abi": 1`.
The host uses the section and does not call a `vc_manifest` export.
Modules without the section load as before.

The Desaturate example carries the section and keeps the export, and
its fixture is rebuilt with Rust 1.100.0. build.sh clears RUSTFLAGS:
.cargo/config.toml sets `+simd128` for wasm32, and the host refuses
SIMD instructions. wat::sectioned builds test plug-ins with the section.
This commit is contained in:
dotCooCoo committed 2026-11-20 21:39:33 -08:00
1 parent 9fff48d88f
commit b919dbd66f
36 files changed
+539 -41

No files matched your search

+20
View File
@@ -12,6 +12,7 @@ const MANIFEST: &str = r#"{
"name": "Desaturate",
"version": "1.0.0",
"kind": "filter",
"abi": 1,
"author": "VectorCraft contributors",
"description": "Moves the colours of the selected paths towards grey; an example of the plug-in ABI.",
"params": {
@@ -19,6 +20,25 @@ const MANIFEST: &str = r#"{
}
}"#;
/// The manifest in the `vc_manifest` custom section, where the host reads it, with its `abi`
/// version, without running any of the module's code. The `vc_manifest` export below returns the
/// same text for hosts that read only the export.
#[used]
#[unsafe(link_section = "vc_manifest")]
static MANIFEST_SECTION: [u8; MANIFEST.len()] = section_bytes();
/// `MANIFEST` as a byte array, which `link_section` needs.
const fn section_bytes<const N: usize>() -> [u8; N] {
let text = MANIFEST.as_bytes();
let mut out = [0; N];
let mut i = 0;
while i < N {
out[i] = text[i];
i += 1;
}
out
}
#[unsafe(no_mangle)]
pub extern "C" fn vc_abi_version() -> u32 {
1