@huihoo: NASA 开源 Rust 开发的符合航空标准的 WebAssembly 解释器 https://github.com/nasa/spacewasm 最近,#Rust 重构、重新实现的开源项目有些多,要挺住
摘要
NASA开源了SpaceWasm,这是一个用Rust编写的、符合航空标准的WebAssembly解释器,专为航天器机载环境设计,支持流式解码和确定性内存分配。
查看缓存全文
缓存时间: 2026/07/11 17:27
NASA 开源 Rust 开发的符合航空标准的 WebAssembly 解释器 https://github.com/nasa/spacewasm 最近,#Rust 重构、重新实现的开源项目有些多,要挺住
nasa/spacewasm
Source: https://github.com/nasa/spacewasm
SpaceWasm
SpaceWasm is an implementation of the Wasm 1.0 specification meant to interpret Wasm binary on-board spacecraft. This software comes with two major components:
-
Decoder/Validator:
Reads the Wasm binary in chunks and decodes it to an executable form. The decoder will use a fixed amount of memory and can be measured per-Wasm binary using the
spacewasm-checkexecutable on the ground.WebAssembly is validated during the decoding process and does not require another pass of the bytecode.
-
Interpreter:
A Wasm interpreter that can operate on linear memory and interface with hooks from the embedding.
SpaceWasm does not execute direct WebAssembly bytecode. Wasm bytecode is meant to be small and structured in a way to validate easily. These properties however make it slow to execute in-place. During the decoding process of Wasm instructions, SpaceWasm converts bytecode into another intermediate representation (IR) which includes properties better suited for interpretation. Read more about the IR in the specification.
Requirements
The requirements of SpaceWasm are levied from similar work produced by DLR.
See requirements.
Embedding
Embedding the interpreter refers to instantiating it and providing implementations for the functions that are imported into the module. Typically, the set of functions imported by the module are fixed and should be specified at compile time both for the Wasm module and the embedder.
Dynamic Allocation
SpaceWasm has a unique dynamic memory allocation model. All of its design choices stem from requirements levied by common flight-software standards. Dynamic allocation follows the following rules:
- All allocations occur over a discrete number of fixed size blocks called pages. These pages are distinct from Wasm’s linear memory pages.
- Deallocation cannot precede allocation.
- Sub-regions inside pages cannot grow or shrink, sizes should be fixed ahead of time.
- Memory usage must be deterministic.
- Any allocation failures must not result in panic.
The standard Rust allocation does not meet these constraints even with custom
allocators. To that end, SpaceWasm provides its own data structures that guarantee these properties. You will find these
data-structures contain the only usage of unsafe Rust semantics.
These limitations are only enforced on the implementation of the interpreter and not on the Wasm bytecode it is made to interpret.
Wasm linear memory pages are allocated outside of dynamic memory pages.
Streaming
Peak memory usage is often an important constraint on small systems found on spacecraft. Many Wasm interpreters require the Wasm binary to be given in one linear blob to the interpreter. This is typically fine for systems where the same regions of memory may be reused for different purposes. Flight software on spacecraft generally assign fixed portions of memory for certain purposes. Therefore, requiring the entire Wasm binary to fit into a single chunk of memory is not feasible.
SpaceWasm is highly optimized to reduce peak memory usage and not require deallocation after allocation required for streaming. To this end, there are certain constraints imposed on the WebAssembly specification.
SpaceWasm supports decoding and compiling Wasm binary in a single pass via a streaming mechanism. Chunks of the Wasm binary may be provided to the interpreter as they are read/requested from the filesystem. The stream must provide chunks synchronously.
Interpreter Limitations
This Wasm interpreter imposes additional constraints beyond the WebAssembly 1.0 specification to support resource-constrained spacecraft environments.
See our IR SPEC for the full list of limitations.
These constraints enable deterministic memory usage and efficient execution in resource-constrained environments while maintaining compatibility with most standard WebAssembly modules.
Limits for Wasm Module Producers
Because SpaceWasm compiles bytecode into a fixed-width IR that is typically larger than the original bytecode, the
practical ceiling on raw module size is bounded by the IR code-page limit above (~8 GiB of IR). This is far larger than
any module expected on flight hardware; the binding constraint in practice is the peak memory configured for the
streaming decoder, which is measured per-module on the ground with spacewasm-check.
spacewasm-checkhas not been developed yet. A similar tool can be found inspacewasm-std.
Here are a couple of limitations that may be relavent to developers of Wasm modules.
| Limit | Value | Notes |
|---|---|---|
| Wasm page size | 64 KiB (65,536 bytes) | The standard WebAssembly linear memory page size. The custom-page-sizes proposal is planned but not yet supported, so this value is fixed. |
| Linear memory pages | 65,536 pages (4 GiB) | Per the Wasm 1.0 spec. A module declaring more (or a max above this) is rejected. Note that the embedding will definitely limit this but it is dependent on how the interpreter is deployed. |
| IR Code | 8GiB | Compiled IR, not raw bytecode. This limit is across all modules in the store. The IR / Bytecode ratio is printed in spacewasm-std as the “compilation ratio”. It is difficult to estimate this upfront because it varies on the types of instructions used. |
| Function parameters | 255 32-bit words | Per function. |
| Local variables | 65,535 32-bit words | Per function. |
Similar Projects
While SpaceWasm is a ground up implementation, it draws on some other similar projects:
- https://github.com/wasmi-labs/wasmi
- https://github.com/wasm3/wasm3
- https://github.com/DLR-FT/wasm-interpreter
Benchmarking
SpaceWasm is tested against the Coremark benchmark to trace performance regression. See coremark for more information.
Testing
Unit & Integration Tests
cargo test
The unit tests check for regressions on the unsafe container abstractions provided by SpaceWasm due to unique alloc
usage. There are also simple unit tests that cover all Wasm instructions without needing full WAST execution.
The integration tests are spectests from the Wasm 1.0 MVP suite which was curated in https://github.com/WasmEdge/wasmedge-spectest. These tests validate the integriy of the Wasm interpreter against the specification.
Fuzzing
SpaceWasm includes a comprehensive fuzzing infrastructure using libfuzzer and wasm-smith.
# Run fuzzer
make fuzz
# Analyze crashes with execution traces
make trace CRASH=fuzz/artifacts/no_traps/crash-xxx
Feature Support Matrix
SpaceWasm currently implements exactly WebAssembly 1.0 (the MVP plus the mutable-globals proposal that was folded into it). SpaceWasm will always be a subset of the full approved Wasm specification. Below is a table of the implemented and planned .
| Feature | Status |
|---|---|
| Wasm MVP | Supported |
| Mutable globals | Supported |
| Custom page sizes | Planned |
| Bulk memory operations | Planned |
| Sign-extension operators | Planned |
| Non-trapping float-to-int conversions | Planned |
| Multi-value | Under Consideration |
| Multiple memories | Under Consideration |
Currently, all other proposals are not planned or considered.
Credits & Acknowledgments
Portions of this project are adapted from the open-source projects:
- DLR-FT/wasm-interpreter, which is licensed under the Apache License 2.0.
- Wasmtime, which is licensed under the Apache License 2.0 with LLVM-exception.
- WABT, which is licensed under the Apache License 2.0.
- wasmedge-spectest, which is licensed under MIT.
- WebAssembly Testsuite, which is licensed under the Apache License 2.0.
- Coremark, which is licensed under the COREMARK ACCEPTABLE USE AGREEMENT.
- Wasm Coremark, which provides no upstream license file; the wrapped CoreMark payload is governed by the COREMARK ACCEPTABLE USE AGREEMENT.
相似文章
SpaceWASM:NASA/JPL 用于航天器序列化的 WebAssembly 解释器
SpaceWASM 是一个来自 NASA/JPL 的开源 WebAssembly 解释器,专为航天器机载序列化设计,注重确定性内存使用和在资源受限环境下的流式处理能力。
Show HN: Nectar——一个类 Rust 的 React,编译为 WebAssembly
Nectar 是一个新型 Web 框架,将类 Rust 代码编译为 WebAssembly,通过 O(1) 信号更新和零依赖构建消除了 JavaScript 依赖。
Show HN: 运行于 WebAssembly 的 Firefox
Firefox 被编译为在 WebAssembly 中运行,采用基于 WebGL 的渲染和实验性的 JS 到 WASM JIT,网页内容通过 Puter 托管的 Wisp 服务器进行代理。
@0xLogicrw: 腾讯云开源了 AI Agent 沙盒 Cube Sandbox,Rust 编写,Apache 2.0 协议。 Agent 跑模型生成的代码需要一个隔离环境,避免误删文件或越权访问主机。这类服务的接口事实标准是 E2B,OpenAI Age…
腾讯云开源Rust编写的AI Agent沙盒Cube Sandbox,兼容E2B接口标准,为模型生成代码提供隔离运行环境。
Wasmer 如何使用 Codex 构建面向边缘计算的 Node.js 运行时
Wasmer 利用 OpenAI 的 Codex 构建了 Edge.js,这是一个运行在 WebAssembly 沙箱中的边缘计算 Node.js 运行时,将开发周期从一年缩短至两周。