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 ¶
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 ¶
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.
var ErrNoExec = errors.New("cannot start a process in this container")
ErrNoExec is what Exec answers when the container's process cannot host another one (an executor without the engine's WASI host, or a process that has ended).
Functions ¶
func ExitCodeOf ¶ added in v0.30.1
ExitCodeOf bounds a guest's proc_exit code (a u32: os.Exit(-1) arrives as 4294967295) to a Docker status. 0..255 is kept; anything else is 1.
This deliberately diverges from wasmtime: its preview 1 proc_exit (crates/wasi/src/p1.rs l.2615-2625) fails with "exit with invalid exit status outside of [0..126)" for a status >= 126, and the CLI then exits 1. Docker is our compatibility target, and Docker statuses are 0..255 with meaning above 125 (126 not executable, 127 not found, 130 interrupted, 128+n signals): `wctr run IMG sh -c 'exit 127'` must report 127. Only a value no Docker status can hold (os.Exit(-1), 256 and above) is mapped to 1, which is what wasmtime reports for those too.
func LoadModule ¶ added in v0.2.0
LoadModule reads and checks the module a spec names: present (else ErrNotFound), a regular file with the wasm magic (else ErrInvalid).
Types ¶
type ExecSpec ¶ added in v0.20.0
type ExecSpec struct {
// Path is the module's absolute path in the container's root.
Path string
// Args is argv, Args[0] included; Env is "KEY=value" entries.
Args, Env []string
// Stdin, Stdout and Stderr default to empty / discard.
Stdin io.Reader
Stdout, Stderr io.Writer
// Terminal, when set, is the process's terminal (exec -t).
Terminal *wasi.Terminal
}
ExecSpec is a further process to start in a running container (`exec`): it runs on the container's trees, network and capabilities, in its process group (counted against its limits, killed with it).
type Execer ¶ added in v0.20.0
Execer is implemented by a Process that can start more processes in its container. Exec returns the new process and its pid in the container's group.
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 Mount ¶ added in v0.8.0
Mount is a tree (a volume) preopened at Path in the guest, read-only when ReadOnly.
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
// ProcExit reports that the guest ended with proc_exit(ProcCode), the
// raw u32; ExitCode is then bounded to 0..125 (see ExitCodeOf).
ProcExit bool
ProcCode uint32
// 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.
func GuestExit ¶ added in v0.30.1
GuestExit is the Result of a guest's proc_exit(code): ExitCode is the bounded Docker-compatible status (ExitCodeOf), ProcCode the raw u32 a WASIX parent still sees.
func (Result) ExitStatus ¶ added in v0.15.0
func (r Result) ExitStatus() wasi.ExitStatus
ExitStatus is how a parent process sees this end: killed or timed out as signal 9, a trap as signal 6, otherwise the exit code.
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
// Mounts are volumes, each preopened at its own path.
Mounts []Mount
// 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
// Net is the container's network endpoint (nil: no network). Only
// the engine's WASI host serves sockets.
Net netdriver.Endpoint
// Caps are capabilities granted to the process ("gpu", from run
// --gpu); host modules read them through the engine's WASI host.
Caps []string
// Terminal is the container's terminal (run -t), if any; the engine's
// WASI host reports it to the guest's processes.
Terminal *wasi.Terminal
// Processes bounds the processes the container may spawn (the
// engine's WASI host only; zero values are its defaults).
Processes wasi.GroupLimits
}
Spec is everything needed to run one container process.
type Stats ¶ added in v0.7.0
type Stats struct {
// MemoryBytes is the guest's linear memory now (it never shrinks);
// MemoryLimitBytes the most it may grow to.
MemoryBytes, MemoryLimitBytes int64
}
Stats is what an executor can measure of a running process.
type StatsReporter ¶ added in v0.7.0
type StatsReporter interface {
Stats() Stats
}
StatsReporter is implemented by processes that can report Stats.
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 "/". |