Skip to content

A fork of wasmtime (a fast and secure runtime for WebAssembly) supporting the WasmFX instruction set

License

Notifications You must be signed in to change notification settings

wasmfx/wasmfxtime

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

This repository is a fork of Wasmtime extended with support for the WasmFX instruction set. WasmFX adds stack switching capabilities to core Wasm, thereby enabling interleaving of computation. The design of the instruction set extension is based on effect handlers, which provide a structured facility for handling non-local control flow.

Additional key resources are

Building

The build steps are equivalent to the standard steps for building Wasmtime from source, but using this repository instead. There is no need to build or install the original version of Wasmtime to use this fork.

Concretely, the steps are as follows:

  1. Make sure that you have a Rust toolchain installed, for example using rustup.
  2. Check out this repository:
git clone https://github.com/wasmfx/wasmfxtime.git
cd wasmfxtime
git submodule update --init
  1. Build in debug mode:
cargo build

As a result, a debug build of the wasmtime executable will be created at target/debug/wasmtime.

Analogously, to build in release mode run cargo build --release, which places the wasmtime artifact in target/release/.

Running programs

The wasmtime executable can compile and run WebAssembly modules in the usual way. However, if a module contains WasmFX instructions, then it is necessary to enable additional features, e.g.

wasmtime -W=exceptions,function-references,stack-switching my_module.wat

The first two features are prerequisite features, i.e. the exceptions feature is required to support WebAssembly tags and the function-references feature is required to support typed references. The stack-switching feature enables support for the stack switching (viz. WasmFX) instruction set.

To run an arbitrary function exported as foo by the module type

wasmtime -W=exceptions,function-references,stack-switching --invoke=foo my_module.wat

Example program

The following module implements a generator and consumer using stack switching.

(module
  (type $ft (func))
  (type $ct (cont $ft))

  ;; Tag used by generator, the i32 payload corresponds to the generated values
  (tag $yield (param i32))

  ;; Printing function for unsigned integers.
  ;; This function is unrelated to stack switching.
  (func $println_u32 (param $value i32)
    ;; See examples/generator.wat for actual implementation
  )


  ;; Simple generator yielding values from 100 down to 1
  (func $generator
    (local $i i32)
    (local.set $i (i32.const 100))
    (loop $l
      ;; Suspend generator, yield current value of $i to consumer
      (suspend $yield (local.get $i))
      ;; Decrement $i and exit loop once $i reaches 0
      (local.tee $i (i32.sub (local.get $i) (i32.const 1)))
      (br_if $l)
    )
  )
  (elem declare func $generator)

  (func $consumer
    (local $c (ref $ct))
    ;; Create continuation executing function $generator
    (local.set $c (cont.new $ct (ref.func $generator)))

    (loop $loop
      (block $on_yield (result i32 (ref $ct))
        ;; Resume continuation $c
        (resume $ct (on $yield $on_yield) (local.get $c))
        ;; Generator returned: no more data
        (return)
      )
      ;; Generator suspend, stack contains [i32 (ref $ct)]
      (local.set $c)
      ;; Stack now contains the i32 value yielded by generator
      (call $println_u32)

      (br $loop)
    )
  )

  (func $start (export "_start")
    (call $consumer)
  )
)

See examples/generator.wat for the full version of the file, including the definition of $println_u32.

Running the full version with

wasmtime -W=exceptions,function-references,stack-switching generator.wat

then prints the numbers 100 down to 1 in the terminal.

Current limitations

The implementation of the WasmFX proposal is currently limited in a few ways:

  • The only supported platform is x64 Linux.
  • Only a single module can be executed. In particular, providing additional modules using the --preload option of wasmtime can lead to unexpected behavior.

Original Wasmtime documentation below

wasmtime

A standalone runtime for WebAssembly

A Bytecode Alliance project

build status zulip chat supported rustc stable Documentation Status

Installation

The Wasmtime CLI can be installed on Linux and macOS (locally) with a small install script:

curl https://wasmtime.dev/install.sh -sSf | bash

This script installs into $WASMTIME_HOME (defaults to $HOME/.wasmtime), and executable is placed in $WASMTIME_HOME/bin.

Windows or otherwise interested users can download installers and binaries directly from the GitHub Releases page.

Example

If you've got the Rust compiler installed then you can take some Rust source code:

fn main() {
    println!("Hello, world!");
}

and compile/run it with:

$ rustup target add wasm32-wasip1
$ rustc hello.rs --target wasm32-wasip1
$ wasmtime hello.wasm
Hello, world!

(Note: make sure you installed Rust using the rustup method in the official instructions above, and do not have a copy of the Rust toolchain installed on your system in some other way as well (e.g. the system package manager). Otherwise, the rustup target add... command may not install the target for the correct copy of Rust.)

Features

  • Fast. Wasmtime is built on the optimizing Cranelift code generator to quickly generate high-quality machine code either at runtime or ahead-of-time. Wasmtime is optimized for efficient instantiation, low-overhead calls between the embedder and wasm, and scalability of concurrent instances.

  • Secure. Wasmtime's development is strongly focused on correctness and security. Building on top of Rust's runtime safety guarantees, each Wasmtime feature goes through careful review and consideration via an RFC process. Once features are designed and implemented, they undergo 24/7 fuzzing donated by Google's OSS Fuzz. As features stabilize they become part of a release, and when things go wrong we have a well-defined security policy in place to quickly mitigate and patch any issues. We follow best practices for defense-in-depth and integrate protections and mitigations for issues like Spectre. Finally, we're working to push the state-of-the-art by collaborating with academic researchers to formally verify critical parts of Wasmtime and Cranelift.

  • Configurable. Wasmtime uses sensible defaults, but can also be configured to provide more fine-grained control over things like CPU and memory consumption. Whether you want to run Wasmtime in a tiny environment or on massive servers with many concurrent instances, we've got you covered.

  • WASI. Wasmtime supports a rich set of APIs for interacting with the host environment through the WASI standard.

  • Standards Compliant. Wasmtime passes the official WebAssembly test suite, implements the official C API of wasm, and implements future proposals to WebAssembly as well. Wasmtime developers are intimately engaged with the WebAssembly standards process all along the way too.

Language Support

You can use Wasmtime from a variety of different languages through embeddings of the implementation.

Languages supported by the Bytecode Alliance:

Languages supported by the community:

Documentation

πŸ“š Read the Wasmtime guide here! πŸ“š

The wasmtime guide is the best starting point to learn about what Wasmtime can do for you or help answer your questions about Wasmtime. If you're curious in contributing to Wasmtime, it can also help you do that!


It's Wasmtime.

About

A fork of wasmtime (a fast and secure runtime for WebAssembly) supporting the WasmFX instruction set

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 68.8%
  • WebAssembly 23.7%
  • Common Lisp 6.3%
  • C 0.9%
  • JavaScript 0.1%
  • Shell 0.1%
  • Other 0.1%