Documentation
¶
Index ¶
- Constants
- Variables
- func WriterForFile(fsc *FSContext, fd uint32) (writer io.Writer)
- type Context
- func (c *Context) Args() [][]byte
- func (c *Context) ArgsSize() uint32
- func (c *Context) Environ() [][]byte
- func (c *Context) EnvironSize() uint32
- func (c *Context) FS() *FSContext
- func (c *Context) Nanosleep(ns int64)
- func (c *Context) Nanotime() int64
- func (c *Context) NanotimeResolution() sys.ClockResolution
- func (c *Context) NewFSContext(stdin io.Reader, stdout, stderr io.Writer, rootFS sysfs.FS) (err error)
- func (c *Context) Osyield()
- func (c *Context) RandSource() io.Reader
- func (c *Context) Walltime() (sec int64, nsec int32)
- func (c *Context) WalltimeNanos() int64
- func (c *Context) WalltimeResolution() sys.ClockResolution
- type FSContext
- func (c *FSContext) ChangeOpenFlag(fd uint32, flag int) syscall.Errno
- func (c *FSContext) Close(context.Context) (err error)
- func (c *FSContext) CloseFile(fd uint32) syscall.Errno
- func (c *FSContext) LookupFile(fd uint32) (*FileEntry, bool)
- func (c *FSContext) OpenFile(fs sysfs.FS, path string, flag int, perm fs.FileMode) (uint32, syscall.Errno)
- func (c *FSContext) ReOpenDir(fd uint32) (*FileEntry, syscall.Errno)
- func (c *FSContext) Renumber(from, to uint32) syscall.Errno
- func (c *FSContext) RootFS() sysfs.FS
- type FileEntry
- type FileTable
- type ReadDir
- type StdioFilePoller
- type StdioFileReader
Constants ¶
const ( FdStdin uint32 = iota FdStdout FdStderr // 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 FdPreopen )
Variables ¶
var PollerAlwaysReady = &pollerAlwaysReady{}
PollerAlwaysReady is a poller that ignores the given timeout, and it returns true and no error.
var PollerDefaultStdin = &pollerDefaultStdin{}
PollerDefaultStdin is a poller that checks standard input.
var PollerNeverReady = &pollerNeverReady{}
PollerNeverReady is a poller that waits for the given duration, and it always returns false and no error.
Functions ¶
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context holds module-scoped system resources currently only supported by built-in host functions.
func DefaultContext ¶
DefaultContext returns Context with no values set except a possible nil fs.FS
This is only used for testing.
func NewContext ¶
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, rootFS sysfs.FS, ) (sysCtx *Context, err error)
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.
func (*Context) Args ¶
Args is like os.Args and defaults to nil.
Note: The count will never be more than math.MaxUint32. See wazero.ModuleConfig WithArgs
func (*Context) ArgsSize ¶
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
func (*Context) Environ ¶
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
func (*Context) EnvironSize ¶
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
func (*Context) NanotimeResolution ¶
func (c *Context) NanotimeResolution() sys.ClockResolution
NanotimeResolution returns resolution of Nanotime.
func (*Context) NewFSContext ¶ added in v1.0.2
func (c *Context) NewFSContext(stdin io.Reader, stdout, stderr io.Writer, rootFS sysfs.FS) (err error)
NewFSContext creates a FSContext with stdio streams and an optional pre-opened filesystem.
If `preopened` is not sysfs.UnimplementedFS, it is inserted into the file descriptor table as FdPreopen.
func (*Context) RandSource ¶
RandSource is a source of random bytes and defaults to a deterministic source. see wazero.ModuleConfig WithRandSource
func (*Context) WalltimeNanos ¶
WalltimeNanos returns platform.Walltime as epoch nanoseconds.
func (*Context) WalltimeResolution ¶
func (c *Context) WalltimeResolution() sys.ClockResolution
WalltimeResolution returns resolution of Walltime.
type FSContext ¶
type FSContext struct {
// contains filtered or unexported fields
}
func (*FSContext) ChangeOpenFlag ¶
ChangeOpenFlag changes the open flag of the given opened file pointed by `fd`. Currently, this only supports the change of syscall.O_APPEND flag.
func (*FSContext) LookupFile ¶
LookupFile returns a file if it is in the table.
func (*FSContext) OpenFile ¶
func (c *FSContext) OpenFile(fs sysfs.FS, path string, flag int, perm fs.FileMode) (uint32, syscall.Errno)
OpenFile opens the file into the table and returns its file descriptor. The result must be closed by CloseFile or Close.
func (*FSContext) ReOpenDir ¶
ReOpenDir re-opens the directory while keeping the same file descriptor. TODO: this might not be necessary once we have our own File type.
type FileEntry ¶
type FileEntry struct { // Name is the name of the directory up to its pre-open, or the pre-open // name itself when IsPreopen. // // Note: This can drift on rename. Name string // IsPreopen is a directory that is lazily opened. IsPreopen bool // FS is the filesystem associated with the pre-open. FS sysfs.FS // File is always non-nil. File fs.File // ReadDir is present when this File is a fs.ReadDirFile and `ReadDir` // was called. ReadDir *ReadDir // contains filtered or unexported fields }
FileEntry maps a path to an open file in a file system.
func (*FileEntry) CachedStat ¶
CachedStat returns the cacheable parts of platform.Stat_t or an error if they couldn't be retrieved.
type FileTable ¶
type FileTable = descriptor.Table[uint32, *FileEntry]
FileTable is an specialization of the descriptor.Table type used to map file descriptors to file entries.
type ReadDir ¶
type ReadDir struct { // CountRead is the total count of files read including Dirents. CountRead uint64 // Dirents is the contents of the last platform.Readdir call. Notably, // directory listing are not rewindable, so we keep entries around in case // the caller mis-estimated their buffer and needs a few still cached. // // Note: This is wasi-specific and needs to be refactored. // In wasi preview1, dot and dot-dot entries are required to exist, but the // reverse is true for preview2. More importantly, preview2 holds separate // stateful dir-entry-streams per file. Dirents []*platform.Dirent }
ReadDir is the status of a prior fs.ReadDirFile call.
type StdioFilePoller ¶ added in v1.0.2
StdioFilePoller is a strategy for polling a StdioFileReader for a given duration. It returns true if the reader has data ready to be read, false and/or an error otherwise.
type StdioFileReader ¶ added in v1.0.2
type StdioFileReader struct {
// contains filtered or unexported fields
}
StdioFileReader implements io.Reader for stdio files.
func NewStdioFileReader ¶ added in v1.0.2
func NewStdioFileReader(reader io.Reader, fileInfo fs.FileInfo, poll StdioFilePoller) *StdioFileReader
NewStdioFileReader is a constructor for StdioFileReader.
func (*StdioFileReader) Close ¶ added in v1.0.2
func (r *StdioFileReader) Close() error
Close implements fs.File
func (*StdioFileReader) Poll ¶ added in v1.0.2
func (r *StdioFileReader) Poll(duration time.Duration) (bool, error)
Poll invokes the StdioFilePoller that was given at the NewStdioFileReader constructor.