WebAssembly Micro Runtime (WAMR)
repository·main·Indexed 27 days ago
https://github.com/bytecodealliance/wasm-micro-runtimeA lightweight, high-performance WebAssembly runtime designed for resource-constrained environments such as IoT, embedded systems, and edge computing, as well as cloud-native and TEE use cases. WAMR supports post-MVP features including 128-bit SIMD, Reference Types, and the WebAssembly C API. It provides language bindings for Go and Python, supports WASI-NN with backends like TensorFlow Lite, OpenVINO, Llama.cpp, and ONNX Runtime, and includes tools for remote application management via host_tool.
What's inside wasm-micro-runtime
- This project provides the WebAssembly Micro Runtime (WAMR), a lightweight WebAssembly runtime designed for resource-constrained environments. The documentation covers WebAssembly fundamentals, the WAMR project architecture, and security features provided by both the WebAssembly specification and WAMR's specific enhancements.
Overview of WAMR-IDE
mainWAMR-IDE is an experimental Integrated Development Environment for developing WebAssembly applications. It provides support for coding, compiling, and source debugging. The IDE consists of three main components:
- VSCode extension: Used to build, manage, run, and debug Wasm applications.
- WASM-toolchain: A Docker image providing the building environment for Wasm.
- WASM source debug server: A Docker image providing the running and source debugging environment for Wasm applications.
Overview of WAMR embedding capabilities in the basic sample
mainThe
basicsample project serves as a demonstration for the following WAMR embedding tasks:- Initialize runtime
- Load WASM app and instantiate the module
- Call WASM function and pass arguments
- Export native functions to the WASM apps
- WASM function calls native function and pass arguments
- Deinitialize runtime
Overview of WebAssembly Micro Runtime (WAMR)
mainWebAssembly Micro Runtime (WAMR) is a lightweight, standalone WebAssembly (Wasm) runtime designed for a small footprint and high performance. It is suitable for embedded systems, IoT, edge computing, Trusted Execution Environments (TEE), smart contracts, and cloud-native applications.
Core components include:
- VMcore: Runtime libraries for loading and running Wasm modules. Supports Interpreter, Ahead-of-Time (AoT) compilation, and Just-in-Time (JIT) compilation (including Fast JIT and LLVM JIT).
- iwasm: An executable binary built with VMcore that supports WASI and a command-line interface.
- wamrc: An AOT compiler used to compile Wasm files into AOT files.
Additional tools include the App-framework for Wasm application APIs, App-manager for remote dynamic loading, and WAMR-IDE (a VSCode extension).
Introduction to the sgx-ra sample
mainThe
sgx-rasample demonstrates how to execute Remote Attestation on Intel SGX using librats and running it with theiwasmruntime.Prerequisites:
- This sample can only build on SGX supported processors.
- The
WASI-SDKmust be installed at/opt/wasi-sdk.
Understand WebAssembly (Wasm) fundamentals
mainWebAssembly (Wasm) is a compact, binary instruction format designed for a stack-based virtual machine. It serves as a portable compilation target for various programming languages, enabling high-performance execution in both client (browser) and server environments.
Key characteristics include:
- High Performance: Near-native execution speeds through compact encoding and hardware leveraging.
- Secure Execution: Operates in a memory-safe, sandboxed environment.
- Portability: A language-agnostic format that can run anywhere.
- Textual Representation: Provides a human-readable format for debugging and optimization.
Understand WAMR Execution Modes and Components
mainWAMR consists of several core components that determine how WASM code is executed:
1. iwasm (VM Core)
The core virtual machine that runs WASM applications. It supports multiple execution modes to balance responsiveness and performance:
- Interpreter mode: Smallest footprint (~85K binary size).
- AOT mode (Ahead-of-Time): Highest performance and smallest runtime footprint (~50K binary size).
- JIT modes (Just-in-Time): Includes LLVM JIT and Fast JIT for near-native speed.
2. wamrc (AOT Compiler)
The compiler used to transform
.wasmbinary files into.aotfiles. These AOT files are optimized for performance and can be executed by theiwasmVM core.3. Application Framework & Manager
- Application Framework: Provides a comprehensive framework for IoT and device-based WASM applications, supporting an event-driven programming model and APIs for Timers, Inter-app communication (request/response, pub/sub), Sensors, Connectivity, and 2D graphic UI.
- Application Manager: Supports remote application management from host environments or the cloud via protocols like TCP, UDP, UART, and BLE.
Understand WAMR Module Validation and Execution Security
mainWAMR provides security through two main phases: validation at load time and enforcement during runtime.
Module Validation (Load Time): Before execution, WAMR performs several checks to ensure the Wasm binary is compliant:
- Format Validation: Checks binary structure (functions, memory, tables, types).
- Type Checking: Verifies function signatures, local variables, and globals.
- Control Flow Integrity: Validates the function call graph and indices.
- Operand Stack Integrity: Checks for stack overflows/underflows against declared signatures.
- Memory and Table Boundaries: Ensures sizes do not exceed predefined limits.
Module Execution (Runtime):
- Memory Safety: Prevents out-of-bounds access using either software boundary checks (address validation) or hardware boundary checks (e.g.,
mmap-based protection). - Deterministic Exceptions: Instead of undefined behavior, WAMR handles specific runtime exceptions.
Key Features of WAMR
mainWAMR provides several advanced features for WebAssembly execution:
- Compliance: Full compliance with W3C Wasm MVP.
- Small Footprint: Highly optimized binary sizes (e.g., ~58.9K for fast interpreter, ~29.4K for AOT runtime on Cortex-M4F).
- Performance: Near-native speeds via AOT and JIT (including multi-tier JIT).
- Execution Modes: Supports Interpreter, Fast JIT, and LLVM JIT with dynamic tier-up.
- Standard Support: Supports WASI, multi-threading (pthread APIs, wasi-threads), and Berkeley/Posix Sockets.
- Advanced Wasm Features: Supports post-MVP features like 128-bit SIMD, Reference Types, Bulk memory operations, Shared memory, Memory64, Tail-call, Garbage Collection, and Exception Handling.
- Extensibility: Simple C APIs for embedding WAMR into host environments and mechanisms to export native APIs to Wasm applications.
Embed WAMR in different programming languages
mainWAMR (WebAssembly Micro Runtime) can be used as a library embedded directly into your own applications. It provides official language bindings for several programming languages, allowing you to run WebAssembly applications within your existing codebase. Supported languages include:
- C/C++: Direct embedding using the WAMR library.
- Python: Via the official Python bindings.
- Go: Via the official Go bindings.
Explore WAMR Sample Implementations
mainThe WAMR repository provides several sample directories that demonstrate specific runtime capabilities, API usage, and advanced features. Use these samples to understand how to implement specific patterns in your own applications.Understand WebAssembly Security and WAMR Sandboxing
mainWebAssembly (Wasm) provides a sandboxed execution environment designed to protect the host runtime from malicious or faulty modules. When using WAMR, modules execute within a fault-isolated sandbox, meaning they cannot escape to the host environment without using explicitly provided APIs. This allows for safe execution of Wasm modules on standalone runtimes without requiring additional OS or hardware-level security support.