Documentation
¶
Overview ¶
Package wasi is a WASI preview 1 (wasi_snapshot_preview1) host written against a byte-addressed guest memory and the engine's rootfs.FS.
It implements every function Go's wasip1 port imports (runtime, syscall, internal/syscall/unix), with the layouts and errno values of the snapshot-01 specification (docs/REFERENCES.md). It knows nothing of a WebAssembly runtime: a host calls Proc.Call with the raw arguments and a Memory, so the same code serves the native executor (as a wazero host module) and the browser executor (from a worker, over shared memory).
Index ¶
Constants ¶
const ( EADDRINUSE = 3 EADDRNOTAVAIL = 4 EAFNOSUPPORT = 5 EALREADY = 7 ECONNABORTED = 13 ECONNREFUSED = 14 ECONNRESET = 15 EHOSTUNREACH = 23 EINPROGRESS = 26 EINTR = 27 EISCONN = 30 EMFILE = 33 EMSGSIZE = 35 ENETDOWN = 38 ENETUNREACH = 40 ENOBUFS = 42 ENOPROTOOPT = 50 ENOTCONN = 53 ENOTSOCK = 57 EPIPE = 64 EPROTOTYPE = 67 ETIMEDOUT = 73 EAI_NONAME = 84 EAI_SERVICE = 85 )
More errno values of wasi_snapshot_preview1 (enum order), and the getaddrinfo ones WasmEdge adds.
const ( ESUCCESS = 0 E2BIG = 1 EACCES = 2 EAGAIN = 6 EBADF = 8 EEXIST = 20 EFAULT = 21 EINVAL = 28 EIO = 29 EISDIR = 31 ELOOP = 32 ENAMETOOLONG = 37 ENOENT = 44 ENOSPC = 51 ENOSYS = 52 ENOTDIR = 54 ENOTEMPTY = 55 ENOTSUP = 58 EPERM = 63 EROFS = 69 ESPIPE = 70 EXDEV = 75 ENOTCAPABLE = 76 )
Errno values of wasi_snapshot_preview1 (enum order of the spec).
const ( I32 = 'i' I64 = 'I' )
Param types of a function's core-wasm signature.
const MaxFDs = 1024
MaxFDs bounds the descriptors a process may hold.
Variables ¶
var FuncIndex = func() map[string]int { m := make(map[string]int, len(Funcs)) for i, f := range Funcs { m[f.Name] = i } return m }()
FuncIndex maps a name to its index in Funcs.
var Funcs = []Func{ {"args_get", "ii", false}, {"args_sizes_get", "ii", false}, {"environ_get", "ii", false}, {"environ_sizes_get", "ii", false}, {"clock_res_get", "ii", false}, {"clock_time_get", "iIi", false}, {"fd_advise", "iIIi", false}, {"fd_allocate", "iII", false}, {"fd_close", "i", false}, {"fd_datasync", "i", false}, {"fd_fdstat_get", "ii", false}, {"fd_fdstat_set_flags", "ii", false}, {"fd_fdstat_set_rights", "iII", false}, {"fd_filestat_get", "ii", false}, {"fd_filestat_set_size", "iI", false}, {"fd_filestat_set_times", "iIIi", false}, {"fd_pread", "iiiIi", false}, {"fd_prestat_get", "ii", false}, {"fd_prestat_dir_name", "iii", false}, {"fd_pwrite", "iiiIi", false}, {"fd_read", "iiii", false}, {"fd_readdir", "iiiIi", false}, {"fd_renumber", "ii", false}, {"fd_seek", "iIii", false}, {"fd_sync", "i", false}, {"fd_tell", "ii", false}, {"fd_write", "iiii", false}, {"path_create_directory", "iii", false}, {"path_filestat_get", "iiiii", false}, {"path_filestat_set_times", "iiiiIIi", false}, {"path_link", "iiiiiii", false}, {"path_open", "iiiiiIIii", false}, {"path_readlink", "iiiiii", false}, {"path_remove_directory", "iii", false}, {"path_rename", "iiiiii", false}, {"path_symlink", "iiiii", false}, {"path_unlink_file", "iii", false}, {"poll_oneoff", "iiii", false}, {"proc_exit", "i", true}, {"proc_raise", "i", false}, {"sched_yield", "", false}, {"random_get", "ii", false}, {"sock_accept", "iii", false}, {"sock_recv", "iiiiii", false}, {"sock_send", "iiiii", false}, {"sock_shutdown", "ii", false}, {"sock_open", "iii", false}, {"sock_bind", "iii", false}, {"sock_listen", "ii", false}, {"sock_connect", "iii", false}, {"sock_recv_from", "iiiiiiii", false}, {"sock_send_to", "iiiiiii", false}, {"sock_getsockopt", "iiiii", false}, {"sock_setsockopt", "iiiii", false}, {"sock_getlocaladdr", "iii", false}, {"sock_getpeeraddr", "iii", false}, {"sock_getaddrinfo", "iiiiiiii", false}, }
Funcs lists the imports, in a fixed order a host may index by.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Args, Env []string
FS *rootfs.FS
// Mounts are further trees, each preopened under its own path after
// "/" (fd 4 onwards), as wasmtime's --dir host::guest does: a guest
// resolves an absolute path against the longest matching preopen.
Mounts []Mount
Stdin io.Reader
Stdout, Stderr io.Writer
// Now is the realtime clock (default time.Now).
Now func() time.Time
// Rand is the randomness source (default crypto/rand).
Rand io.Reader
// Net is the container's place on a network; nil means no network
// (sock_open fails with ENOTSUP).
Net netdriver.Endpoint
}
Config is a process's world.
type Func ¶
type Func struct {
Name string
Params string // one of I32/I64 per parameter
// NoResult is set for proc_exit; every other function returns an errno.
NoResult bool
}
Func describes one import.
type Memory ¶
Memory is the guest's linear memory. Read returns a slice valid until the next call on the Memory; both return false out of bounds.
type Mount ¶ added in v0.8.0
Mount is a tree preopened at Path; ReadOnly refuses every change made through it with EROFS.
type Proc ¶
type Proc struct {
// contains filtered or unexported fields
}
Proc is one guest process's WASI state.
type Result ¶
type Result struct {
Errno uint32
// Sleep asks the host to block the guest this long before returning
// (poll_oneoff on clocks). The host may cut it short on a kill.
Sleep time.Duration
// Wait, when set, asks the host to block until Wait is closed, Sleep
// (if not zero) has passed, or the process is killed, and then to
// return what Resume returns instead (which may ask to wait again).
// The call itself never blocks: sockets wait this way.
Wait <-chan struct{}
Resume func(m Memory) Result
// Exit is set by proc_exit, with Code.
Exit bool
Code uint32
}
Result is what a call returned.