package sys

Import Path
	github.com/tetratelabs/wazero/internal/sys (on go.dev)

Dependency Relation
	imports 14 packages, and imported by 2 packages

Involved Source Files fs.go lazy.go stdio.go sys.go
Package-Level Type Names (total 6)
/* sort by: | */
Context holds module-scoped system resources currently only supported by built-in host functions. Args is like os.Args and defaults to nil. Note: The count will never be more than math.MaxUint32. See wazero.ModuleConfig WithArgs ArgsSize is the size to encode Args as Null-terminated strings. Note: To get the size without null-terminators, subtract the length of Args from this value. See wazero.ModuleConfig WithArgs See https://en.wikipedia.org/wiki/Null-terminated_string Environ are "key=value" entries like os.Environ and default to nil. Note: The count will never be more than math.MaxUint32. See wazero.ModuleConfig WithEnv EnvironSize is the size to encode Environ as Null-terminated strings. Note: To get the size without null-terminators, subtract the length of Environ from this value. See wazero.ModuleConfig WithEnv See https://en.wikipedia.org/wiki/Null-terminated_string FS returns the possibly empty (UnimplementedFS) file system context. InitFSContext initializes a FSContext with stdio streams and optional pre-opened filesystems and TCP listeners. Nanosleep implements sys.Nanosleep. Nanotime implements sys.Nanotime. NanotimeResolution returns resolution of Nanotime. Osyield implements sys.Osyield. RandSource is a source of random bytes and defaults to a deterministic source. see wazero.ModuleConfig WithRandSource Walltime implements platform.Walltime. WalltimeNanos returns platform.Walltime as epoch nanoseconds. WalltimeResolution returns resolution of Walltime. func DefaultContext(fs experimentalsys.FS) *Context func NewContext(max uint32, args, environ [][]byte, stdin io.Reader, stdout, stderr io.Writer, randSource io.Reader, walltime sys.Walltime, walltimeResolution sys.ClockResolution, nanotime sys.Nanotime, nanotimeResolution sys.ClockResolution, nanosleep sys.Nanosleep, osyield sys.Osyield, fs []experimentalsys.FS, guestPaths []string, tcpListeners []*net.TCPListener) (sysCtx *Context, err error) func github.com/tetratelabs/wazero/internal/wasm.(*Store).Instantiate(ctx context.Context, module *wasm.Module, name string, sys *Context, typeIDs []wasm.FunctionTypeID) (*wasm.ModuleInstance, error)
DirentCache is a caching abstraction of sys.File Readdir. This is special-cased for "wasi_snapshot_preview1.fd_readdir", and may be unneeded, or require changes, to support preview1 or preview2. - The position of the dirents are serialized as `d_next`. For reasons described below, any may need to be re-read. This accepts any positions in the cache, rather than track the position of the last dirent. - dot entries ("." and "..") must be returned. See /RATIONALE.md for why. - An sys.Dirent Name is variable length, it could exceed memory size and need to be re-read. - Multiple dirents may be returned. It is more efficient to read from the underlying file in bulk vs one-at-a-time. The last results returned by Read are cached, but entries before that position are not. This support re-reading entries that couldn't fit into memory without accidentally caching all entries in a large directory. This approach is sometimes called a sliding window. Read is similar to and returns the same errors as `Readdir` on sys.File. The main difference is this caches entries returned, resulting in multiple valid positions to read from. When zero, `pos` means rewind to the beginning of this directory. This implies a rewind (Seek to zero on the underlying sys.File), unless the initial entries are still cached. When non-zero, `pos` is the zero based index of all dirents returned since last rewind. Only entries beginning at `pos` are cached for subsequent calls. A non-zero `pos` before the cache returns sys.ENOENT for reasons described on DirentCache documentation. Up to `n` entries are cached and returned. When `n` exceeds the cache, the difference are read from the underlying sys.File via `Readdir`. EOF is when `len(dirents)` returned are less than `n`. func (*FileEntry).DirentCache() (*DirentCache, sys.Errno)
FileEntry maps a path to an open file in a file system. FS is the filesystem associated with the pre-open. File is always non-nil. IsPreopen is a directory that is lazily opened. Name is the name of the directory up to its pre-open, or the pre-open name itself when IsPreopen. # Notes - This can drift on rename. - This relates to the guest path, which is not the real file path except if the entire host filesystem was made available. DirentCache gets or creates a DirentCache for this file or returns an error. # Errors A zero sys.Errno is success. The below are expected otherwise: - sys.ENOSYS: the implementation does not support this function. - sys.EBADF: the dir was closed or not readable. - sys.ENOTDIR: the file was not a directory. # Notes - See /RATIONALE.md for design notes. func (*FSContext).LookupFile(fd int32) (*FileEntry, bool)
FileTable is a specialization of the descriptor.Table type used to map file descriptors to file entries.
Close implements io.Closer CloseFile returns any error closing the existing file. LookupFile returns a file if it is in the table. OpenFile opens the file into the table and returns its file descriptor. The result must be closed by CloseFile or Close. Renumber assigns the file pointed by the descriptor `from` to `to`. SockAccept accepts a sock.TCPConn into the file table and returns its file descriptor. *FSContext : github.com/prometheus/common/expfmt.Closer *FSContext : io.Closer func (*Context).FS() *FSContext
StdinFile is a fs.ModeDevice file for use implementing FdStdin. This is safer than reading from os.DevNull as it can never overrun operating system file descriptors. noopStdinFile.noopStdioFile.UnimplementedFile experimentalsys.UnimplementedFile Reader io.Reader Close implements the same method as documented on sys.File Datasync implements File.Datasync Dev implements File.Dev Ino implements File.Ino IsAppend implements File.IsAppend IsDir implements the same method as documented on sys.File IsNonblock implements the same method as documented on fsapi.File Poll implements the same method as documented on fsapi.File Pread implements File.Pread Pwrite implements File.Pwrite Read implements the same method as documented on sys.File Readdir implements File.Readdir Seek implements File.Seek SetAppend implements File.SetAppend SetNonblock implements the same method as documented on fsapi.File Stat implements the same method as documented on sys.File Sync implements File.Sync Truncate implements File.Truncate Utimens implements File.Utimens Write implements File.Write *StdinFile : github.com/tetratelabs/wazero/internal/fsapi.File *StdinFile : github.com/tetratelabs/wazero/experimental/sys.File
Package-Level Functions (total 3)
DefaultContext returns Context with no values set except a possible nil sys.FS. Note: This is only used for testing.
NewContext is a factory function which helps avoid needing to know defaults or exporting all fields. Note: max is exposed for testing. max is only used for env/args validation.
StripPrefixesAndTrailingSlash skips any leading "./" or "/" such that the result index begins with another string. A result of "." coerces to the empty string "" because the current directory is handled by the guest. Results are the offset/len pair which is an optimization to avoid re-slicing overhead, as this function is called for every path operation. Note: Relative paths should be handled by the guest, as that's what knows what the current directory is. However, paths that escape the current directory e.g. "../.." have been found in `tinygo test` and this implementation takes care to avoid it.
Package-Level Constants (total 4)
FdPreopen is the file descriptor of the first pre-opened directory. # Why file descriptor 3? While not specified, the most common WASI implementation, wasi-libc, expects POSIX style file descriptor allocation, where the lowest available number is used to open the next file. Since 1 and 2 are taken by stdout and stderr, the next is 3. - https://github.com/WebAssembly/WASI/issues/122 - https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_14 - https://github.com/WebAssembly/wasi-libc/blob/wasi-sdk-16/libc-bottom-half/sources/preopens.c#L215
const FdStderr int32 = 2
const FdStdin int32 = 0
const FdStdout int32 = 1