vm

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: BSD-3-Clause Imports: 10 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// ExternTypeFuncName is the name of the WebAssembly 1.0 (20191205) Text Format field for ExternTypeFunc.
	ExternTypeFuncName = "func"
	// ExternTypeTableName is the name of the WebAssembly 1.0 (20191205) Text Format field for ExternTypeTable.
	ExternTypeTableName = "table"
	// ExternTypeMemoryName is the name of the WebAssembly 1.0 (20191205) Text Format field for ExternTypeMemory.
	ExternTypeMemoryName = "memory"
	// ExternTypeGlobalName is the name of the WebAssembly 1.0 (20191205) Text Format field for ExternTypeGlobal.
	ExternTypeGlobalName = "global"
)

The below are exported to consolidate parsing behavior for external types.

Variables

View Source
var (
	GetTimeout = 60 * time.Second

	//TODO: Lookup should handle timeout (tns fetch may need to take context)
	LookupTimeout = 10 * time.Second
)
View Source
var ContextType = reflect.TypeOf((*context.Context)(nil)).Elem()

ContextType lets the satellite plugin server detect a leading context.Context parameter when reflecting over a plugin's exported functions.

Functions

func DecodeExternref

func DecodeExternref(input uint64) uintptr

DecodeExternref decodes the input as a ValueTypeExternref.

func DecodeF32

func DecodeF32(input uint64) float32

DecodeF32 decodes the input as a ValueTypeF32.

func DecodeF64

func DecodeF64(input uint64) float64

DecodeF64 decodes the input as a ValueTypeF64.

func EncodeExternref

func EncodeExternref(input uintptr) uint64

EncodeExternref encodes the input as a ValueTypeExternref.

func EncodeF32

func EncodeF32(input float32) uint64

EncodeF32 encodes the input as a ValueTypeF32.

func EncodeF64

func EncodeF64(input float64) uint64

EncodeF64 encodes the input as a ValueTypeF64.

func EncodeI32

func EncodeI32(input int32) uint64

EncodeI32 encodes the input as a ValueTypeI32.

func EncodeI64

func EncodeI64(input int64) uint64

EncodeI64 encodes the input as a ValueTypeI64.

func ExternTypeName

func ExternTypeName(et ExternType) string

ExternTypeName returns the name of the WebAssembly 1.0 (20191205) Text Format field of the given type.

func ValueTypeName

func ValueTypeName(t ValueType) string

ValueTypeName returns the type name of the given ValueType as a string. These type names match the names used in the WebAssembly text format.

Types

type Backend

type Backend interface {
	// Returns the URI scheme the backend supports.
	Scheme() string
	// Get attempts to retrieve the WASM asset.
	Get(multAddr ma.Multiaddr) (io.ReadCloser, error)
	// Close will close the Backend.
	Close() error
}

type Config

type Config struct {
	MemoryLimitPages uint32 // should default to MemoryLimitPages
	Output           OutputType
}

Config sets configuration of the VM service

type Context

type Context interface {
	// Context returns the go context of the function instance
	Context() context.Context

	// Project returns the Taubyte project id
	Project() string

	// Application returns the application, if none returns an empty string
	Application() string

	// Resource returns the id of the resource being used.
	Resource() string

	// Branches returns the branch name used by this resource execution pipeline.
	Branches() []string

	// Commit returns the commit id used by this resource execution pipeline.
	Commit() string

	// Clone clones the VM.Context with a new go context
	Clone(context.Context) Context
}

type ExternType

type ExternType = byte

ExternType classifies imports and exports with their respective types.

See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#external-types%E2%91%A0

const (
	ExternTypeFunc   ExternType = 0x00
	ExternTypeTable  ExternType = 0x01
	ExternTypeMemory ExternType = 0x02
	ExternTypeGlobal ExternType = 0x03
)

type Factory

type Factory interface {
	// Close will close and cleanup the Factory
	Close() error

	// Name returns the name of the Factory
	Name() string
}

type Function

type Function = api.Function

Function and Global are wazy's, exposed directly (wazy is the only engine).

type FunctionDefinition

type FunctionDefinition interface {
	// Name is the module-defined name of the function, which is not necessarily
	// the same as its export name.
	Name() string

	// ParamTypes are the possibly empty sequence of value types accepted by a
	// function with this signature.
	ParamTypes() []ValueType

	// ResultTypes are the results of the function.
	ResultTypes() []ValueType
}

FunctionDefinition is a WebAssembly function exported in a module.

type FunctionInstance

type FunctionInstance interface {
	RawCall(ctx context.Context, args ...uint64) ([]uint64, error)
}

FunctionInstance is a callable wasm export. It stays a tau interface (rather than aliasing api.Function) so it can be mocked in substrate tests without a real engine. Params/results are raw wasm uint64 slots — the caller marshals.

type Global

type Global = api.Global

Function and Global are wazy's, exposed directly (wazy is the only engine).

type HostFunctionProvider added in v1.2.0

type HostFunctionProvider interface {
	RegisterHostFunctions(wazy.HostModuleBuilder)
}

HostFunctionProvider is implemented by factories that register their host functions onto a wazy host-module builder (typed, via wazy.HostFuncN / HostProcN). The plugin loader calls this for each factory.

type HostModule

type HostModule interface {
	// Builder returns the underlying wazy host-module builder.
	Builder() wazy.HostModuleBuilder

	// Compile instantiates the registered functions and returns the module.
	Compile() (ModuleInstance, error)
}

HostModule is a wazy host module under construction. Register host functions on its Builder (with wazy.HostFuncN / HostProcN, or WithGoModuleFunction for raw signatures), then Compile.

type Instance

type Instance interface {
	// Context returns the context of the function Instance
	Context() Context

	// Close will close the Instance
	Close() error

	// Runtime returns a new Function Instance Runtime. Optional register
	// callbacks add extra host functions to the built-in `env` module (used by
	// tests to expose fixtures' host imports).
	Runtime(register ...func(wazy.HostModuleBuilder)) (Runtime, error)

	// Filesystem returns the filesystem used by the given Instance.
	Filesystem() afero.Fs

	// Stdout returns the Reader interface of stdout
	Stdout() io.Reader

	// Stderr returns the Reader interface of stderr
	Stderr() io.Reader
}

type Loader

type Loader interface {
	// Load resolves the module, then loads the module using a Backend
	Load(ctx Context, module string) (io.ReadCloser, error)
}

type Logger added in v1.1.9

type Logger interface {
	// New creates a new call logger instance using the provided vm.Context
	// Writes to memory buffer, commits to file on close
	New(ctx Context) (io.WriteCloser, error)

	// Open returns a ReadCloser for reading logs at specific timestamp, fails if file doesn't exist
	Open(ctx Context, timestamp time.Time) (io.ReadCloser, error)

	// List returns all timestamps for a specific context within the specified range
	// If start is zero, uses first timestamp. If end is zero, uses last timestamp.
	List(ctx Context, start, end time.Time) ([]time.Time, error)

	// First returns the first (earliest) timestamp for a specific context
	First(ctx Context) (time.Time, error)

	// Last returns the last (most recent) timestamp for a specific context
	Last(ctx Context) (time.Time, error)

	// Close closes the logger and all open files
	Close() error
}

Logger provides logging capabilities for VM function calls and executions

type Memory

type Memory = api.Memory

Memory is a wazy module's memory, exposed directly (wazy is the only engine).

type MemorySizer

type MemorySizer func(minPages uint32, maxPages *uint32) (min, capacity, max uint32)

MemorySizer applies during compilation after a module has been decoded from wasm, but before it is instantiated.

type Module

type Module = api.Module

Module is a wazy-instantiated module, exposed directly. wazy is the only engine, so there is no abstraction to wrap it (the old callBridge is gone).

type ModuleInstance

type ModuleInstance interface {
	// Function returns a FunctionInstance of given name from the ModuleInstance
	Function(name string) (FunctionInstance, error)
	Memory() Memory
}

type OutputType

type OutputType uint32
const (
	Pipe OutputType = iota
	Buffer
	Stdio
)

type Plugin

type Plugin interface {
	// New creates a new PluginInstance
	New(Instance) (PluginInstance, error)

	// Name returns the name of the Plugin
	Name() string

	Close() error
}

TODO: New takes options for factories

type PluginInstance

type PluginInstance interface {
	// Load will load all Factories to the HostModule, and return the ModuleInstance
	Load(HostModule) (ModuleInstance, error)

	// Close will close the PluginInstance
	Close() error
}

type Resolver

type Resolver interface {
	// Lookup resolves a module name and returns the uri
	Lookup(ctx Context, module string) (ma.Multiaddr, error)
}

type Runtime

type Runtime interface {
	Modules() []string
	Module(name string) (ModuleInstance, error)
	Expose(name string) (HostModule, error)
	Attach(plugin Plugin) (PluginInstance, ModuleInstance, error)
	Stdout() io.Reader
	Stderr() io.Reader
	// TODO: Add Runtime Stat
	Close() error
}

type Service

type Service interface {
	New(context Context, config Config) (Instance, error)
	Source() Source
	Close() error
}

type Source

type Source interface {
	// Module Loads the given module name, and returns the SourceModule
	Module(ctx Context, name string) (SourceModule, error)
}

type SourceModule

type SourceModule []byte

type ValueType

type ValueType = byte

ValueType describes a numeric type used in Web Assembly 1.0 (20191205).

const (
	// ValueTypeI32 is a 32-bit integer.
	ValueTypeI32 ValueType = 0x7f
	// ValueTypeI64 is a 64-bit integer.
	ValueTypeI64 ValueType = 0x7e
	// ValueTypeF32 is a 32-bit floating point number.
	ValueTypeF32 ValueType = 0x7d
	// ValueTypeF64 is a 64-bit floating point number.
	ValueTypeF64 ValueType = 0x7c

	// ValueTypeExternref is a externref type.
	ValueTypeExternref ValueType = 0x6f
)

Jump to

Keyboard shortcuts

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