wasi

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2023 License: Apache-2.0 Imports: 11 Imported by: 5

README

Build Go Reference Apache 2 License

WASI

The WebAssembly System Interface (WASI) is a set of host imports that allow WebAssembly modules to interact with the outside world (e.g. perform I/O, read clocks).

The WASI standard is under development. This repository provides a Go implementation of WASI preview 1 for Unix systems, and a command to run WebAssembly modules that use WASI host functions.

Motivation

WASI preview 1 was cut before getting a fully capable socket API, and WASI as a standard is still a moving target.

Some WebAssembly runtimes such as wasmer, wasmedge, and lunatic have taken the initiative to either extend WASI preview 1 or provide alternative solutions for capabilities that were missing from the core specification, enabling a wider range of applications to run as WebAssembly modules.

This package intends to bring those extensions to wazero, and more generally be a playground for experimentation with cutting-edge WASI features.

🔌 Sockets

This library provides all the socket capabilities specified in WASI preview 1, as well as a full support for a socket API which is ABI-compatible with the extensions implemented in wasmedge.

🔋 Experimentation

The library separates the implementation of WASI from the WebAssembly runtime host module, so that implementations of the provided WASI interface don't have to worry about ABI concerns. The design makes it easy to wrap, augment and keep up with the evolving WASI specification.

Performance

The provided implementation of WASI is a thin zero-allocation layer around OS system calls. Non-blocking I/O is fully supported, allowing WebAssembly modules with an embedded scheduler (e.g. the Go runtime, or Rust Tokio scheduler) to schedule goroutines / green threads while waiting for I/O.

Non-Goals

wasi-go does not aim to be a drop-in replacement for the wasi_snapshot_preview1 package that ships with the wazero runtime. For example, the wasi-go package does not build on Windows, nor does it allow customization of the file systems via a fs.FS.

Usage

As a Command

A wasirun command is provided for running WebAssembly modules that use WASI host imports. It bundles the WASI implementation from this repository with the wazero runtime.

$ go install github.com/stealthrocket/wasi-go/cmd/wasirun@latest

The wasirun command has many options for controlling the capabilities of the WebAssembly module, and for tracing and profiling execution. See wasirun --help for details.

As a Library

The package layout is as follows:

To run a WebAssembly module, it's also necessary to prepare clocks and "preopens" (files/directories that the WebAssembly module can access). To see how it all fits together, see the implementation of the wasirun command.

With Go

As the providers of a Go implementation of WASI, we're naturally interested in Go's support for WebAssembly and WASI, and are championing the efforts to make Go a first class citizen in the ecosystem (along with Rust and Zig).

Go v1.21 (scheduled for release in August 2023) has native support for WebAssembly and WASI:

$ GOOS=wasip1 GOARCH=wasm go build -o app.wasm app.go
$ wasirun app.wasm

To test this feature before release, use gotip in place of go.

This repository bundles a script that can be used to skip the go build step.

Contributing

Pull requests are welcome! Anything that is not a simple fix would probably benefit from being discussed in an issue first.

Remember to be respectful and open minded!

Documentation

Index

Constants

View Source
const SizeOfDirent = 24

SizeOfDirent is the size in bytes of directory entries when serialized to the output buffer of fd_readdir.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advice

type Advice uint8

Advice is file or memory access pattern advisory information.

const (
	// Normal indicates that the application has no advice to give on its
	// behavior with respect to the specified data.
	Normal Advice = iota

	// Sequential indicates that the application expects to access the
	// specified data sequentially from lower offsets to higher offsets.
	Sequential

	// Random indicates that the application expects to access the specified
	// data in a random order.
	Random

	// WillNeed indicates that the application expects to access the specified
	// data in the near future.
	WillNeed

	// DontNeed indicates that the application expects that it will not access
	// the specified data in the near future.
	DontNeed

	// NoReuse indicates that the application expects to access the specified
	// data once and then not reuse it thereafter.
	NoReuse
)

func (Advice) String

func (a Advice) String() string

type ClockID

type ClockID uint32

ClockID is an identifier for clocks.

const (
	// Realtime is the clock measuring real time. Time value zero corresponds
	// with 1970-01-01T00:00:00Z.
	Realtime ClockID = iota

	// Monotonic is the store-wide monotonic clock, which is defined as a clock
	// measuring real time, whose value cannot be adjusted and which cannot
	// have negative clock jumps. The epoch of this clock is undefined. The
	// absolute time value of this clock therefore has no meaning.
	Monotonic

	// ProcessCPUTimeID is the CPU-time clock associated with the current
	// process.
	ProcessCPUTimeID

	// ThreadCPUTimeID is the CPU-time clock associated with the current
	// thread.
	ThreadCPUTimeID
)

func (ClockID) String

func (c ClockID) String() string

type Device

type Device uint64

Device is an identifier for a device containing a file system.

It can be used in combination with INode to uniquely identify a file or directory in the filesystem.

type DirCookie

type DirCookie uint64

DirCookie is a reference to the offset of a directory entry.

The value 0 signifies the start of the directory.

type DirEntry

type DirEntry struct {
	// Next is the offset of the next directory entry stored in this directory.
	Next DirCookie

	// INode is the serial number of the file referred to by this directory
	// entry.
	INode INode

	// Type is the type of the file referred to by this directory entry.
	Type FileType

	// Name of the directory entry. When the directory entry is retrieved by a
	// call to FDReadDir, the name may point to an internal buffer and therefore
	// remains valid only until the next call to FDReadDir.
	Name []byte
}

DirEntry is a directory entry.

type DirNameLength

type DirNameLength uint32

DirNameLength is the type for the DirEntry.NameLength field.

type Errno

type Errno uint16

Errno are the error codes returned by functions.

Not all of these error codes are returned by the functions provided by this API; some are used in higher-level library layers, and others are provided merely for alignment with POSIX.

const (
	// ESUCCESS indicates that no error occurred (system call completed
	// successfully).
	ESUCCESS Errno = iota

	// E2BIG means an argument list is too long.
	E2BIG

	// EACCES means permission is denied.
	EACCES

	// EADDRINUSE means an address is already in use.
	EADDRINUSE

	// EADDRNOTAVAIL means an address is not available.
	EADDRNOTAVAIL

	// EAFNOSUPPORT means an address family is not supported by a protocol family.
	EAFNOSUPPORT

	// EAGAIN means the caller should try again.
	EAGAIN

	// EALREADY means a socket already connected
	EALREADY

	// EBADF means bad file number.
	EBADF

	// EBADMSG indicates that the caller is trying to read an unreadable message.
	EBADMSG

	// EBUSY means a device or resource busy.
	EBUSY

	// ECANCELED means an operation was canceled.
	ECANCELED

	// ECHILD means no child processes.
	ECHILD

	// ECONNABORTED means a connection was aborted.
	ECONNABORTED

	// ECONNREFUSED means connection was refused.
	ECONNREFUSED

	// ECONNRESET means a connection was reset by peer.
	ECONNRESET

	// EDEADLK indicates a deadlock condition.
	EDEADLK

	// EDESTADDRREQ means a destination address is required.
	EDESTADDRREQ

	// EDOM means a math argument is out of domain of func.
	EDOM

	// EDQUOT means a quota was exceeded.
	EDQUOT

	// EEXIST means a file exists.
	EEXIST

	// EFAULT means bad address.
	EFAULT

	// EFBIG indicates a file is too large.
	EFBIG

	// EHOSTUNREACH means a host is unreachable.
	EHOSTUNREACH

	// EIDRM means identifier removed.
	EIDRM

	// EILSEQ indicates an illegal byte sequence
	EILSEQ

	// EINPROGRESS means a connection is already in progress.
	EINPROGRESS

	// EINTR means a system call was interrupted.
	EINTR

	// EINVAL means an argument was invalid.
	EINVAL

	// EIO means an I/O error occurred.
	EIO

	// EISCONN means a socket is already connected.
	EISCONN

	// EISDIR means a file is a directory.
	EISDIR

	// ELOOP indicates that there are too many symbolic links.
	ELOOP

	// EMFILE indicates that there are too many open files
	EMFILE

	// EMLINK indicates that there are too many links
	EMLINK

	// EMSGSIZE means a message is too long.
	EMSGSIZE

	// EMULTIHOP means a multihop was attempted.
	EMULTIHOP

	// ENAMETOOLONG means a file name is too long.
	ENAMETOOLONG

	// ENETDOWN means a network interface is not configured.
	ENETDOWN

	// ENETRESET means a network was dropped connection on reset.
	ENETRESET

	// ENETUNREACH means a network is unreachable.
	ENETUNREACH

	// ENFILE means a file table overflow occurred.
	ENFILE

	// ENOBUFS means that no buffer space is available.
	ENOBUFS

	// ENODEV means no such device.
	ENODEV

	// ENOENT means no such file or directory.
	ENOENT
	// ENOEXEC means an exec format error.
	ENOEXEC

	// ENOLCK means that there are no record locks available
	ENOLCK

	// ENOLINK means the link has been severed.
	ENOLINK

	// ENOMEM means out of memory.
	ENOMEM

	// ENOMSG means that there is no message of desired type.
	ENOMSG

	// ENOPROTOOPT means a protocol is not available.
	ENOPROTOOPT

	// ENOSPC means that there is no space left on a device.
	ENOSPC

	// ENOSYS means not implemented.
	ENOSYS

	// ENOTCONN means a socket is not connected.
	ENOTCONN

	// ENOTDIR means a file is not a directory
	ENOTDIR

	// ENOTEMPTY means a directory is not empty.
	ENOTEMPTY

	// ENOTRECOVERABLE means state is not recoverable.
	ENOTRECOVERABLE

	// ENOTSOCK means a socket operation was attempted on a non-socket.
	ENOTSOCK

	// ENOTSUP means not supported.
	ENOTSUP

	// ENOTTY means not a typewriter.
	ENOTTY

	// ENXIO means no such device or address.
	ENXIO

	// EOVERFLOW means the value is too large for defined data type.
	EOVERFLOW

	// EOWNERDEAD means an owner died.
	EOWNERDEAD

	// EPERM means an operation is not permitted.
	EPERM

	// EPIPE means broken pipe.
	EPIPE

	// EPROTO means a protocol error ocurred.
	EPROTO

	// EPROTONOSUPPORT means a protocol is not supported.
	EPROTONOSUPPORT

	// EPROTOTYPE means that a protocol is the wrong type for socket.
	EPROTOTYPE

	// ERANGE means a math result is not representable.
	ERANGE

	// EROFS means a file system is read-only.
	EROFS

	// ESPIPE means a seek is illegal.
	ESPIPE

	// ESRCH means no such process.
	ESRCH

	// ESTALE means a file handle is stale.
	ESTALE

	// ETIMEDOUT means a connection timed out.
	ETIMEDOUT

	// ETXTBSY means text file busy.
	ETXTBSY

	// EXDEV means cross-device link.
	EXDEV

	// ENOTCAPABLE means capabilities are insufficient.
	ENOTCAPABLE
)

func (Errno) Error

func (e Errno) Error() string

func (Errno) Name

func (e Errno) Name() string

type Event

type Event struct {
	// UserData is the user-provided value that got attached to
	// Subscription.UserData.
	UserData UserData

	// Errno is an error that occurred while processing the subscription
	// request.
	Errno Errno

	// EventType is the type of event that occurred.
	EventType EventType

	// FDReadWrite is the contents of the event, if it is a FDReadEvent or
	// FDWriteEvent. ClockEvent events ignore this field.
	FDReadWrite EventFDReadWrite
}

Event is an event that occurred.

func (Event) FormatObject

func (e Event) FormatObject(w io.Writer, _ api.Memory, b []byte)

func (Event) LoadObject

func (e Event) LoadObject(_ api.Memory, b []byte) Event

func (Event) ObjectSize

func (e Event) ObjectSize() int

func (Event) StoreObject

func (e Event) StoreObject(_ api.Memory, b []byte)

type EventFDReadWrite

type EventFDReadWrite struct {
	// NBytes is the number of bytes available for reading or writing.
	NBytes FileSize

	// Flags is the state of the file descriptor.
	Flags EventFDReadWriteFlags
}

EventFDReadWrite is the contents of an event when event type is FDReadEvent or FDWriteEvent.

type EventFDReadWriteFlags

type EventFDReadWriteFlags uint16

EventFDReadWriteFlags is the state of the file descriptor subscribed to with FDReadEvent or FDWriteEvent.

const (
	// Hangup is a flag that indicates that the peer of this socket
	// has closed or disconnected.
	Hangup EventFDReadWriteFlags = 1 << iota
)

func (EventFDReadWriteFlags) Has

Has is true if the flag is set.

func (EventFDReadWriteFlags) String

func (flags EventFDReadWriteFlags) String() string

type EventType

type EventType uint8

EventType is a type of a subscription to an event, or its occurrence.

const (
	// ClockEvent is an event type that indicates that the time value of clock
	// SubscriptionClock.ID has reached timestamp SubscriptionClock.Timeout.
	ClockEvent EventType = iota

	// FDReadEvent is an event type that indicates that the file descriptor
	// SubscriptionFDReadWrite.FD has data available for reading.
	FDReadEvent

	// FDWriteEvent is an event type that indicates that the file descriptor
	// SubscriptionFDReadWrite.FD has data available for writing.
	FDWriteEvent
)

func (EventType) String

func (e EventType) String() string

type ExitCode

type ExitCode uint32

ExitCode is the exit code generated by a process when exiting.

type FD

type FD int32

FD is a file descriptor handle.

type FDFlags

type FDFlags uint16

FDFlags are file descriptor flags.

const (
	// Append indicates append mode; data written to the file is always
	// appended to the file's end.
	Append FDFlags = 1 << iota

	// DSync means write according to synchronized I/O data integrity
	// completion.
	//
	// Only the data stored in the file is synchronized.
	DSync

	// NonBlock indicates non-blocking mode.
	NonBlock

	// RSync indicates synchronized read I/O operations.
	RSync

	// Sync means write according to synchronized I/O data integrity
	// completion.
	//
	// In addition to synchronizing the data stored in the file, the
	// implementation may also synchronously update the file's metadata.
	Sync
)

func (FDFlags) Has

func (flags FDFlags) Has(f FDFlags) bool

Has is true if the flag is set.

func (FDFlags) String

func (flags FDFlags) String() (s string)

type FDStat

type FDStat struct {
	// FileType is the file type.
	FileType FileType

	// Flags are the file descriptor flags.
	Flags FDFlags

	// RightsBase are rights that apply to this file descriptor.
	RightsBase Rights

	// RightsInheriting are the maximum set of rights that may be installed on
	// new file descriptors that are created through this file descriptor,
	// e.g. through PathOpen.
	RightsInheriting Rights
}

FDStat is file descriptor attributes.

func (FDStat) FormatObject

func (f FDStat) FormatObject(w io.Writer, _ api.Memory, b []byte)

func (FDStat) LoadObject

func (f FDStat) LoadObject(_ api.Memory, b []byte) FDStat

func (FDStat) ObjectSize

func (f FDStat) ObjectSize() int

func (FDStat) StoreObject

func (f FDStat) StoreObject(_ api.Memory, b []byte)

type FSTFlags

type FSTFlags uint16

FSTFlags indicate which file time attributes to adjust.

const (
	// AccessTime means adjust the last data access timestamp to the value
	// stored in FileStat.AccessTime.
	AccessTime FSTFlags = 1 << iota

	// AccessTimeNow means adjust the last data access timestamp to the time
	// of clock Realtime.
	AccessTimeNow

	// ModifyTime means adjust the last data modification timestamp to the value
	// stored in FileStat.ModifyTime.
	ModifyTime

	// ModifyTimeNow means adjust the last data modification timestamp to the time
	// of clock Realtime.
	ModifyTimeNow
)

func (FSTFlags) Has

func (flags FSTFlags) Has(f FSTFlags) bool

Has is true if the flag is set.

func (FSTFlags) String

func (flags FSTFlags) String() (s string)

type FileDelta

type FileDelta int64

FileDelta is a relative offset within a file.

type FileSize

type FileSize uint64

FileSize is a non-negative file size or length of a region within a file.

type FileStat

type FileStat struct {
	// Device is the ID of the device containing the file.
	Device Device

	// INode is the file serial number.
	INode INode

	// FileType is the file type.
	FileType FileType

	// NLink is the number of hard links to the file.
	NLink LinkCount

	// Size is the size. For regular files, it's the file size in bytes. For
	// symbolic links, the length in bytes of the pathname contained in the
	// symbolic link.
	Size FileSize

	// AccessTime is the last data access timestamp.
	AccessTime Timestamp

	// ModifyTime is the last data modification timestamp.
	ModifyTime Timestamp

	// ChangeTime is the last file status change timestamp.
	ChangeTime Timestamp
}

FileStat are file attributes.

func (FileStat) FormatObject

func (f FileStat) FormatObject(w io.Writer, _ api.Memory, b []byte)

func (FileStat) LoadObject

func (f FileStat) LoadObject(_ api.Memory, b []byte) FileStat

func (FileStat) ObjectSize

func (f FileStat) ObjectSize() int

func (FileStat) StoreObject

func (f FileStat) StoreObject(_ api.Memory, b []byte)

type FileType

type FileType uint8

FileType is the type of a file descriptor or file.

const (
	// UnknownType indicates that the type of the file descriptor or file is
	// unknown or is different from any of the other types specified.
	UnknownType FileType = iota

	// BlockDeviceType is indicates that the file descriptor or file refers to
	// a block device inode.
	BlockDeviceType

	// CharacterDeviceType indicates that the file descriptor or file refers to
	// a character device inode.
	CharacterDeviceType

	// DirectoryType indicates that the file descriptor or file refers to a
	// directory inode.
	DirectoryType

	// RegularFileType indicates that the file descriptor or file refers to a
	// regular file inode.
	RegularFileType

	// SocketDGramType indicates that the file descriptor or file refers to a
	// datagram socket.
	SocketDGramType

	// SocketStreamType indicates that the file descriptor or file refers to a
	// byte-stream socket.
	SocketStreamType

	// SymbolicLinkType indicates that the file refers to a symbolic link
	// inode.
	SymbolicLinkType
)

func (FileType) String

func (f FileType) String() string

type INode

type INode uint64

INode is a file serial number that is unique within its file system.

type IOVec

type IOVec []byte

IOVec is a slice of bytes.

func (IOVec) FormatObject

func (arg IOVec) FormatObject(w io.Writer, memory api.Memory, object []byte)

func (IOVec) LoadObject

func (arg IOVec) LoadObject(memory api.Memory, object []byte) IOVec

func (IOVec) ObjectSize

func (arg IOVec) ObjectSize() int

func (IOVec) StoreObject

func (arg IOVec) StoreObject(memory api.Memory, object []byte)

type Inet4Address

type Inet4Address struct {
	Port int
	Addr [4]byte
}

func (*Inet4Address) Network

func (a *Inet4Address) Network() string

func (*Inet4Address) String

func (a *Inet4Address) String() string

type Inet6Address

type Inet6Address struct {
	Port int
	Addr [16]byte
}

func (*Inet6Address) Network

func (a *Inet6Address) Network() string

func (*Inet6Address) String

func (a *Inet6Address) String() string

type LinkCount

type LinkCount uint64

LinkCount is the number of hard links to an INode.

type LookupFlags

type LookupFlags uint32

LookupFlags determine the method of how paths are resolved.

const (
	// SymlinkFollow means that as long as the resolved path corresponds to a
	// symbolic link, it is expanded.
	SymlinkFollow LookupFlags = 1 << iota
)

func (LookupFlags) Has

func (flags LookupFlags) Has(f LookupFlags) bool

Has is true if the flag is set.

func (LookupFlags) String

func (flags LookupFlags) String() string

type OpenFlags

type OpenFlags uint16

OpenFlags are flags used by PathOpen.

const (
	// OpenCreate means create a file if it does not exist.
	OpenCreate OpenFlags = 1 << iota

	// OpenDirectory means fail if the path is not a directory.
	OpenDirectory

	// OpenExclusive means fail if the file already exists.
	OpenExclusive

	// OpenTruncate means truncate file to size 0.
	OpenTruncate
)

func (OpenFlags) Has

func (flags OpenFlags) Has(f OpenFlags) bool

Has is true if the flag is set.

func (OpenFlags) String

func (flags OpenFlags) String() (s string)

type Port

type Port uint32

Port is a port.

type PreOpenType

type PreOpenType uint8

PreOpenType are identifiers for pre-opened capabilities.

const (
	// PreOpenDir is a pre-opened directory.
	PreOpenDir PreOpenType = iota
)

func (PreOpenType) String

func (p PreOpenType) String() string

type PreStat

type PreStat struct {
	// Type is the type of pre-open.
	Type PreOpenType

	// PreStatDir is directory information when type is PreOpenDir.
	PreStatDir PreStatDir
}

PreStat is information about a pre-opened capability.

func (PreStat) FormatObject

func (p PreStat) FormatObject(w io.Writer, _ api.Memory, b []byte)

func (PreStat) LoadObject

func (p PreStat) LoadObject(_ api.Memory, b []byte) PreStat

func (PreStat) ObjectSize

func (p PreStat) ObjectSize() int

func (PreStat) StoreObject

func (p PreStat) StoreObject(_ api.Memory, b []byte)

type PreStatDir

type PreStatDir struct {
	// NameLength is the length of the directory name for use with
	// FDPreStatDirName.
	NameLength Size
}

PreStatDir is the contents of a PreStat when type is PreOpenDir.

type Protocol

type Protocol int32

Protocol is a socket protocol.

const (
	IPProtocol Protocol = iota
	TCPProtocol
	UDPProtocol
)

func (Protocol) String

func (p Protocol) String() string

type ProtocolFamily

type ProtocolFamily int32

ProtocolFamily is a socket protocol family.

const (
	Inet ProtocolFamily
	Inet6
)

func (ProtocolFamily) String

func (pf ProtocolFamily) String() string

type RIFlags

type RIFlags uint16

RIFlags are flags provided to SockRecv.

const (
	// RecvPeek indicates that SockRecv should return the message without
	// removing it from the socket's receive queue.
	RecvPeek RIFlags = 1 << iota

	// RecvWaitAll indicates that on byte-stream sockets, SockRecv should block
	// until the full amount of data can be returned.
	RecvWaitAll
)

func (RIFlags) Has

func (flags RIFlags) Has(f RIFlags) bool

Has is true if the flag is set.

func (RIFlags) String

func (flags RIFlags) String() (s string)

type ROFlags

type ROFlags uint16

ROFlags are flags returned by SockRecv.

const (
	// RecvDataTruncated indicates that message data has been truncated.
	RecvDataTruncated ROFlags = 1 << iota
)

func (ROFlags) Has

func (flags ROFlags) Has(f ROFlags) bool

Has is true if the flag is set.

func (ROFlags) String

func (flags ROFlags) String() string

type Rights

type Rights uint64

Rights are file descriptor rights, determining which actions may be performed.

const (
	// FDDataSyncRight is the right to invoke FDDataSync.
	//
	// If PathOpenRight is set, it includes the right to invoke PathOpen with
	// the DSync flag.
	FDDataSyncRight Rights = 1 << iota

	// FDReadRight is the right to invoke FDRead and SockRecv.
	//
	// If FDSeekRight is set, it includes the right to invoke FDPread.
	FDReadRight

	// FDSeekRight is the right to invoke FDSeek. This flag implies FDTellRight.
	FDSeekRight

	// FDStatSetFlagsRight is the right to invoke FDStatSetFlags.
	FDStatSetFlagsRight

	// FDSyncRight is the right to invoke FDSync.
	//
	// If PathOpenRight is set, it includes the right to invoke PathOpen with
	// flags RSync and DSync.
	FDSyncRight

	// FDTellRight is the right to invoke FDTell, and the right to invoke
	// FDSeek in such a way that the file offset remains unaltered (i.e.
	// WhenceCurrent with offset zero).
	FDTellRight

	// FDWriteRight is the right to invoke FDWrite and SockSend.
	//
	// If FDSeekRight is set, it includes the right to invoke FDPwrite.
	FDWriteRight

	// FDAdviseRight is the right to invoke FDAdvise.
	FDAdviseRight

	// FDAllocateRight is the right to invoke FDAllocate.
	FDAllocateRight

	// PathCreateDirectoryRight is the right to invoke PathCreateDirectory.
	PathCreateDirectoryRight

	// PathCreateFileRight is (along with PathOpenRight) the right to invoke
	// PathOpen with the OpenCreate flag.
	PathCreateFileRight

	// PathLinkSourceRight is the right to invoke PathLink with the file
	// descriptor as the source directory.
	PathLinkSourceRight

	// PathLinkTargetRight is the right to invoke PathLink with the file
	// descriptor as the target directory.
	PathLinkTargetRight

	// PathOpenRight is the right to invoke PathOpen.
	PathOpenRight

	// FDReadDirRight is the right to invoke FDReadDir.
	FDReadDirRight

	// PathReadLinkRight is the right to invoke PathReadLink.
	PathReadLinkRight

	// PathRenameSourceRight is the right to invoke PathRename with the file
	// descriptor as the source directory.
	PathRenameSourceRight

	// PathRenameTargetRight is the right to invoke PathRename with the file
	// descriptor as the target directory.
	PathRenameTargetRight

	// PathFileStatGetRight is the right to invoke PathFileStatGet.
	PathFileStatGetRight

	// PathFileStatSetSizeRight is the right to change a file's size.
	//
	// If PathOpenRight is set, it includes the right to invoke PathOpen with
	// the OpenTruncate flag.
	//
	// Note: there is no function named PathFileStatSetSize. This follows POSIX
	// design, which only has ftruncate and does not provide ftruncateat. While
	// such function would be desirable from the API design perspective, there
	// are virtually no use cases for it since no code written for POSIX
	// systems would use it. Moreover, implementing it would require multiple
	// syscalls, leading to inferior performance.
	PathFileStatSetSizeRight

	// PathFileStatSetTimesRight is the right to invoke PathFileStatSetTimes.
	PathFileStatSetTimesRight

	// FDFileStatGetRight is the right to invoke FDFileStatGet.
	FDFileStatGetRight

	// FDFileStatSetSizeRight is the right to invoke FDFileStatSetSize.
	FDFileStatSetSizeRight

	// FDFileStatSetTimesRight is the right to invoke FDFileStatSetTimes.
	FDFileStatSetTimesRight

	// PathSymlinkRight is the right to invoke PathSymlink.
	PathSymlinkRight

	// PathRemoveDirectoryRight is the right to invoke PathRemoveDirectory.
	PathRemoveDirectoryRight

	// PathUnlinkFileRight is the right to invoke PathUnlinkFile.
	PathUnlinkFileRight

	// PollFDReadWriteRight is the right to invoke PollOneOff.
	//
	// If FDReadWrite is set, it includes the right to invoke PollOneOff with a
	// FDReadEvent subscription. If FDWriteWrite is set, it includes the right
	// to invoke PollOneOff with a FDWriteEvent subscription.
	PollFDReadWriteRight

	// SockShutdownRight is the right to invoke SockShutdown
	SockShutdownRight

	// SockAccessRight is the right to invoke SockAccept
	SockAcceptRight

	// AllRights is the set of all available rights
	AllRights Rights = (1 << 30) - 1

	// ReadRights are rights related to reads.
	ReadRights Rights = FDReadRight | FDReadDirRight

	// WriteRights are rights related to writes.
	WriteRights Rights = FDWriteRight | FDAllocateRight | PathFileStatSetSizeRight | FDDataSyncRight

	// FileRights are rights related to files.
	FileRights Rights = syncRights | seekRights | fileStatRights | FDReadRight | FDStatSetFlagsRight | FDWriteRight | FDAdviseRight | FDAllocateRight | PollFDReadWriteRight

	// DirectoryRights are rights related to directories.
	// See https://github.com/WebAssembly/wasi-testsuite/blob/1b1d4a5/tests/rust/src/bin/directory_seek.rs
	DirectoryRights Rights = pathRights | syncRights | fileStatRights | FDStatSetFlagsRight | FDReadDirRight

	// TTYRights are rights related to terminals.
	// See https://github.com/WebAssembly/wasi-libc/blob/a6f871343/libc-bottom-half/sources/isatty.c
	TTYRights = FileRights &^ seekRights

	// SockListenRights are rights for listener sockets.
	SockListenRights = SockAcceptRight | PollFDReadWriteRight | FDFileStatGetRight | FDStatSetFlagsRight

	// SockConnectionRights are rights for connection sockets.
	SockConnectionRights = FDReadRight | FDWriteRight | PollFDReadWriteRight | SockShutdownRight | FDFileStatGetRight | FDStatSetFlagsRight
)

func (Rights) Has

func (flags Rights) Has(f Rights) bool

Has is true if the flag is set. If multiple flags are specified, Has returns true if all flags are set.

func (Rights) HasAny

func (flags Rights) HasAny(f Rights) bool

HasAny is true if any flag in a set of flags is set.

func (Rights) String

func (flags Rights) String() (s string)

type SDFlags

type SDFlags uint16

SDFlags are flags provided to SockShutdown which indicate which channels on a socket to shut down.

const (
	// ShutdownRD disables further receive operations.
	ShutdownRD SDFlags = 1 << iota

	// ShutdownWR disables further send operations.
	ShutdownWR
)

func (SDFlags) Has

func (flags SDFlags) Has(f SDFlags) bool

Has is true if the flag is set.

func (SDFlags) String

func (flags SDFlags) String() (s string)

type SIFlags

type SIFlags uint16

SIFlags are flags provided to SockSend.

As there are currently no flags defined, it must be set to zero.

func (SIFlags) Has

func (flags SIFlags) Has(f SIFlags) bool

Has is true if the flag is set.

func (SIFlags) String

func (flags SIFlags) String() string

type Signal

type Signal uint8

Signal is a signal condition.

const (
	// SIGNONE means no signal. Note that POSIX has special semantics for
	// kill(pid, 0), so this value is reserved.
	SIGNONE Signal = iota

	// SIGHUP means hangup. Action: Terminates the process.
	SIGHUP

	// SIGINT is the terminate interrupt signal. Action: Terminates the
	// process.
	SIGINT

	// SIGQUIT is the terminal quit signal. Action: Terminates the process.
	SIGQUIT

	// SIGILL means illegal instruction. Action: Terminates the process.
	SIGILL

	// SIGTRAP is the trace/breakpoint trap. Action: Terminates the process.
	SIGTRAP

	// SIGABRT is the process abort signal. Action: Terminates the process.
	SIGABRT

	// SIGBUS indicates access to an undefined portion of a memory object.
	// Action: Terminates the process.
	SIGBUS

	// SIGFPE indicates an erroneous arithmetic operation. Action: Terminates
	// the process.
	SIGFPE

	// SIGKILL means kill. Action: Terminates the process.
	SIGKILL

	// SIGUSR1 is the user-defined signal 1. Action: Terminates the process.
	SIGUSR1

	// SIGSEGV indicates an invalid memory reference. Action: Terminates the
	// process.
	SIGSEGV

	// SIGUSR2 is the user-defined signal 1. Action: Terminates the process.
	SIGUSR2

	// SIGPIPE indicates a write on a pipe with no one to read it.
	// Action: Ignored.
	SIGPIPE

	// SIGALRM indicates an alarm clock. Action: Terminates the process.
	SIGALRM

	// SIGTERM is the termination signal. Action: Terminates the process.
	SIGTERM

	// SIGCHLD indicates that a child process terminated, stopped, or
	// continued. Action: Ignored.
	SIGCHLD

	// SIGCONT indicates that execution should continue, if stopped.
	// Action: Continues executing, if stopped.
	SIGCONT

	// SIGSTOP means stop executing. Action: Stops executing.
	SIGSTOP

	// SIGTSTP is the terminal stop signal. Action: Stops executing.
	SIGTSTP

	// SIGTTIN indicates that a background process is attempting read.
	// Action: Stops executing.
	SIGTTIN

	// SIGTTOU indicates that a background process is attempting write.
	// Action: Stops executing.
	SIGTTOU

	// SIGURG indicates that high bandwidth data is available at a socket.
	// Action: Ignored.
	SIGURG

	// SIGXCPU means CPU time limit exceeded. Action: Terminates the process.
	SIGXCPU

	// SIGXFSZ means file size limit exceeded. Action: Terminates the process.
	SIGXFSZ

	// SIGVTALRM means virtual timer expired. Action: Terminates the process.
	SIGVTALRM

	// SIGPROF means profiling timer expired. Action: Terminates the process.
	SIGPROF

	// SIGWINCH means window changed. Action: Ignored.
	SIGWINCH

	// SIGPOLL means I/O is possible. Action: Terminates the process.
	SIGPOLL

	// SIGPWR indicates power failure. Action: Terminates the process.
	SIGPWR

	// SIGSYS indicates a bad system call. Action: Terminates the process.
	SIGSYS
)

func (Signal) Name

func (s Signal) Name() string

func (Signal) String

func (s Signal) String() string

type Size

type Size uint32

Size represents a size.

type SocketAddress

type SocketAddress interface {
	Network() string
	String() string
	// contains filtered or unexported methods
}

SocketAddress is a socket address.

type SocketOption

type SocketOption int32

SocketOption is a socket option that can be queried or set.

const (
	ReuseAddress SocketOption = iota
	QuerySocketType
	QuerySocketError
	DontRoute
	Broadcast
	SendBufferSize
	RecvBufferSize
	KeepAlive
	OOBInline
	Linger
	RecvLowWatermark
	RecvTimeout
	SendTimeout
	QueryAcceptConnections
)

func (SocketOption) String

func (so SocketOption) String() string

type SocketOptionLevel

type SocketOptionLevel int32

SocketOptionLevel controls the level that a socket option is applied at or queried from.

const (
	SocketLevel SocketOptionLevel = iota
)

func (SocketOptionLevel) String

func (sl SocketOptionLevel) String() string

type SocketType

type SocketType int32

SocketType is a type of socket.

const (
	DatagramSocket SocketType
	StreamSocket
)

func (SocketType) String

func (st SocketType) String() string

type SocketsExtension

type SocketsExtension interface {
	// SockOpen opens a socket.
	//
	// Note: This is similar to socket in POSIX.
	SockOpen(ctx context.Context, family ProtocolFamily, socketType SocketType, protocol Protocol, rightsBase, rightsInheriting Rights) (FD, Errno)

	// SockBind binds a socket to an address.
	//
	// The implementation must not retain the socket address.
	//
	// Note: This is similar to bind in POSIX.
	SockBind(ctx context.Context, fd FD, addr SocketAddress) Errno

	// SockConnect connects a socket to an address.
	//
	// The implementation must not retain the socket address.
	//
	// Note: This is similar to connect in POSIX.
	SockConnect(ctx context.Context, fd FD, addr SocketAddress) Errno

	// SockListen allows the socket to accept connections with SockAccept.
	//
	// Note: This is similar to listen in POSIX.
	SockListen(ctx context.Context, fd FD, backlog int) Errno

	// SockSendTo sends a message on a socket.
	//
	// It's similar to SockSend, but accepts an additional SocketAddress.
	//
	// Note: This is similar to sendto in POSIX, though it also supports
	// writing the data from multiple buffers in the manner of writev.
	SockSendTo(ctx context.Context, fd FD, iovecs []IOVec, flags SIFlags, addr SocketAddress) (Size, Errno)

	// SockRecvFrom receives a message from a socket.
	//
	// It's similar to SockRecv, but returns an additional SocketAddress.
	//
	// Note: This is similar to recvfrom in POSIX, though it also supports reading
	// the data into multiple buffers in the manner of readv.
	SockRecvFrom(ctx context.Context, fd FD, iovecs []IOVec, flags RIFlags) (Size, ROFlags, SocketAddress, Errno)

	// SockGetOptInt gets a socket option.
	//
	// Note: This is similar to getsockopt in POSIX.
	SockGetOptInt(ctx context.Context, fd FD, level SocketOptionLevel, option SocketOption) (int, Errno)

	// SockSetOptInt sets a socket option.
	//
	// Note: This is similar to setsockopt in POSIX.
	SockSetOptInt(ctx context.Context, fd FD, level SocketOptionLevel, option SocketOption, value int) Errno

	// SockLocalAddress gets the local address of the socket.
	//
	// The returned address is only valid until the next call on this
	// interface. Assume that any method may invalidate the address.
	//
	// Note: This is similar to getsockname in POSIX.
	SockLocalAddress(ctx context.Context, fd FD) (SocketAddress, Errno)

	// SockPeerAddress gets the address of the peer when the socket is a
	// connection.
	//
	// The returned address is only valid until the next call on this
	// interface. Assume that any method may invalidate the address.
	//
	// Note: This is similar to getpeername in POSIX.
	SockPeerAddress(ctx context.Context, fd FD) (SocketAddress, Errno)
}

SocketsExtension is a sockets extension for WASI preview 1.

type Subscription

type Subscription struct {
	// UserData is a user-provided value that is attached to the subscription
	// in the implementation and returned through Event.UserData.
	UserData UserData

	// EventType is the type of the event to subscribe to.
	EventType EventType
	// contains filtered or unexported fields
}

Subscription is a subscription to an event.

func MakeSubscriptionClock

func MakeSubscriptionClock(userData UserData, c SubscriptionClock) Subscription

MakeSubscriptionClock makes a Subscription for ClockEvent events.

func MakeSubscriptionFDReadWrite

func MakeSubscriptionFDReadWrite(userData UserData, eventType EventType, fdrw SubscriptionFDReadWrite) Subscription

MakeSubscriptionFDReadWrite makes a Subscription for FDReadEvent or FDWriteEvent events.

func (Subscription) FormatObject

func (s Subscription) FormatObject(w io.Writer, m api.Memory, b []byte)

func (*Subscription) GetClock

func (s *Subscription) GetClock() SubscriptionClock

GetClock gets the embedded SubscriptionClock.

func (*Subscription) GetFDReadWrite

func (s *Subscription) GetFDReadWrite() SubscriptionFDReadWrite

GetFDReadWrite gets the embedded SubscriptionFDReadWrite.

func (Subscription) LoadObject

func (s Subscription) LoadObject(_ api.Memory, b []byte) Subscription

func (Subscription) ObjectSize

func (s Subscription) ObjectSize() int

func (*Subscription) SetClock

func (s *Subscription) SetClock(c SubscriptionClock)

SetClock sets the subscription variant to a SubscriptionClock.

func (*Subscription) SetFDReadWrite

func (s *Subscription) SetFDReadWrite(fdrw SubscriptionFDReadWrite)

SetFDReadWrite sets the subscription variant to a SubscriptionFDReadWrite.

func (Subscription) StoreObject

func (s Subscription) StoreObject(_ api.Memory, b []byte)

type SubscriptionClock

type SubscriptionClock struct {
	// ID is the clock against which to compare the timestamp.
	ID ClockID

	// Timeout is the absolute or relative timestamp.
	Timeout Timestamp

	// Precision is the amount of time that the implementation may wait
	// additionally to coalesce with other events.
	Precision Timestamp

	// Flags specify whether the timeout is absolute or relative.
	Flags SubscriptionClockFlags
}

SubscriptionClock is the contents of a subscription when event type is ClockEvent.

func (SubscriptionClock) Format

func (c SubscriptionClock) Format(w io.Writer)

type SubscriptionClockFlags

type SubscriptionClockFlags uint16

SubscriptionClockFlags are flags determining how to interpret the timestamp provided in SubscriptionClock.Timeout.

const (
	// Abstime is a flag indicating that the timestamp provided in
	// SubscriptionClock.Timeout is an absolute timestamp of clock
	// SubscriptionClock.ID. If unset, treat the timestamp provided in
	// SubscriptionClock.Timeout as relative to the current time value of clock
	// SubscriptionClock.ID.
	Abstime SubscriptionClockFlags = 1 << iota
)

func (SubscriptionClockFlags) Has

Has is true if the flag is set.

func (SubscriptionClockFlags) String

func (flags SubscriptionClockFlags) String() string

type SubscriptionFDReadWrite

type SubscriptionFDReadWrite struct {
	// FD is the file descriptor to wait on.
	FD FD
}

SubscriptionFDReadWrite is the contents of a subscription when event type is FDReadEvent or FDWriteEvent.

func (SubscriptionFDReadWrite) Format

func (c SubscriptionFDReadWrite) Format(w io.Writer)

type System

type System interface {
	// Preopen registers an open directory or socket as a "preopen", granting
	// access to the WASM module.
	Preopen(hostfd int, path string, fdstat FDStat) FD

	// ArgsSizesGet reads command-line argument data sizes.
	//
	// The implementation should return the number of args, and the number of
	// bytes required to hold the strings (including terminating null bytes).
	ArgsSizesGet(ctx context.Context) (argCount int, stringBytes int, errno Errno)

	// ArgsGet reads command-line argument data.
	ArgsGet(ctx context.Context) ([]string, Errno)

	// EnvironSizesGet reads environment variable data sizes.
	//
	// The implementation should return the number of env variables, and the
	// number of bytes required to hold the strings (including terminating
	// null bytes).
	EnvironSizesGet(ctx context.Context) (argCount int, stringBytes int, errno Errno)

	// EnvironGet reads environment variable data.
	//
	// Key/value pairs are expected to be joined with an '=' char.
	EnvironGet(ctx context.Context) ([]string, Errno)

	// ClockResGet returns the resolution of a clock.
	//
	// The function accepts the clock ID for which to return the resolution.
	//
	// Implementations are required to provide a non-zero value for supported
	// clocks. For unsupported clocks, EINVAL is returned.
	//
	// Note: This is similar to clock_getres in POSIX.
	ClockResGet(ctx context.Context, id ClockID) (Timestamp, Errno)

	// ClockTimeGet returns the time value of a clock.
	//
	// The function accepts the clock ID for which to return the time. It
	// also accepts a precision which represents the maximum lag (exclusive)
	// that the returned time value may have, compared to its actual value.
	//
	// Note: This is similar to clock_gettime in POSIX.
	ClockTimeGet(ctx context.Context, id ClockID, precision Timestamp) (Timestamp, Errno)

	// FDAdvise provides file advisory information on a file descriptor
	//
	// Note: This is similar to posix_fadvise in POSIX.
	FDAdvise(ctx context.Context, fd FD, offset FileSize, length FileSize, advice Advice) Errno

	// FDAllocate forces the allocation of space in a file.
	//
	// Note: This is similar to posix_fallocate in POSIX.
	FDAllocate(ctx context.Context, fd FD, offset FileSize, length FileSize) Errno

	// FDClose closes a file descriptor.
	//
	// Note: This is similar to close in POSIX.
	FDClose(ctx context.Context, fd FD) Errno

	// FDDataSync synchronizes the data of a file to disk.
	//
	// Note: This is similar to fdatasync in POSIX.
	FDDataSync(ctx context.Context, fd FD) Errno

	// FDStatGet gets the attributes of a file descriptor.
	//
	// Note: This returns similar flags to fcntl(fd, F_GETFL) in POSIX, as
	// well as additional fields.
	FDStatGet(ctx context.Context, fd FD) (FDStat, Errno)

	// FDStatSetFlags adjusts the flags associated with a file descriptor.
	//
	// Note: This is similar to fcntl(fd, F_SETFL, flags) in POSIX.
	FDStatSetFlags(ctx context.Context, fd FD, flags FDFlags) Errno

	// FDStatSetRights adjusts the rights associated with a file descriptor.
	//
	// This can only be used to remove rights, and returns ENOTCAPABLE if
	// called in a way that would attempt to add rights.
	FDStatSetRights(ctx context.Context, fd FD, rightsBase, rightsInheriting Rights) Errno

	// FDFileStatGet returns the attributes of an open file.
	FDFileStatGet(ctx context.Context, fd FD) (FileStat, Errno)

	// FDFileStatSetSize adjusts the size of an open file.
	//
	// If this increases the file's size, the extra bytes are filled with
	// zeros.
	//
	// Note: This is similar to ftruncate in POSIX.
	FDFileStatSetSize(ctx context.Context, fd FD, size FileSize) Errno

	// FDFileStatSetTimes adjusts the timestamps of an open file or directory.
	//
	// Note: This is similar to futimens in POSIX.
	FDFileStatSetTimes(ctx context.Context, fd FD, accessTime, modifyTime Timestamp, flags FSTFlags) Errno

	// FDPread reads from a file descriptor, without using and updating the
	// file descriptor's offset.
	//
	// On success, it returns the number of bytes read. On failure, it returns
	// an Errno.
	//
	// Note: This is similar to preadv in Linux (and other Unix-es).
	FDPread(ctx context.Context, fd FD, iovecs []IOVec, offset FileSize) (Size, Errno)

	// FDPreStatGet returns a description of the given pre-opened file
	// descriptor.
	FDPreStatGet(ctx context.Context, fd FD) (PreStat, Errno)

	// FDPreStatDirName returns a description of the given pre-opened file
	// descriptor.
	FDPreStatDirName(ctx context.Context, fd FD) (string, Errno)

	// FDPwrite writes from a file descriptor, without using and updating the
	// file descriptor's offset.
	//
	// On success, it returns the number of bytes read. On failure, it returns
	// an Errno.
	//
	// Note: This is similar to pwritev in Linux (and other Unix-es).
	//
	// Like Linux (and other Unix-es), any calls of pwrite (and other functions
	// to read or write) for a regular file by other threads in the WASI
	// process should not be interleaved while pwrite is executed.
	FDPwrite(ctx context.Context, fd FD, iovecs []IOVec, offset FileSize) (Size, Errno)

	// FDRead reads from a file descriptor.
	//
	// On success, it returns the number of bytes read. On failure, it returns
	// an Errno.
	//
	// Note: This is similar to readv in POSIX.
	FDRead(ctx context.Context, fd FD, iovecs []IOVec) (Size, Errno)

	// FDReadDir reads directory entries from a directory.
	//
	// The implementation must write entries to the provided entries buffer,
	// and return the number of entries written.
	//
	// The implementation must ensure that the entries fit into a buffer
	// with the specified size (bufferSizeBytes). It's ok if the final entry
	// only partially fits into such a buffer.
	FDReadDir(ctx context.Context, fd FD, entries []DirEntry, cookie DirCookie, bufferSizeBytes int) (int, Errno)

	// FDRenumber atomically replaces a file descriptor by renumbering another
	// file descriptor. Due to the strong focus on thread safety, this
	// environment does not provide a mechanism to duplicate or renumber a file
	// descriptor to an arbitrary number, like dup2(). This would be prone to
	// race conditions, as an actual file descriptor with the same number could
	// be allocated by a different thread at the same time. This function
	// provides a way to atomically renumber file descriptors, which would
	// disappear if dup2() were to be removed entirely.
	FDRenumber(ctx context.Context, from, to FD) Errno

	// FDSeek moves the offset of a file descriptor.
	//
	// On success, this returns the new offset of the file descriptor, relative
	// to the start of the file. On failure, it returns an Errno.
	//
	// Note: This is similar to lseek in POSIX.
	FDSeek(ctx context.Context, fd FD, offset FileDelta, whence Whence) (FileSize, Errno)

	// FDSync synchronizes the data and metadata of a file to disk.
	//
	// Note: This is similar to fsync in POSIX.
	FDSync(ctx context.Context, fd FD) Errno

	// FDTell returns the current offset of a file descriptor.
	//
	// Note: This is similar to lseek(fd, 0, SEEK_CUR) in POSIX.
	FDTell(ctx context.Context, fd FD) (FileSize, Errno)

	// FDWrite write to a file descriptor.
	//
	// Note: This is similar to writev in POSIX.
	//
	// Like POSIX, any calls of write (and other functions to read or write)
	// for a regular file by other threads in the WASI process should not be
	// interleaved while write is executed.
	FDWrite(ctx context.Context, fd FD, iovecs []IOVec) (Size, Errno)

	// PathCreateDirectory create a directory.
	//
	// Note: This is similar to mkdirat in POSIX.
	PathCreateDirectory(ctx context.Context, fd FD, path string) Errno

	// PathFileStatGet returns the attributes of a file or directory.
	//
	// Note: This is similar to stat in POSIX.
	PathFileStatGet(ctx context.Context, fd FD, lookupFlags LookupFlags, path string) (FileStat, Errno)

	// PathFileStatSetTimes adjusts the timestamps of a file or directory.
	//
	// Note: This is similar to utimensat in POSIX.
	PathFileStatSetTimes(ctx context.Context, fd FD, lookupFlags LookupFlags, path string, accessTime, modifyTime Timestamp, flags FSTFlags) Errno

	// PathLink creates a hard link.
	//
	// Note: This is similar to linkat in POSIX.
	PathLink(ctx context.Context, oldFD FD, oldFlags LookupFlags, oldPath string, newFD FD, newPath string) Errno

	// PathOpen opens a file or directory.
	//
	// The returned file descriptor is not guaranteed to be the lowest-numbered
	// file descriptor not currently open; it is randomized to prevent
	// applications from depending on making assumptions about indexes, since
	// this is error-prone in multi-threaded contexts. The returned file
	// descriptor is guaranteed to be less than 2**31.
	//
	// Note: This is similar to openat in POSIX.
	PathOpen(ctx context.Context, fd FD, dirFlags LookupFlags, path string, openFlags OpenFlags, rightsBase, rightsInheriting Rights, fdFlags FDFlags) (FD, Errno)

	// PathReadLink reads the contents of a symbolic link.
	//
	// The implementation must read the path into the specified buffer and then
	// return it. If the buffer is not large enough to hold the contents of the
	// symbolic link, the implementation must return ERANGE.
	//
	// Note: This is similar to readlinkat in POSIX.
	PathReadLink(ctx context.Context, fd FD, path string, buffer []byte) ([]byte, Errno)

	// PathRemoveDirectory removes a directory.
	//
	// If the directory is not empty, ENOTEMPTY is returned.
	//
	// Note: This is similar to unlinkat(fd, path, AT_REMOVEDIR) in POSIX.
	PathRemoveDirectory(ctx context.Context, fd FD, path string) Errno

	// PathRename renames a file or directory.
	//
	// Note: This is similar to renameat in POSIX.
	PathRename(ctx context.Context, fd FD, oldPath string, newFD FD, newPath string) Errno

	// PathSymlink creates a symbolic link.
	//
	// Note: This is similar to symlinkat in POSIX.
	PathSymlink(ctx context.Context, oldPath string, fd FD, newPath string) Errno

	// PathUnlinkFile unlinks a file.
	//
	// If the path refers to a directory, EISDIR is returned.
	//
	// Note: This is similar to unlinkat(fd, path, 0) in POSIX.
	PathUnlinkFile(ctx context.Context, fd FD, path string) Errno

	// PollOneOff concurrently polls for the occurrence of a set of events.
	//
	// If len(subscriptions) == 0, EINVAL is returned.
	//
	// The function writes events to the provided []Event buffer, expecting
	// len(events)>=len(subscriptions).
	PollOneOff(ctx context.Context, subscriptions []Subscription, events []Event) (int, Errno)

	// ProcExit terminates the process normally.
	//
	// An exit code of 0 indicates successful termination of the program.
	// The meanings of other values is dependent on the environment.
	ProcExit(ctx context.Context, exitCode ExitCode) Errno

	// ProcRaise sends a signal to the process of the calling thread.
	//
	// Note: This is similar to raise in POSIX.
	ProcRaise(ctx context.Context, signal Signal) Errno

	// SchedYield temporarily yields execution of the calling thread.
	//
	// Note: This is similar to sched_yield in POSIX.
	SchedYield(ctx context.Context) Errno

	// RandomGet write high-quality random data into a buffer.
	//
	// This function blocks when the implementation is unable to immediately
	// provide sufficient high-quality random data. This function may execute
	// slowly, so when large mounts of random data are required, it's
	// advisable to use this function to seed a pseudo-random number generator,
	// rather than to provide the random data directly.
	RandomGet(ctx context.Context, b []byte) Errno

	// SockAccept accepts a new incoming connection.
	//
	// Note: This is similar to accept in POSIX.
	SockAccept(ctx context.Context, fd FD, flags FDFlags) (FD, Errno)

	// SockRecv receives a message from a socket.
	//
	// On success, this returns the number of bytes read along with
	// output flags. On failure, this returns an Errno.
	//
	// Note: This is similar to recv in POSIX, though it also supports reading
	// the data into multiple buffers in the manner of readv.
	SockRecv(ctx context.Context, fd FD, iovecs []IOVec, flags RIFlags) (Size, ROFlags, Errno)

	// SockSend sends a message on a socket.
	//
	// On success, this returns the number of bytes written. On failure, this
	// returns an Errno.
	//
	// Note: This is similar to send in POSIX, though it also supports
	// writing the data from multiple buffers in the manner of writev.
	SockSend(ctx context.Context, fd FD, iovecs []IOVec, flags SIFlags) (Size, Errno)

	// SockShutdown shuts down a socket's send and/or receive channels.
	//
	// Note: This is similar to shutdown in POSIX.
	SockShutdown(ctx context.Context, fd FD, flags SDFlags) Errno

	// Close closes the System.
	Close(ctx context.Context) error

	// Register is a lower-level variant of Preopen that registers a file
	// descriptor.
	Register(hostfd int, fdstat FDStat) FD
}

System is the WebAssembly System Interface (WASI).

type Timestamp

type Timestamp uint64

Timestamp is a timestamp in nanoseconds.

func (Timestamp) Duration

func (t Timestamp) Duration() time.Duration

func (Timestamp) Format

func (t Timestamp) Format(w io.Writer)

func (Timestamp) String

func (t Timestamp) String() string

func (Timestamp) Time

func (t Timestamp) Time() time.Time

type Tracer

type Tracer struct {
	Writer io.Writer
	System
}

Tracer wraps a System to log calls.

func (*Tracer) ArgsGet

func (t *Tracer) ArgsGet(ctx context.Context) ([]string, Errno)

func (*Tracer) ArgsSizesGet

func (t *Tracer) ArgsSizesGet(ctx context.Context) (int, int, Errno)

func (*Tracer) ClockResGet

func (t *Tracer) ClockResGet(ctx context.Context, id ClockID) (Timestamp, Errno)

func (*Tracer) ClockTimeGet

func (t *Tracer) ClockTimeGet(ctx context.Context, id ClockID, precision Timestamp) (Timestamp, Errno)

func (*Tracer) Close

func (t *Tracer) Close(ctx context.Context) error

func (*Tracer) EnvironGet

func (t *Tracer) EnvironGet(ctx context.Context) ([]string, Errno)

func (*Tracer) EnvironSizesGet

func (t *Tracer) EnvironSizesGet(ctx context.Context) (int, int, Errno)

func (*Tracer) FDAdvise

func (t *Tracer) FDAdvise(ctx context.Context, fd FD, offset, length FileSize, advice Advice) Errno

func (*Tracer) FDAllocate

func (t *Tracer) FDAllocate(ctx context.Context, fd FD, offset, length FileSize) Errno

func (*Tracer) FDClose

func (t *Tracer) FDClose(ctx context.Context, fd FD) Errno

func (*Tracer) FDDataSync

func (t *Tracer) FDDataSync(ctx context.Context, fd FD) Errno

func (*Tracer) FDFileStatGet

func (t *Tracer) FDFileStatGet(ctx context.Context, fd FD) (FileStat, Errno)

func (*Tracer) FDFileStatSetSize

func (t *Tracer) FDFileStatSetSize(ctx context.Context, fd FD, size FileSize) Errno

func (*Tracer) FDFileStatSetTimes

func (t *Tracer) FDFileStatSetTimes(ctx context.Context, fd FD, accessTime, modifyTime Timestamp, flags FSTFlags) Errno

func (*Tracer) FDPreStatDirName

func (t *Tracer) FDPreStatDirName(ctx context.Context, fd FD) (string, Errno)

func (*Tracer) FDPreStatGet

func (t *Tracer) FDPreStatGet(ctx context.Context, fd FD) (PreStat, Errno)

func (*Tracer) FDPread

func (t *Tracer) FDPread(ctx context.Context, fd FD, iovecs []IOVec, offset FileSize) (Size, Errno)

func (*Tracer) FDPwrite

func (t *Tracer) FDPwrite(ctx context.Context, fd FD, iovecs []IOVec, offset FileSize) (Size, Errno)

func (*Tracer) FDRead

func (t *Tracer) FDRead(ctx context.Context, fd FD, iovecs []IOVec) (Size, Errno)

func (*Tracer) FDReadDir

func (t *Tracer) FDReadDir(ctx context.Context, fd FD, entries []DirEntry, cookie DirCookie, bufferSizeBytes int) (int, Errno)

func (*Tracer) FDRenumber

func (t *Tracer) FDRenumber(ctx context.Context, from, to FD) Errno

func (*Tracer) FDSeek

func (t *Tracer) FDSeek(ctx context.Context, fd FD, offset FileDelta, whence Whence) (FileSize, Errno)

func (*Tracer) FDStatGet

func (t *Tracer) FDStatGet(ctx context.Context, fd FD) (FDStat, Errno)

func (*Tracer) FDStatSetFlags

func (t *Tracer) FDStatSetFlags(ctx context.Context, fd FD, flags FDFlags) Errno

func (*Tracer) FDSync

func (t *Tracer) FDSync(ctx context.Context, fd FD) Errno

func (*Tracer) FDTell

func (t *Tracer) FDTell(ctx context.Context, fd FD) (FileSize, Errno)

func (*Tracer) FDWrite

func (t *Tracer) FDWrite(ctx context.Context, fd FD, iovecs []IOVec) (Size, Errno)

func (*Tracer) PathCreateDirectory

func (t *Tracer) PathCreateDirectory(ctx context.Context, fd FD, path string) Errno

func (*Tracer) PathFileStatGet

func (t *Tracer) PathFileStatGet(ctx context.Context, fd FD, lookupFlags LookupFlags, path string) (FileStat, Errno)

func (*Tracer) PathFileStatSetTimes

func (t *Tracer) PathFileStatSetTimes(ctx context.Context, fd FD, lookupFlags LookupFlags, path string, accessTime, modifyTime Timestamp, flags FSTFlags) Errno
func (t *Tracer) PathLink(ctx context.Context, oldFD FD, oldFlags LookupFlags, oldPath string, newFD FD, newPath string) Errno

func (*Tracer) PathOpen

func (t *Tracer) PathOpen(ctx context.Context, fd FD, dirFlags LookupFlags, path string, openFlags OpenFlags, rightsBase, rightsInheriting Rights, fdFlags FDFlags) (FD, Errno)
func (t *Tracer) PathReadLink(ctx context.Context, fd FD, path string, buffer []byte) ([]byte, Errno)

func (*Tracer) PathRemoveDirectory

func (t *Tracer) PathRemoveDirectory(ctx context.Context, fd FD, path string) Errno

func (*Tracer) PathRename

func (t *Tracer) PathRename(ctx context.Context, fd FD, oldPath string, newFD FD, newPath string) Errno
func (t *Tracer) PathSymlink(ctx context.Context, oldPath string, fd FD, newPath string) Errno

func (*Tracer) PathUnlinkFile

func (t *Tracer) PathUnlinkFile(ctx context.Context, fd FD, path string) Errno

func (*Tracer) PollOneOff

func (t *Tracer) PollOneOff(ctx context.Context, subscriptions []Subscription, events []Event) (int, Errno)

func (*Tracer) Preopen

func (t *Tracer) Preopen(hostfd int, path string, fdstat FDStat) FD

func (*Tracer) ProcExit

func (t *Tracer) ProcExit(ctx context.Context, exitCode ExitCode) Errno

func (*Tracer) ProcRaise

func (t *Tracer) ProcRaise(ctx context.Context, signal Signal) Errno

func (*Tracer) RandomGet

func (t *Tracer) RandomGet(ctx context.Context, b []byte) Errno

func (*Tracer) Register

func (t *Tracer) Register(hostfd int, fdstat FDStat) FD

func (*Tracer) SchedYield

func (t *Tracer) SchedYield(ctx context.Context) Errno

func (*Tracer) SockAccept

func (t *Tracer) SockAccept(ctx context.Context, fd FD, flags FDFlags) (FD, Errno)

func (*Tracer) SockBind

func (t *Tracer) SockBind(ctx context.Context, fd FD, addr SocketAddress) Errno

func (*Tracer) SockConnect

func (t *Tracer) SockConnect(ctx context.Context, fd FD, addr SocketAddress) Errno

func (*Tracer) SockGetOptInt

func (t *Tracer) SockGetOptInt(ctx context.Context, fd FD, level SocketOptionLevel, option SocketOption) (int, Errno)

func (*Tracer) SockListen

func (t *Tracer) SockListen(ctx context.Context, fd FD, backlog int) Errno

func (*Tracer) SockLocalAddress

func (t *Tracer) SockLocalAddress(ctx context.Context, fd FD) (SocketAddress, Errno)

func (*Tracer) SockOpen

func (t *Tracer) SockOpen(ctx context.Context, pf ProtocolFamily, socketType SocketType, protocol Protocol, rightsBase, rightsInheriting Rights) (FD, Errno)

func (*Tracer) SockPeerAddress

func (t *Tracer) SockPeerAddress(ctx context.Context, fd FD) (SocketAddress, Errno)

func (*Tracer) SockRecv

func (t *Tracer) SockRecv(ctx context.Context, fd FD, iovecs []IOVec, iflags RIFlags) (Size, ROFlags, Errno)

func (*Tracer) SockRecvFrom

func (t *Tracer) SockRecvFrom(ctx context.Context, fd FD, iovecs []IOVec, iflags RIFlags) (Size, ROFlags, SocketAddress, Errno)

func (*Tracer) SockSend

func (t *Tracer) SockSend(ctx context.Context, fd FD, iovecs []IOVec, iflags SIFlags) (Size, Errno)

func (*Tracer) SockSendTo

func (t *Tracer) SockSendTo(ctx context.Context, fd FD, iovecs []IOVec, iflags SIFlags, addr SocketAddress) (Size, Errno)

func (*Tracer) SockSetOptInt

func (t *Tracer) SockSetOptInt(ctx context.Context, fd FD, level SocketOptionLevel, option SocketOption, value int) Errno

func (*Tracer) SockShutdown

func (t *Tracer) SockShutdown(ctx context.Context, fd FD, flags SDFlags) Errno

type UnixAddress

type UnixAddress struct {
	Name string
}

func (*UnixAddress) Network

func (a *UnixAddress) Network() string

func (*UnixAddress) String

func (a *UnixAddress) String() string

type UserData

type UserData uint64

UserData is a user-provided value that may be attached to objects that is retained when extracted from the implementation.

type Whence

type Whence uint8

Whence is the position relative to which to set the offset of the file descriptor.

const (
	// SeekStart seeks relative to the origin of the file.
	SeekStart Whence = iota

	// SeekCurrent seeks relative to current offset.
	SeekCurrent

	// SeekEnd seeks relative to end of the file.
	SeekEnd
)

func (Whence) String

func (w Whence) String() string

Directories

Path Synopsis
cmd
internal
systems

Jump to

Keyboard shortcuts

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