Skip to content

wasm-rtos: one .wasm file runs on an ESP32, an STM32 and in the browser

A program is an ordinary .wasm file built from C, C++ or an Arduino sketch, and the kernel runs it the way a desktop OS runs an executable. The same file runs on an ESP32, on an STM32 and in the browser simulator at https://wasm-rtos.github.io, and a program stopped on one of them can go on on another.

It is written from scratch: a kernel and its own interpreter, both small enough for chips with 128 KB of RAM (the interpreter alone fits an Arduino Uno), both in plain C with no platform code.

How it fits together

Programs, the kernel, the interpreter and the board, and what passes between them

  • A program calls the system through imports: WASI for files, time and output, and the wasm-rtos ABI (versioned, frozen at 1.8) for kernel objects and devices. It never sees an address of the host.
  • The kernel decides: which program runs next and for how long, which frames of memory stay in RAM. It has no platform code: a board gives it a clock through a small port.
  • The devices (wasm-rtos-hw) lend pins, buses, displays and the rest to one program at a time; a board registers what it has through small ports. They need from the kernel only what one header declares, so a scheduler of one's own can have them too.
  • The interpreter runs the program's own instructions, counts them and stops between any two of them, and pages the program's memory. It knows nothing of tasks or devices.

What the interpreter does

Task A runs until its fuel is gone and stops between two instructions; task B gets a slice; later A goes on from the next instruction

  • Fuel. One unit is one WebAssembly instruction of the module, counted by the interpreter itself: programs are not rewritten or instrumented first. The same program uses the same fuel on every device (a test run takes 900013 on an ESP32, an STM32 and a computer alike).
  • A safe point at every instruction. A call stops when its fuel runs out, when a host function asks, or when memory it touches is on its way from storage. Everything about the stopped program is plain data.
  • Portable snapshots. A stopped program is saved by its position in the module, not by host addresses, and continues in another build, on another chip, with other pointer sizes.
  • MMU. Programs' memory is paged in frames (4 KiB by default) through a TLB; a pager of the host moves frames to storage and back, in the background where the storage can. A memory in one block costs nothing on the fast path.
  • Code as a cache. Functions are decoded into compact records for a fast loop at their first call; the records are dropped when memory is short and made again when needed, never those of a function on a call stack.
  • The full standard. WebAssembly 2.0 without SIMD: the official test suite passes (27437 checks), also under the sanitizers, in every build.
  • dylink.0 shared libraries, traces after a trap, options to leave out validation, 64-bit integers, floats or reference types on small chips.

What the kernel does

  • Preemption without a timer interrupt. Each program gets a slice of fuel, so a plain int main with an endless loop still shares the processor, and a program cannot block the others.
  • Real-time objects for the host and for programs: priorities with priority inheritance, queues, mutexes, semaphores, event groups, task notifications, software timers, waiting for several objects at once.
  • Processes. Programs start other programs from memory or a file path with arguments, wait for their exit codes and stop them; libraries are shared, each process with its own copy of their data.
  • Isolation. Each program has its own memory and reaches the kernel only through checked calls; a program that traps ends alone, and the pins and devices it held come back.
  • Devices for programs, each lent to one program at a time: GPIO by pin name, displays, input devices, I2C, SPI and 1-Wire buses, analog inputs and outputs, PWM, serial ports, pulse trains (addressable LEDs, IR) and counters (encoders). Transfers can run in the background with DMA while only the calling program waits.
  • Memory larger than RAM. With a page store, programs' memory is a cache in RAM; a waiting program can leave RAM altogether and come back when it runs.
  • A file system behind the WASI file calls, with a read-only tar driver; programs start from files.

Memory larger than RAM

A program's memory in frames, some in RAM and some in a page store, and predecoded code as a cache

The interpreter pages, the kernel decides. A frame comes into RAM when the program touches it; while a slow store reads it, only that program waits. When RAM is full the kernel sends a frame not touched lately to the page store, writing it only if it was written. Decoded code is a cache in the same RAM and gives way first: a program's memory is never refused while records can be made again later.

Measured

18 programs at once on an ESP32, 9 on an STM32, the interpreter in 34.7 KB on an Uno, 27437 spec checks

  • CoreMark inside the OS, among the other programs: 11.8 on an ESP32, 5.84 on an STM32F411.
  • Memory larger than RAM: on an ESP32 with 250 KB of free heap, a program with 640 KB of memory runs, paged from an SD card.
  • The same work, the same fuel: a test program takes 900013 units on an ESP32, an STM32 and a computer alike.

The board checks also cover traps, sleeping on time, fair shares between equal programs, priorities, wake-up latency, queues between programs and that every byte comes back after shutdown.

Repositories

Repository What is in it
wasm-rtos The kernel: scheduler, objects, processes, files, paging policy, the guest ABI (include/wasm-rtos.h, wit/kernel.wit).
wasm-rtos-hw The devices: pins, buses, displays, input, analog, PWM, serial ports, pulse trains, 1-Wire, counters; the ports a board fills in and drivers of one's own. What they need from an operating system is one header.
wasm-rtos-vm The interpreter: fuel, MMU, code cache, snapshots, dylink.0, WASI without files. Usable on its own.
wasm-rtos-examples Small, complete hosts and programs for every layer: the interpreter alone, a mini OS of the interpreter and the devices, the kernel with tasks, queues and devices. Built and run in CI.
wasm-rtos-libraries Libraries inside programs: the Arduino core (Serial, Wire, SPI) and ports of Arduino libraries for 1-Wire sensors, encoders and addressable LEDs.
wasm-rtos-tests One test per feature, run on every change of the kernel, also under the sanitizers.
wasm-rtos.github.io The browser simulator: the same kernel compiled to WebAssembly, a dev board with devices, a bus analyzer.

Roadmap

Where the project stands, kept up to date with every merged change. Ideas and questions: Discussions.

Now: the interpreter, as good as it can be

  • Instances and modules keep only the memory they use: the tour program's module 26% smaller, 920 bytes less for each of its processes on an ESP32, the Uno runs its test program again (wasm-rtos-vm#24)
  • A faster fast loop: the top of the stack in a register, canonical types, handlers of their own for byte and 16-bit accesses and globals; CoreMark +28.8% on an ESP32, +15.5% on a Mac (wasm-rtos-vm#25)
  • Code quality: the static analyzer finds nothing, no const cast away, the two loops in files of their own, GCC builds without a warning on every chip, CI builds with clang and GCC (wasm-rtos-vm#26)
  • The instructions described once, in one list both loops are made from (wasm-rtos-vm#27)
  • Every experiment written down with its numbers, kept or not (wasm-rtos-vm#28)
  • Fuzzing the loader, the interpreter and snapshots, and the engine against itself; snapshots checked against the code as modules are, and references on the stack that survive a fresh instance (wasm-rtos-vm#29)
  • A profile of what programs run, and speed and size in CI by counts of instructions, against each pull request's base (wasm-rtos-vm#31)
  • Clear hot code, and fused records chosen by the profile: CoreMark +2.9% on an ESP32, +3.8% on a Black Pill (wasm-rtos-vm#33)
  • Operands in records, the gain of a register machine with fuel and snapshots exact as before: CoreMark +3.7% on an ESP32, +8.8% on a Black Pill (wasm-rtos-vm#34)
  • Paged memory closer to memory in one block: an addend in the TLB, fused loads on paged memories; CoreMark paged +6.1% on an ESP32 (wasm-rtos-vm#35)
  • Programs' code in flash or PSRAM, RAM only for the hot functions: CoreMark from flash with no RAM for code 3% slower on an ESP32; short of RAM 2% slower instead of half (wasm-rtos-vm#36)
  • Moves fused with what takes them next: CoreMark +7.7% on an ESP32, +11% on a Black Pill (wasm-rtos-vm#37)
  • The register loop (decision 16): frame slots as operands, fuel and snapshots exact as before; CoreMark +33% on an ESP32, +28% on a Black Pill (wasm-rtos-vm#38)
  • Shorter records, below the stack loop's (wasm-rtos-vm#39)
  • The kernel and its tests on this interpreter (wasm-rtos#75, wasm-rtos-tests#75): CoreMark in the system 17.5 → 22.6 on an ESP32
  • Code stores: programs' decoded code kept in flash or PSRAM, by priority, so it needs no RAM and programs start without predecoding (wasm-rtos#77); a failed instantiation no longer leaks (wasm-rtos#76)

Before: programs that live through deep sleep

  • The kernel saves the whole system before the RAM is lost and restores it after: tasks with their waits, queues, mutexes, semaphores, events, timers, children, open files; the clock goes on with the time slept (wasm-rtos#69)
  • Drivers save and restore their devices, so programs that hold pins, buses, serial ports or a display can be saved too (wasm-rtos#70)
  • Waking by a pin a sleeping program waits on (#70)
  • On boards: an ESP32 in deep sleep woken by its timer and by a pin, the system on its SD card (saved in 0.1 to 0.24 s, restored in 61 to 73 ms); a Black Pill reset, the system in flash (restored in 40 ms) (#70)

1.0: everything of it done; tagged once the interpreter work above is done too

  • The guest ABI 1.x frozen at 1.8: programs built with a newer 1.x header still load, calls a kernel lacks return -WR_EUNSUPPORTED, every WASI call links; CI holds the kernel to the frozen list (wasm-rtos#71)
  • Every repository explains its design in docs/decisions.md (wasm-rtos-libraries#1)
  • The simulator on the current kernel: programs' memory paged under each device's RAM budget, and a sleep button that saves the whole system and wakes it by its timer, a pin or a press, even across a reload (wasm-rtos.github.io#39)
  • Processes of one program share it: loaded once, found by its contents, so a program and its child from an SD card fit on an ESP32 without PSRAM (wasm-rtos#72)
  • The simulator's chip settings: the ESP32 measured on a real board (heap in its regions, RAM for programs, the SD card's speed), so the page runs out of memory where the board does, and chips of your own (wasm-rtos.github.io#40)
  • Several page stores with priorities the person sets (an SD card and the computer on the cable, say), and one going away without taking everything with it (wasm-rtos#73)
  • A board over its serial port, from a script or from the page: its console, putting and running programs, the computer's files and the computer as its page store, so a board without an SD card runs programs larger than its RAM (wasm-rtos.github.io#41)
  • One program on an ESP32 and on the page, with the same output, compared line by line; Run on both does it from the page (wasm-rtos.github.io#43)
  • Changelogs
  • Devices in a library of their own, wasm-rtos-hw, with the prefix hw_; what they need from an operating system is one header (wasm-rtos#81)
  • Each layer holds what is its own: WASI without files in the interpreter, device imports bound by the device library, the host's RTOS out of the kernel's API, a simple host for a mini OS of the interpreter and the devices, the public API at 1.0 checked in CI (wasm-rtos#84, wasm-rtos-vm#43, wasm-rtos-hw#1)
  • Examples of every layer in a repository of their own, built and run in CI (wasm-rtos-examples)
  • The interpreter's own heap, the same on every platform: constant time, code kept apart from what stays, so memory comes back in one piece (wasm-rtos-vm#45, wasm-rtos#86)
  • A function runs in place by itself when its code finds no room, and idle tasks make no new code (wasm-rtos-vm#46, wasm-rtos#87)
  • Tags and the 1.0 release (v1.0.0 in every repository)

After 1.0

  • Moving a running program to another device or into the browser
  • dylink.0 programs in snapshots
  • More from the MMU: zero frames never written, a compressed page store in RAM, sleeping tasks' frames written ahead in quiet time (wasm-rtos-vm#40, wasm-rtos#78, wasm-rtos-vm#41, wasm-rtos#80)
  • Reading frames ahead and storage drivers with DMA
  • A faster interpreter: operands inside records, code records in flash (done before 1.0: the register loop and code images above)
  • Programs in more languages: a Rust crate for the ABI
  • Programs that state what they need, power management, windows for programs with a display, graphics libraries
  • A redesigned simulator with components and chip models

Timeline

Timeline from July to November 2026

When What
July 2026 The kernel starts: synchronization objects, queues, software timers and a tickless clock, on a third-party interpreter patched for fuel and snapshots. A browser dashboard shows the scheduler live.
August 2026 Shared WebAssembly libraries and programs loaded at run time.
Late October 2026 Processes (spawn, wait, kill), a virtual file system, entry points found and imports checked at load.
1–2 November 2026 Guest ABI 1.0 and the device interfaces in a few days: GPIO, display and input, I2C and SPI with background transfers, analog inputs, PWM, serial ports, pulse trains. The Arduino core: sketches and libraries become programs. Swapping and portable snapshots.
7 November 2026 ABI 1.6–1.8: 1-Wire, counters and encoders, analog outputs. First runs on a real ESP32.
9 November 2026 Our own interpreter, wasm-rtos-vm, becomes the engine: faster than the patched one on the boards (CoreMark on a bare ESP32 13.1 against 4.0), with the same API to the kernel. Drivers become pluggable modules. Records packed into 32-bit cells.
11 November 2026 The MMU: paged memory, a TLB, a page store with dirty frames written like a log, frames read and written in the background, whole tasks swapped out through it.
12 November 2026 Code as a cache: 50% more programs at once on an ESP32 and a Black Pill. Memory before code. CI builds the interpreter and the kernel in every configuration and runs the whole suite on every change.

All of it is public domain.

Pinned Loading

  1. wasm-rtos.github.io wasm-rtos.github.io Public

    JavaScript

Repositories

Showing 9 of 9 repositories
  • wasm-rtos/wasm-rtos-tests's past year of commit activity
    C 0 Unlicense 0 0 0 Updated Nov 23, 2026
  • .github Public
    wasm-rtos/.github's past year of commit activity
    Python 0 0 0 0 Updated Nov 23, 2026
  • wasm-rtos Public
    wasm-rtos/wasm-rtos's past year of commit activity
    C 0 Unlicense 0 0 0 Updated Nov 23, 2026
  • wasm-rtos-vm Public

    A small WebAssembly interpreter for microcontrollers, the engine of wasm-rtos

    wasm-rtos/wasm-rtos-vm's past year of commit activity
    C 0 Unlicense 0 0 0 Updated Nov 23, 2026
  • wasm-rtos-examples Public

    Small, complete programs showing how the interpreter, the devices and the kernel of wasm-rtos fit together

    wasm-rtos/wasm-rtos-examples's past year of commit activity
    C 0 Unlicense 0 0 0 Updated Nov 22, 2026
  • wasm-rtos-hw Public

    The devices WebAssembly programs reach on wasm-rtos: pins, buses, displays, input, analog, PWM, serial, pulse trains, 1-Wire and counters

    wasm-rtos/wasm-rtos-hw's past year of commit activity
    C 0 Unlicense 0 0 0 Updated Nov 22, 2026
  • wasm-rtos/wasm-rtos.github.io's past year of commit activity
    JavaScript 0 Unlicense 0 0 0 Updated Nov 13, 2026
  • wasm-rtos-libraries Public

    Libraries for programs that run on wasm-rtos: the Arduino core and ports of Arduino libraries

    wasm-rtos/wasm-rtos-libraries's past year of commit activity
    C++ 0 Unlicense 0 0 0 Updated Nov 13, 2026
  • wasm3 Public archive Forked from wasm3/wasm3

    Experimental wasm3 fork with fuel, yield/resume, and runtime snapshot extensions.

    wasm-rtos/wasm3's past year of commit activity
    C 0 MIT 548 0 0 Updated Nov 7, 2026