runtime

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package runtime defines how the engine runs a container's module. The Executor interface carries no type of any WebAssembly runtime, so the native executor (runtime/wazero) and the browser executor that comes later implement the same contract.

Index

Constants

View Source
const (
	ExitTrap    = 134 // 128 + SIGABRT: the module trapped
	ExitKilled  = 137 // 128 + SIGKILL: killed or timed out
	ExitNoExec  = 126 // found but not runnable (not a valid module)
	ExitMissing = 127 // module not found
)

Exit codes the engine uses for ends that are not a proc_exit, following the shell and Docker conventions (128+SIGKILL for a kill).

Variables

View Source
var (
	ErrNotFound = errors.New("module not found")
	ErrInvalid  = errors.New("not a valid WebAssembly module")
)

Errors a Start may return; the exit code to record goes with each.

Functions

func LoadModule added in v0.2.0

func LoadModule(spec Spec) ([]byte, error)

LoadModule reads and checks the module a spec names: present (else ErrNotFound), a regular file with the wasm magic (else ErrInvalid).

Types

type Executor

type Executor interface {
	// Start validates and compiles the module, then runs it in the
	// background. A missing module wraps ErrNotFound, an invalid one
	// ErrInvalid.
	Start(ctx context.Context, spec Spec) (Process, error)
	// Close releases the executor's resources.
	Close(ctx context.Context) error
}

Executor starts processes.

type Process

type Process interface {
	// Wait blocks until the process ends.
	Wait() Result
	// Kill ends the process; Wait then reports Killed.
	Kill()
}

Process is a started run.

type Result

type Result struct {
	ExitCode int
	// TimedOut reports a wall-clock cancel.
	TimedOut bool
	// Killed reports a cancel through Process.Kill or the context.
	Killed bool
	// Error describes an abnormal end (a trap), empty on a normal exit.
	Error string
}

Result is how a process ended.

type Spec

type Spec struct {
	// ID names the process in errors and logs.
	ID string
	// FS is the container's root filesystem, preopened as "/".
	FS *rootfs.FS
	// Path is the module's absolute path inside FS.
	Path string
	// Args is argv, Args[0] included.
	Args []string
	// Env is "KEY=value" entries.
	Env []string
	// Stdin, Stdout and Stderr default to empty / discard.
	Stdin          io.Reader
	Stdout, Stderr io.Writer
	// MemoryLimitBytes bounds the module's linear memory (0 = executor
	// default). It is rounded down to whole 64 KiB pages.
	MemoryLimitBytes int64
	// Timeout cancels the run after this wall-clock time (0 = none).
	Timeout time.Duration
}

Spec is everything needed to run one container process.

Directories

Path Synopsis
Package browser is the Executor for GOOS=js: each container process runs in its own Web Worker (worker.js), its wasi_snapshot_preview1 imports served synchronously by the engine's WASI host (package wasi) in the worker that runs the engine, over SharedArrayBuffer and Atomics.wait.
Package browser is the Executor for GOOS=js: each container process runs in its own Web Worker (worker.js), its wasi_snapshot_preview1 imports served synchronously by the engine's WASI host (package wasi) in the worker that runs the engine, over SharedArrayBuffer and Atomics.wait.
Package wazero is the native Executor: it runs a container's wasip1 module with wazero (pure Go, no cgo), the container's rootfs mounted as the guest's "/".
Package wazero is the native Executor: it runs a container's wasip1 module with wazero (pure Go, no cgo), the container's rootfs mounted as the guest's "/".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL