sandbox

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PATH_MAX   = 4096
	UTIME_NOW  = unix.UTIME_NOW
	UTIME_OMIT = unix.UTIME_OMIT
)
View Source
const (
	EADDRNOTAVAIL   = unix.EADDRNOTAVAIL
	EAFNOSUPPORT    = unix.EAFNOSUPPORT
	EAGAIN          = unix.EAGAIN
	EBADF           = unix.EBADF
	ECONNABORTED    = unix.ECONNABORTED
	ECONNREFUSED    = unix.ECONNREFUSED
	ECONNRESET      = unix.ECONNRESET
	EEXIST          = unix.EEXIST
	EHOSTUNREACH    = unix.EHOSTUNREACH
	EINVAL          = unix.EINVAL
	EINTR           = unix.EINTR
	EINPROGRESS     = unix.EINPROGRESS
	EISCONN         = unix.EISCONN
	EISDIR          = unix.EISDIR
	ELOOP           = unix.ELOOP
	ENAMETOOLONG    = unix.ENAMETOOLONG
	ENETUNREACH     = unix.ENETUNREACH
	ENOENT          = unix.ENOENT
	ENOPROTOOPT     = unix.ENOPROTOOPT
	ENOSYS          = unix.ENOSYS
	ENOTCONN        = unix.ENOTCONN
	ENOTDIR         = unix.ENOTDIR
	ENOTEMPTY       = unix.ENOTEMPTY
	EOPNOTSUPP      = unix.EOPNOTSUPP
	EPERM           = unix.EPERM
	EPROTONOSUPPORT = unix.EPROTONOSUPPORT
	EPROTOTYPE      = unix.EPROTOTYPE
	EROFS           = unix.EROFS
	ETIMEDOUT       = unix.ETIMEDOUT
	EXDEV           = unix.EXDEV
)
View Source
const (
	SEEK_SET = unix.SEEK_SET
	SEEK_CUR = unix.SEEK_CUR
	SEEK_END = unix.SEEK_END
)
View Source
const (
	DT_BLK     = unix.DT_BLK
	DT_CHR     = unix.DT_CHR
	DT_DIR     = unix.DT_DIR
	DT_LNK     = unix.DT_LNK
	DT_REG     = unix.DT_REG
	DT_FIFO    = unix.DT_FIFO
	DT_SOCK    = unix.DT_SOCK
	DT_UNKNOWN = unix.DT_UNKNOWN
)
View Source
const (
	TRUNC   = unix.MSG_TRUNC
	PEEK    = unix.MSG_PEEK
	WAITALL = unix.MSG_WAITALL
)
View Source
const (
	SHUTRD = unix.SHUT_RD
	SHUTWR = unix.SHUT_WR
)
View Source
const (
	// maxFollowSymlink is the hardcoded limit of symbolic links that may be
	// followed when resolving paths.
	//
	// This limit applies to RootFS, EvalSymlinks, and the functions that
	// depend on it.
	MaxFollowSymlink = 10
)

Variables

View Source
var ErrIPAM = errors.New("IP pool exhausted")
View Source
var (
	ErrInterfaceNotFound = errors.New("network interface not found")
)

Functions

func CopyFile added in v0.1.1

func CopyFile(fsys FileSystem, oldName, newName string) error

CopyFile creates a copy of oldName at newName in the given file system.

func CopyFileRange added in v0.1.1

func CopyFileRange(src File, srcOffset int64, dst File, dstOffset int64, length int) (int, error)

CopyFileRange is a generic implementation of the File.CopyFileRange method using Preadv/Pwritev.

func FS

func FS(fsys FileSystem) fs.FS

FS constructs a fs.FS backed by a FileSystem instance.

This method is useful to run the standard testing/fstest test suite against instances of the FileSystem interface.

The returned fs.FS implements fs.StatFS.

func Link(fsys FileSystem, oldName, newName string) error

Link creates a hard link between the old and new names passed as arguments.

func Mkdir

func Mkdir(fsys FileSystem, name string, mode fs.FileMode) error

Mkdir creates a directory on a file system. The mode is used to set the permissions of the new directory.

func MkdirAll

func MkdirAll(fsys FileSystem, name string, mode fs.FileMode) error

MkdirAll creates all directories to form the given path name on a file system. The mode is used to set the permissions of each new directory, permissions of existing directories are left untouched.

func ReadDirent

func ReadDirent(buf []byte) (n int, typ fs.FileMode, ino, off uint64, name []byte, err error)

ReadDirent reads a directory entry from buf, returning the number of bytes consumed and the values extracted from the buffer.

If the buffer was too short to contain a directory entry, the function returns io.ErrShortBuffer.

func ReadFile

func ReadFile(fsys FileSystem, name string, flags LookupFlags) ([]byte, error)

ReadFile reads the content of a file on a file system. The name represents the location where the file is recorded on the file system. The flags are passed to configure how the file is opened (e.g. passing O_NOFOLLOW will fail if a symbolic link exists at that location).

func Readlink(fsys FileSystem, name string) (string, error)

Readlink reads the target of a symbolic link located at the given path name on a file system.

func Rename

func Rename(fsys FileSystem, oldName, newName string, flags RenameFlags) error

Rename changes the name referencing a file, symbolic link, or directory on a file system.

func ResolvePath

func ResolvePath[F File, R any](dir F, name string, flags LookupFlags, do func(F, string) (R, error)) (ret R, err error)

ResolvePath is the path resolution algorithm which guarantees sandboxing of path access in a root FS.

The algorithm walks the path name from f, calling the do function when it reaches a path leaf. The function may return ELOOP to indicate that a symlink was encountered and must be followed, in which case ResolvePath continues walking the path at the link target. Any other value or error returned by the do function will be returned immediately.

func Rmdir

func Rmdir(fsys FileSystem, name string) error

Rmdir removes an empty directory from a file system.

func SockaddrAddr

func SockaddrAddr(sa Sockaddr) netip.Addr

func SockaddrAddrPort

func SockaddrAddrPort(sa Sockaddr) netip.AddrPort
func Symlink(fsys FileSystem, oldName, newName string) error

Symlink creates a symbolic link to a file system location.

func ThrottleFS

func ThrottleFS(f wasiFS, r, w *rate.Limiter) wasiFS

ThrottleFS wraps the file system passed as argument to apply the rate limits r and w on read and write operations.

The limits apply to all access to the underlying file system which may result in I/O operations.

Passing a nil rate limiter to r or w disables rate limiting on the corresponding I/O operations.

func Unlink(fsys FileSystem, name string) error

Unlink removes a file or symbolic link from a file system.

func WriteDirent

func WriteDirent(buf []byte, typ fs.FileMode, ino, off uint64, name string) int

WriteDirent writes a directory entry to buf.

Thie function is useful to create implementations of the FileSystem interface which need to implement the ReadDirent method to read directories.

func WriteFile

func WriteFile(fsys FileSystem, name string, data []byte, mode fs.FileMode) error

WriteFile writes a file on a file system.

Types

type Family

type Family uint8
const (
	UNIX  Family = unix.AF_UNIX
	INET  Family = unix.AF_INET
	INET6 Family = unix.AF_INET6
)

func SockaddrFamily

func SockaddrFamily(sa Sockaddr) Family

func (Family) String

func (f Family) String() string

type File

type File interface {
	// Returns the file descriptor number for the underlying kernel handle for
	// the file.
	Fd() uintptr

	// Closes the file.
	//
	// This method must be opened when the program does not need the file
	// anymore. Attempting to use the file after it was closed will cause
	// the methods to return errors.
	Close() error

	// Opens a file at the given name, relative to the file's position in the
	// file system.
	//
	// The file must point to a directory or the method errors with ENOTDIR.
	Open(name string, flags OpenFlags, mode fs.FileMode) (File, error)

	// Readv reads data from the current seek offset of the file into the list
	// of vectors passed as arguments.
	//
	// The method returns the number of bytes read, which may be less than the
	// total size of the read buffers, even in the absence of errors.
	//
	// When the end of file is reached, the method returns zero and a nil error
	// (it does not return io.EOF).
	Readv(iovs [][]byte) (int, error)

	// Writev writes data from the list of vectors to the current seek offset
	// of the file.
	//
	// The method returns the number of bytes written, which may be less than
	// the total size of the write buffers, even in the absence of errors.
	Writev(iovs [][]byte) (int, error)

	// Preadv reads data from the given seek offset into the list of vectors
	// passed as arguments.
	//
	// The method returns the number of bytes read, which may be less than the
	// total size of the read buffers, even in the absence of errors.
	//
	// When the end of file is reached, the method returns zero and a nil error
	// (it does not return io.EOF).
	Preadv(iovs [][]byte, offset int64) (int, error)

	// Pwritev writes data from the list of vectors at the given seek offset.
	//
	// The method returns the number of bytes written, which may be less than
	// the total size of the write buffers, even in the absence of errors.
	Pwritev(iovs [][]byte, offset int64) (int, error)

	// CopyFileRange copies length bytes from the receiver at srcOffset to the
	// destination at dstOffset, returning the number of bytes that have been
	// copied, which might be shorter than the requested length if an error
	// occured.
	CopyFileRange(srcOffset int64, dst File, dstOffset int64, length int) (int, error)

	// Seek positions the seek offset of the file at the given location, which
	// is interpreted relative to the whence value. The whence may be SEEK_SET,
	// SEEK_CUR, or SEEK_END to describe how to compute the final seek offset.
	Seek(offset int64, whence int) (int64, error)

	// Pre-allocates storage for the file at the given offset and length. If the
	// sum of offset and length exceeds the current size, the file is extended
	// as if Truncate(offset + length) had been called.
	Allocate(offset, length int64) error

	// Sets the file to the given size.
	//
	// If the size is shorter than the current file size, its content is
	// truncated and the data at the end of the file is dropped.
	//
	// If the size is larger than the current file size, zero bytes are appended
	// at the end to match the requested size.
	Truncate(size int64) error

	// Blocks until all buffered changes have been flushed to the underyling
	// storage device.
	//
	// Syncing includes writing metdata such as mutations to a directory.
	Sync() error

	// Datasync is similar to Sync but it only synchronizes writes to a file
	// content.
	Datasync() error

	// Returns the bitset of flags currently set on the file, which is a
	// combination of O_* flags such as those that can be passed to Open.
	//
	// The set of flags supported by the file depends on the underlying type.
	Flags() (OpenFlags, error)

	// Changes the bitset of flags set on the file. The flags are a combination
	// of O_* flags such as those that can be passed to Open.
	//
	// The set of flags supported by the file depends on the underlying type.
	SetFlags(flags OpenFlags) error

	// Read directory entries into the given buffer. The caller must be aware of
	// the way directory entries are laid out by the underlying file system to
	// interpret the content.
	//
	// The method returns the number of bytes written to buf.
	ReadDirent(buf []byte) (int, error)

	// Looks up and return file metdata.
	//
	// If the receiver is a directory, a name may be given to represent the file
	// to retrieve metdata for, relative to the directory. The flags may be
	// AT_SYMLINK_NOFOLLOW to retrieve metdata for a symbolic link instead of
	// its target.
	//
	// If the name is empty, flags are ignored and the method returns metdata
	// for the receiver.
	Stat(name string, flags LookupFlags) (FileInfo, error)

	// Reads the target of a symbolic link into buf.
	//
	// If the name is empty, the method assumes that the receiver is a file
	// opened on a symbolic link and returns the receiver's target.
	//
	// The method returns the number of bytes written to buf.
	Readlink(name string, buf []byte) (int, error)

	// Changes the access and modification time of a file.
	//
	// The access time is the first Timespec value, the modification time is the
	// second. Either of the Timespec values may have their nanosecond field set
	// to UTIME_OMIT to ignore it, or UTIME_NOW to set it to the current time.
	//
	// If the receiver is a directory, a name may be given to represent the file
	// to set the times for, relative to the directory. The flags may be
	// AT_SYMLINK_NOFOLLOW to change the times of a symbolic link instead of its
	// target (note that not all file systems may support it).
	//
	// If the name is empty, flags are ignored and the method changes times of
	// the receiver.
	Chtimes(name string, times [2]Timespec, flags LookupFlags) error

	// Creates a directory at the named location.
	//
	// The method assumes that the receiver is a directory and resolves the path
	// relative to it.
	//
	// The mode sets permissions on the newly created directory.
	Mkdir(name string, mode fs.FileMode) error

	// Removes an empty directory at a named location.
	//
	// The method assumes that the receiver is a directory and resolves the path
	// relative to it.
	Rmdir(name string) error

	// Moves a file to a new location.
	//
	// The old name is the path to the file to be moved, relative to the
	// receiver, which is expected to refer to a directory.
	//
	// The new name is interpreted relative to the directory passed as argument,
	// which may or may not be the same as the receiver, but must be on the same
	// file system.
	Rename(oldName string, newDir File, newName string, flags RenameFlags) error

	// Creates a hard link to a named location.
	//
	// The old name is the path to the file to be linked, relative to the
	// receiver, which is expected to refer to a directory.
	//
	// The new name is interpreted relative to the directory passed as argument,
	// which may or may not be the same as the reciver, but must be on the same
	// file system.
	//
	// The flags may be AT_SYMLINK_NOFOLLOW to create a link to a symbolic link
	// instead of its target.
	Link(oldName string, newDir File, newName string, flags LookupFlags) error

	// Creates a symbolic link to a named location.
	//
	// The old name may be an absolute or relative location, and does not need
	// to exist on the file system.
	//
	// The new name is interpreted relative to the receiver, which is expected
	// to refer to a directory.
	Symlink(oldName, newName string) error

	// Removes a file or symbolic link from the file system.
	//
	// The method is not idempotent, an error is returned if no files exist at
	// the location.
	//
	// Unlinking a file only drops the name referencing it, its content is only
	// reclaimed by the file system once all open references have been closed.
	Unlink(name string) error
}

File is an interface representing files opened from a file system.

File implementations must be safe for concurrent use by multiple goroutines.

func Create

func Create(fsys FileSystem, name string, mode fs.FileMode) (File, error)

Create creates and opens a file on a file system. The name is the location where the file is created and the mode is used to set permissions.

func Open

func Open(fsys FileSystem, name string) (File, error)

Open opens a file with the given name on a file system.

func OpenDir

func OpenDir(fsys FileSystem, name string) (File, error)

OpenDir opens a directory with the given name on the file system.

func OpenRoot

func OpenRoot(fsys FileSystem) (File, error)

OpenRoot opens the root directory of a file system.

type FileInfo

type FileInfo struct {
	Dev   uint64
	Ino   uint64
	Nlink uint64
	Mode  fs.FileMode
	Uid   uint32
	Gid   uint32
	Size  int64
	Atime Timespec
	Mtime Timespec
	Ctime Timespec
}

FileInfo is a type similar to fs.FileInfo or syscall.Stat_t on unix systems. It contains metadata about an entry on the file system.

func Lstat

func Lstat(fsys FileSystem, name string) (FileInfo, error)

Lstat returns information about a file on a file system.

Is the name points to a location where a symbolic link exists, the function returns information about the link itself.

func Stat

func Stat(fsys FileSystem, name string) (FileInfo, error)

Stat returns information about a file on a file system.

Is the name points to a location where a symbolic link exists, the function returns information about the link target.

func (FileInfo) String

func (info FileInfo) String() string

type FileSystem

type FileSystem interface {
	Open(name string, flags OpenFlags, mode fs.FileMode) (File, error)
}

FileSystem is the interface representing file systems.

The interface has a single method used to open a file at a path on the file system, which may be a directory. Often time this method is used to open the root directory and use the methods of the returned File instance to access the rest of the directory tree.

FileSystem implementations must be safe for concurrent use by multiple goroutines.

func DirFS

func DirFS(path string) FileSystem

DirFS constructs a FileSystem instance backed by a directory location on the local file system.

The returned FileSystem instance captures the path passed as argument as-is. If the path is relative, the resulting FileSystem depends on the program's current working directory when opening files.

As long as the directory that the file system is opened on does not change, it prevents escaping from it, even in the presence of symbolic links referencing paths above the root directory.

type Interface

type Interface interface {
	Index() int

	MTU() int

	Name() string

	HardwareAddr() net.HardwareAddr

	Flags() net.Flags

	Addrs() ([]net.Addr, error)

	MulticastAddrs() ([]net.Addr, error)
}

type LocalNamespace

type LocalNamespace struct {
	// contains filtered or unexported fields
}

func (*LocalNamespace) Detach

func (ns *LocalNamespace) Detach()

func (*LocalNamespace) InterfaceByIndex

func (ns *LocalNamespace) InterfaceByIndex(index int) (Interface, error)

func (*LocalNamespace) InterfaceByName

func (ns *LocalNamespace) InterfaceByName(name string) (Interface, error)

func (*LocalNamespace) Interfaces

func (ns *LocalNamespace) Interfaces() ([]Interface, error)

func (*LocalNamespace) Socket

func (ns *LocalNamespace) Socket(family Family, socktype Socktype, protocol Protocol) (Socket, error)

type LocalNetwork

type LocalNetwork struct {
	// contains filtered or unexported fields
}

func NewLocalNetwork

func NewLocalNetwork(addrs ...netip.Prefix) *LocalNetwork

func (*LocalNetwork) CreateNamespace

func (n *LocalNetwork) CreateNamespace(host Namespace, opts ...LocalOption) (*LocalNamespace, error)

type LocalOption

type LocalOption func(*LocalNamespace)

func DialFunc

func DialFunc(dial func(context.Context, string, string) (net.Conn, error)) LocalOption

func ListenFunc

func ListenFunc(listen func(context.Context, string, string) (net.Listener, error)) LocalOption

func ListenPacketFunc

func ListenPacketFunc(listenPacket func(context.Context, string, string) (net.PacketConn, error)) LocalOption

type LookupFlags added in v0.1.1

type LookupFlags int

LookupFlags is a bitset of flags that can be passed to methods of File and FileSystem values to customize the behavior of file name lookups.

const (
	AT_SYMLINK_NOFOLLOW LookupFlags = unix.AT_SYMLINK_NOFOLLOW
)

func (LookupFlags) OpenFlags added in v0.1.1

func (lf LookupFlags) OpenFlags() OpenFlags

func (LookupFlags) String added in v0.1.1

func (lf LookupFlags) String() string

type Namespace

type Namespace interface {
	InterfaceByIndex(index int) (Interface, error)

	InterfaceByName(name string) (Interface, error)

	Interfaces() ([]Interface, error)

	Socket(family Family, socktype Socktype, protocol Protocol) (Socket, error)
}

func Host

func Host() Namespace

type OpenFlags added in v0.1.1

type OpenFlags int

OpenFlags is a bitset of flags that can be passed to the Open method of File and FileSystem values.

const (
	O_DSYNC OpenFlags = unix.O_DSYNC
	O_RSYNC OpenFlags = unix.O_RSYNC
)
const (
	O_RDONLY    OpenFlags = unix.O_RDONLY
	O_WRONLY    OpenFlags = unix.O_WRONLY
	O_RDWR      OpenFlags = unix.O_RDWR
	O_APPEND    OpenFlags = unix.O_APPEND
	O_CREAT     OpenFlags = unix.O_CREAT
	O_EXCL      OpenFlags = unix.O_EXCL
	O_SYNC      OpenFlags = unix.O_SYNC
	O_TRUNC     OpenFlags = unix.O_TRUNC
	O_DIRECTORY OpenFlags = unix.O_DIRECTORY
	O_NOFOLLOW  OpenFlags = unix.O_NOFOLLOW
	O_NONBLOCK  OpenFlags = unix.O_NONBLOCK
)

func (OpenFlags) LookupFlags added in v0.1.1

func (of OpenFlags) LookupFlags() LookupFlags

func (OpenFlags) String added in v0.1.1

func (of OpenFlags) String() string

type Option

type Option func(*System)

Option represents configuration options that can be set when instantiating a System.

func Args

func Args(args ...string) Option

Args configures the list of arguments passed to the guest module.

func Environ

func Environ(environ ...string) Option

Environ configures the list of environment variables exposed to the guest module.

func MaxOpenDirs

func MaxOpenDirs(n int) Option

MaxOpenDirs configures the maximum number of directories that can be opened by the guest module.

Default to no limits (zero).

func MaxOpenFiles

func MaxOpenFiles(n int) Option

MaxOpenFiles configures the maximum number of files that can be opened by the guest module.

Note that the limit applies only to files open via PathOpen or sockets created by SockOpen or SockAccept, it does not apply to preopens installed directly by the host.

Default to no limits (zero).

func Mount

func Mount(path string, fsys FileSystem) Option

Mount configures a mount point to expose a file system to the guest module, with each mount point exposed as a preopen directory.

If no endpoints are set, the guest does not have a file system.

func Network

func Network(ns Namespace) Option

Network configures the network namespace exposed to the guest module.

Default to only exposing a loopback interface.

func Rand

func Rand(rand io.Reader) Option

Rand configures the random number generator exposed to the guest module.

If not set, the guest cannot generate random numbers.

func Resolver

func Resolver(rslv ServiceResolver) Option

Resolver configures the name resolver used when the guest attempts to lookup addresses.

Default to disabling name resolution.

func Time

func Time(time func() time.Time) Option

Time configures the function used by the guest module to get the current time.

If not set, the guest does not have access to the current time.

type Protocol

type Protocol uint16
const (
	NOPROTO Protocol = 0
	TCP     Protocol = 6
	UDP     Protocol = 17
)

func (Protocol) String

func (p Protocol) String() string

type RenameFlags added in v0.1.1

type RenameFlags int

RenameFlags is a bitset of flags passed to the File.Rename method to configure the behavior of the rename operation.

const (
	RENAME_EXCHANGE  RenameFlags = unix.RENAME_EXCHANGE
	RENAME_NOREPLACE RenameFlags = unix.RENAME_NOREPLACE
)

func (RenameFlags) String added in v0.1.1

func (rf RenameFlags) String() string

type ServiceResolver

type ServiceResolver interface {
	LookupPort(ctx context.Context, network, service string) (int, error)
	LookupIP(ctx context.Context, network, hostname string) ([]net.IP, error)
}

ServiceResolver is an interface used to implement service name resolution on System instances.

net.Resolver is a valid implementation of this interface.

type Sockaddr

type Sockaddr = unix.Sockaddr

func SockaddrFromAddrPort

func SockaddrFromAddrPort(addrPort netip.AddrPort) Sockaddr

type SockaddrInet4

type SockaddrInet4 = unix.SockaddrInet4

type SockaddrInet6

type SockaddrInet6 = unix.SockaddrInet6

type SockaddrUnix

type SockaddrUnix = unix.SockaddrUnix

type Socket

type Socket interface {
	Family() Family

	Type() Socktype

	Fd() uintptr

	File() *os.File

	Close() error

	Bind(addr Sockaddr) error

	Listen(backlog int) error

	Connect(addr Sockaddr) error

	Accept() (Socket, Sockaddr, error)

	Name() (Sockaddr, error)

	Peer() (Sockaddr, error)

	RecvFrom(iovs [][]byte, flags int) (n, rflags int, addr Sockaddr, err error)

	SendTo(iovs [][]byte, addr Sockaddr, flags int) (int, error)

	Shutdown(how int) error

	Error() error

	IsListening() (bool, error)

	IsNonBlock() (bool, error)

	TCPNoDelay() (bool, error)

	RecvBuffer() (int, error)

	SendBuffer() (int, error)

	RecvTimeout() (time.Duration, error)

	SendTimeout() (time.Duration, error)

	SetNonBlock(nonblock bool) error

	SetRecvBuffer(size int) error

	SetSendBuffer(size int) error

	SetRecvTimeout(timeout time.Duration) error

	SetSendTimeout(timeout time.Duration) error

	SetTCPNoDelay(nodelay bool) error

	SetTLSServerName(serverName string) error
}

type Socktype

type Socktype uint8
const (
	STREAM Socktype = unix.SOCK_STREAM
	DGRAM  Socktype = unix.SOCK_DGRAM
)

type System

type System struct {
	// contains filtered or unexported fields
}

System is an implementation of the wasi.System interface which sandboxes all interactions of the guest module with the world.

func New

func New(opts ...Option) *System

New creates a new System instance, applying the list of options passed as arguments.

func NewSystem

func NewSystem(opts ...Option) (*System, error)

func (*System) ArgsGet

func (s *System) ArgsGet(ctx context.Context) ([]string, wasi.Errno)

func (*System) ArgsSizesGet

func (s *System) ArgsSizesGet(ctx context.Context) (argCount, stringBytes int, errno wasi.Errno)

func (*System) ClockResGet

func (s *System) ClockResGet(ctx context.Context, id wasi.ClockID) (wasi.Timestamp, wasi.Errno)

func (*System) ClockTimeGet

func (s *System) ClockTimeGet(ctx context.Context, id wasi.ClockID, precision wasi.Timestamp) (wasi.Timestamp, wasi.Errno)

func (*System) Close

func (s *System) Close(ctx context.Context) error

func (*System) Dial

func (s *System) Dial(ctx context.Context, network, address string) (net.Conn, error)

Dial opens a connection to a listening socket on the guest module network.

This function has a signature that matches the one commonly used in the Go standard library as a hook to customize how and where network connections are estalibshed. The intent is for this function to be used when the host needs to establish a connection to the guest, maybe indirectly such as using a http.Transport and setting this method as the transport's dial function.

func (*System) EnvironGet

func (s *System) EnvironGet(ctx context.Context) ([]string, wasi.Errno)

func (*System) EnvironSizesGet

func (s *System) EnvironSizesGet(ctx context.Context) (envCount, stringBytes int, errno wasi.Errno)

func (*System) FDAdvise

func (s *System) FDAdvise(ctx context.Context, fd wasi.FD, offset, length wasi.FileSize, advice wasi.Advice) wasi.Errno

func (*System) FDAllocate

func (s *System) FDAllocate(ctx context.Context, fd wasi.FD, offset, length wasi.FileSize) wasi.Errno

func (*System) FDClose

func (s *System) FDClose(ctx context.Context, fd wasi.FD) wasi.Errno

func (*System) FDDataSync

func (s *System) FDDataSync(ctx context.Context, fd wasi.FD) wasi.Errno

func (*System) FDFileStatGet

func (s *System) FDFileStatGet(ctx context.Context, fd wasi.FD) (wasi.FileStat, wasi.Errno)

func (*System) FDFileStatSetSize

func (s *System) FDFileStatSetSize(ctx context.Context, fd wasi.FD, size wasi.FileSize) wasi.Errno

func (*System) FDFileStatSetTimes

func (s *System) FDFileStatSetTimes(ctx context.Context, fd wasi.FD, accessTime, modifyTime wasi.Timestamp, flags wasi.FSTFlags) wasi.Errno

func (*System) FDPreStatDirName

func (s *System) FDPreStatDirName(ctx context.Context, fd wasi.FD) (string, wasi.Errno)

func (*System) FDPreStatGet

func (s *System) FDPreStatGet(ctx context.Context, fd wasi.FD) (wasi.PreStat, wasi.Errno)

func (*System) FDPread

func (s *System) FDPread(ctx context.Context, fd wasi.FD, iovs []wasi.IOVec, offset wasi.FileSize) (wasi.Size, wasi.Errno)

func (*System) FDPwrite

func (s *System) FDPwrite(ctx context.Context, fd wasi.FD, iovs []wasi.IOVec, offset wasi.FileSize) (wasi.Size, wasi.Errno)

func (*System) FDRead

func (s *System) FDRead(ctx context.Context, fd wasi.FD, iovs []wasi.IOVec) (wasi.Size, wasi.Errno)

func (*System) FDReadDir

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

func (*System) FDRenumber

func (s *System) FDRenumber(ctx context.Context, from, to wasi.FD) wasi.Errno

func (*System) FDSeek

func (s *System) FDSeek(ctx context.Context, fd wasi.FD, offset wasi.FileDelta, whence wasi.Whence) (wasi.FileSize, wasi.Errno)

func (*System) FDStatGet

func (s *System) FDStatGet(ctx context.Context, fd wasi.FD) (wasi.FDStat, wasi.Errno)

func (*System) FDStatSetFlags

func (s *System) FDStatSetFlags(ctx context.Context, fd wasi.FD, flags wasi.FDFlags) wasi.Errno

func (*System) FDStatSetRights

func (s *System) FDStatSetRights(ctx context.Context, fd wasi.FD, rightsBase, rightsInheriting wasi.Rights) wasi.Errno

func (*System) FDSync

func (s *System) FDSync(ctx context.Context, fd wasi.FD) wasi.Errno

func (*System) FDTell

func (s *System) FDTell(ctx context.Context, fd wasi.FD) (wasi.FileSize, wasi.Errno)

func (*System) FDWrite

func (s *System) FDWrite(ctx context.Context, fd wasi.FD, iovs []wasi.IOVec) (wasi.Size, wasi.Errno)

func (*System) Kill

func (s *System) Kill()

Kill may be called asynchronously to cancel all blocking operations on the system, causing calls such as PollOneOff to unblock and return an error indicating that the system is shutting down.

func (*System) Listen

func (s *System) Listen(ctx context.Context, network, address string) (net.Listener, error)

Listen opens a listening socket on the network stack of the guest module, returning a net.Listener that the host can use to receive connections to the given network address.

The returned listener does not exist in the guest module file table, which means that the guest cannot shut it down, allowing the host ot have full control over the lifecycle of the underlying socket.

func (*System) ListenPacket

func (s *System) ListenPacket(ctx context.Context, network, address string) (net.PacketConn, error)

ListenPacket is like Listen but for datagram connections.

The supported networks are "udp", "udp4", and "udp6".

func (*System) PathCreateDirectory

func (s *System) PathCreateDirectory(ctx context.Context, fd wasi.FD, path string) wasi.Errno

func (*System) PathFileStatGet

func (s *System) PathFileStatGet(ctx context.Context, fd wasi.FD, lookupFlags wasi.LookupFlags, path string) (wasi.FileStat, wasi.Errno)

func (*System) PathFileStatSetTimes

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

func (*System) PathOpen

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

func (*System) PathRemoveDirectory

func (s *System) PathRemoveDirectory(ctx context.Context, fd wasi.FD, path string) wasi.Errno

func (*System) PathRename

func (s *System) PathRename(ctx context.Context, fd wasi.FD, oldPath string, newFD wasi.FD, newPath string) wasi.Errno
func (s *System) PathSymlink(ctx context.Context, oldPath string, fd wasi.FD, newPath string) wasi.Errno

func (*System) PathUnlinkFile

func (s *System) PathUnlinkFile(ctx context.Context, fd wasi.FD, path string) wasi.Errno

func (*System) PollOneOff

func (s *System) PollOneOff(ctx context.Context, subscriptions []wasi.Subscription, events []wasi.Event) (int, wasi.Errno)

func (*System) PreopenFD

func (s *System) PreopenFD(fd wasi.FD)

func (*System) ProcExit

func (s *System) ProcExit(ctx context.Context, code wasi.ExitCode) wasi.Errno

func (*System) ProcRaise

func (s *System) ProcRaise(ctx context.Context, signal wasi.Signal) wasi.Errno

func (*System) RandomGet

func (s *System) RandomGet(ctx context.Context, b []byte) wasi.Errno

func (*System) SchedYield

func (s *System) SchedYield(ctx context.Context) wasi.Errno

func (*System) SockAccept

func (s *System) SockAccept(ctx context.Context, fd wasi.FD, flags wasi.FDFlags) (wasi.FD, wasi.SocketAddress, wasi.SocketAddress, wasi.Errno)

func (*System) SockAddressInfo

func (s *System) SockAddressInfo(ctx context.Context, name, service string, hints wasi.AddressInfo, results []wasi.AddressInfo) (int, wasi.Errno)

func (*System) SockBind

func (s *System) SockBind(ctx context.Context, fd wasi.FD, addr wasi.SocketAddress) (wasi.SocketAddress, wasi.Errno)

func (*System) SockConnect

func (s *System) SockConnect(ctx context.Context, fd wasi.FD, peer wasi.SocketAddress) (wasi.SocketAddress, wasi.Errno)

func (*System) SockGetOpt

func (s *System) SockGetOpt(ctx context.Context, fd wasi.FD, option wasi.SocketOption) (wasi.SocketOptionValue, wasi.Errno)

func (*System) SockListen

func (s *System) SockListen(ctx context.Context, fd wasi.FD, backlog int) wasi.Errno

func (*System) SockLocalAddress

func (s *System) SockLocalAddress(ctx context.Context, fd wasi.FD) (wasi.SocketAddress, wasi.Errno)

func (*System) SockOpen

func (s *System) SockOpen(ctx context.Context, pf wasi.ProtocolFamily, st wasi.SocketType, proto wasi.Protocol, rightsBase, rightsInheriting wasi.Rights) (wasi.FD, wasi.Errno)

func (*System) SockRecv

func (s *System) SockRecv(ctx context.Context, fd wasi.FD, iovecs []wasi.IOVec, flags wasi.RIFlags) (wasi.Size, wasi.ROFlags, wasi.Errno)

func (*System) SockRecvFrom

func (s *System) SockRecvFrom(ctx context.Context, fd wasi.FD, iovecs []wasi.IOVec, flags wasi.RIFlags) (wasi.Size, wasi.ROFlags, wasi.SocketAddress, wasi.Errno)

func (*System) SockRemoteAddress

func (s *System) SockRemoteAddress(ctx context.Context, fd wasi.FD) (wasi.SocketAddress, wasi.Errno)

func (*System) SockSend

func (s *System) SockSend(ctx context.Context, fd wasi.FD, iovecs []wasi.IOVec, flags wasi.SIFlags) (wasi.Size, wasi.Errno)

func (*System) SockSendTo

func (s *System) SockSendTo(ctx context.Context, fd wasi.FD, iovecs []wasi.IOVec, flags wasi.SIFlags, addr wasi.SocketAddress) (wasi.Size, wasi.Errno)

func (*System) SockSetOpt

func (s *System) SockSetOpt(ctx context.Context, fd wasi.FD, option wasi.SocketOption, value wasi.SocketOptionValue) wasi.Errno

func (*System) SockShutdown

func (s *System) SockShutdown(ctx context.Context, fd wasi.FD, flags wasi.SDFlags) wasi.Errno

func (*System) Stderr

func (s *System) Stderr() io.ReadCloser

Stderr returns a writer to the standard output of the guest module.

func (*System) Stdin

func (s *System) Stdin() io.WriteCloser

Stdin returns a writer to the standard input of the guest module.

func (*System) Stdout

func (s *System) Stdout() io.ReadCloser

Stdout returns a writer to the standard output of the guest module.

type Timespec

type Timespec = unix.Timespec

func TimeToTimespec

func TimeToTimespec(t time.Time) Timespec

type Timeval

type Timeval = unix.Timeval

Directories

Path Synopsis
Package fspath is similar to the standard path package but provides functions that are more useful for path manipulation in the presence of symbolic links.
Package fspath is similar to the standard path package but provides functions that are more useful for path manipulation in the presence of symbolic links.

Jump to

Keyboard shortcuts

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