WebAssembly Micro Runtime (WAMR)

repository·main·Indexed 27 days ago

https://github.com/bytecodealliance/wasm-micro-runtime

A 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.

Tokens
70.2K
Snippets
183
Records
406
Agent score
91%

What's inside wasm-micro-runtime

  1. Overview of WAMR-IDE

    main

    WAMR-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:

    1. VSCode extension: Used to build, manage, run, and debug Wasm applications.
    2. WASM-toolchain: A Docker image providing the building environment for Wasm.
    3. WASM source debug server: A Docker image providing the running and source debugging environment for Wasm applications.
  2. Overview of WAMR embedding capabilities in the basic sample

    main

    The basic sample 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
  3. Overview of WebAssembly Micro Runtime (WAMR)

    main

    WebAssembly 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).

  4. Understand WebAssembly (Wasm) fundamentals

    main

    WebAssembly (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.
  5. Understand WAMR Execution Modes and Components

    main

    WAMR 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 .wasm binary files into .aot files. These AOT files are optimized for performance and can be executed by the iwasm VM 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.
  6. Understand WAMR Module Validation and Execution Security

    main

    WAMR 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.
  7. Key Features of WAMR

    main

    WAMR 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.
  8. Embed WAMR in different programming languages

    main

    WAMR (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.
  9. Understand WebAssembly Security and WAMR Sandboxing

    main
    WebAssembly (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.