exec

package
v0.0.0-...-3940e3f Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2021 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDataSegmentDoesNotFit = errors.New("data segment does not fit")

ErrDataSegmentDoesNotFit should be returned by Instantiate if a data segment attempts to write outside of its target memory's bounds.

View Source
var ErrElementSegmentDoesNotFit = errors.New("element segment does not fit")

ErrElementSegmentDoesNotFit should be returned by Instantiate if a element segment attempts to write outside of its target table's bounds.

View Source
var ErrGlobalType = errors.New("global type mismatch")
View Source
var ErrInvalidTypeIndex = fmt.Errorf("invalid type index")

ErrInvalidTypeIndex is returned by InstantiateModule if the module's imports contain an invalid type index.

View Source
var ErrLimitExceeded = fmt.Errorf("memory limit exceeded")
View Source
var ErrMemoryType = errors.New("memory type mismatch")
View Source
var ErrModuleNotFound = fmt.Errorf("module not found")
View Source
var ErrTableType = errors.New("table type mismatch")
View Source
var TrapCallStackExhausted = Trap("call stack exhausted")

TrapCallStackExhausted indicates call stack exhaustion.

View Source
var TrapGeneric = Trap("")

TrapGeneric is produced for failures with no associated information.

View Source
var TrapIndirectCallTypeMismatch = Trap("indirect call type mismatch")

TrapIndirectCallTypeMismatch indicates a mismatch between the exepected and actual signature of a function.

View Source
var TrapIntegerDivideByZero = Trap("integer divide by zero")

TrapIntegerDivideByZero indicates an attempt to divide by zero.

View Source
var TrapIntegerOverflow = Trap("integer overflow")

TrapIntegerOverflow indicates an integer overflow.

View Source
var TrapInvalidConversionToInteger = Trap("invalid conversion to integer")

TrapInvalidConversionToInteger indicates an invalid converstion from a floating-point value to an integer.

View Source
var TrapOutOfBoundsMemoryAccess = Trap("out of bounds memory access")

TrapOutOfBoundsMemoryAccess indicates an out-of-bounds memory access.

View Source
var TrapUndefinedElement = Trap("undefined element")

TrapInvalidUndefinedElement indicates an attempt to access a table with an index that is out of bounds.

View Source
var TrapUninitializedElement = Trap("uninitialized element")

TrapUninitializedElement indicates an attempt to use an uninitialized table element.

View Source
var TrapUnreachable = Trap("unreachable")

TrapUnreachable indicates execution of unreachable code.

Functions

func EvalConstantExpression

func EvalConstantExpression(imports []*Global, expr []byte) (interface{}, error)

EvalConstantExpression executes the given (encoded) constant expression in the context of the given imports.

func Fmax

func Fmax(z1, z2 float64) float64

func Fmin

func Fmin(z1, z2 float64) float64

func I32DivS

func I32DivS(i1, i2 int32) int32

func I32TruncS

func I32TruncS(z float64) int32

func I32TruncSatS

func I32TruncSatS(z float64) int32

func I32TruncSatU

func I32TruncSatU(z float64) uint32

func I32TruncU

func I32TruncU(z float64) uint32

func I64DivS

func I64DivS(i1, i2 int64) int64

func I64TruncS

func I64TruncS(z float64) int64

func I64TruncSatS

func I64TruncSatS(z float64) int64

func I64TruncSatU

func I64TruncSatU(z float64) uint64

func I64TruncU

func I64TruncU(z float64) uint64

func NewKindMismatchError

func NewKindMismatchError(exportingModuleName, exportName string, importKind, exportKind wasm.External) error

NewKindMismatchError creates a new error that reports a mismatch between an import and export kind. This function should be used to create the errors returned by Module.Get{Function,Table,Memory,Global} if the requested name refers to an export of a different kind.

func TranslateRecover

func TranslateRecover(x interface{})

TranslateRecover is a utility function that translates the result of a call to recover() into nothing, a trap, or a panic. This function should be called like so:

defer func() { exec.TranslateRecover(recover()) }()

Types

type AllocatedModule

type AllocatedModule interface {
	Module

	// Instantiate initializes the allocated module with imports supplied by the given resolver.
	Instantiate(imports ImportResolver) (Module, error)
}

An AllocatedModule is an allocated but uninitialized WASM module.

type ExportNotFoundError

type ExportNotFoundError struct {
	ModuleName string
	FieldName  string
}

An ExportNotFoundError is returned by InstantiateModule if an export could not be found.

func (*ExportNotFoundError) Error

func (e *ExportNotFoundError) Error() string

type Frame

type Frame struct {
	Caller            *Frame
	ModuleName        string
	FunctionIndex     uint32
	FunctionSignature wasm.FunctionSig
	Locals            []uint64
}

A Frame records a single WASM activation record.

type Function

type Function interface {
	// GetSignature returns this function's signature.
	GetSignature() wasm.FunctionSig
	// Call calls the function with the given arguments. If the number and type of the arguments do not match the
	// number and type of the parameters in this function's signature, this method may panic.
	Call(thread *Thread, args ...interface{}) []interface{}
	// UncheckedCall calls the function with the given arguments. This method's behavior is undefined If the number of
	// arguments/returns does not match the number of parameters/results in this function's signature.
	UncheckedCall(thread *Thread, args, returns []uint64)
}

Function represents a function exported by a WASM module.

var UninitializedFunction Function = uninitializedFunction(0)

UninitializedFunction represents an uninitialized table entry. Calling this function will trap.

type Global

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

func NewGlobalF32

func NewGlobalF32(immutable bool, value float32) Global

func NewGlobalF64

func NewGlobalF64(immutable bool, value float64) Global

func NewGlobalI32

func NewGlobalI32(immutable bool, value int32) Global

func NewGlobalI64

func NewGlobalI64(immutable bool, value int64) Global

func (*Global) Get

func (g *Global) Get() uint64

func (*Global) GetF32

func (g *Global) GetF32() float32

func (*Global) GetF64

func (g *Global) GetF64() float64

func (*Global) GetI32

func (g *Global) GetI32() int32

func (*Global) GetI64

func (g *Global) GetI64() int64

func (*Global) GetValue

func (g *Global) GetValue() interface{}

func (*Global) Set

func (g *Global) Set(v uint64)

func (*Global) SetF32

func (g *Global) SetF32(v float32)

func (*Global) SetF64

func (g *Global) SetF64(v float64)

func (*Global) SetI32

func (g *Global) SetI32(v int32)

func (*Global) SetI64

func (g *Global) SetI64(v int64)

func (*Global) SetValue

func (g *Global) SetValue(v interface{})

func (*Global) Type

func (g *Global) Type() wasm.GlobalVar

type HostFunction

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

func NewHostFunction

func NewHostFunction(module Module, index uint32, method reflect.Value) *HostFunction

func (*HostFunction) Call

func (f *HostFunction) Call(thread *Thread, args ...interface{}) []interface{}

func (*HostFunction) Func

func (f *HostFunction) Func() interface{}

func (*HostFunction) GetSignature

func (f *HostFunction) GetSignature() wasm.FunctionSig

func (*HostFunction) UncheckedCall

func (f *HostFunction) UncheckedCall(thread *Thread, args, returns []uint64)

type ImportResolver

type ImportResolver interface {
	ResolveFunction(moduleName, functionName string, type_ wasm.FunctionSig) (Function, error)
	ResolveMemory(moduleName, memoryName string, type_ wasm.Memory) (*Memory, error)
	ResolveTable(moduleName, tableName string, type_ wasm.Table) (*Table, error)
	ResolveGlobal(moduleName, globalName string, type_ wasm.GlobalVar) (*Global, error)
}

An ImportResolver resolves import entries to function, memory, table, and global instances.

type InvalidGlobalIndexError

type InvalidGlobalIndexError uint32

func (InvalidGlobalIndexError) Error

func (e InvalidGlobalIndexError) Error() string

type InvalidImportError

type InvalidImportError struct {
	ModuleName string
	FieldName  string
	TypeIndex  uint32
}

InvalidImportError is returned when the export of a resolved module doesn't match the signature of its import declaration.

func (*InvalidImportError) Error

func (e *InvalidImportError) Error() string

type InvalidTableIndexError

type InvalidTableIndexError uint32

func (InvalidTableIndexError) Error

func (e InvalidTableIndexError) Error() string

type InvalidValueTypeInitExprError

type InvalidValueTypeInitExprError struct {
	Wanted reflect.Kind
	Got    reflect.Kind
}

func (InvalidValueTypeInitExprError) Error

type KindMismatchError

type KindMismatchError struct {
	ModuleName string
	FieldName  string
	Import     wasm.External
	Export     wasm.External
}

func (*KindMismatchError) Error

func (e *KindMismatchError) Error() string

type MapResolver

type MapResolver map[string]ModuleDefinition

A MapResolver is a ModuleResolver that maps module names to definitions using the contents of a map.

func (MapResolver) ResolveModule

func (r MapResolver) ResolveModule(name string) (ModuleDefinition, error)

ResolveModule resolves the given module name to a module definition.

type Memory

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

Memory is a WASM linear memory.

func NewMemory

func NewMemory(min, max uint32) Memory

NewMemory creates a new linear memory with the given limits.

func (*Memory) Byte

func (m *Memory) Byte(base, offset uint32) byte

Byte returns the byte stored at the given effective address.

func (*Memory) ByteAt

func (m *Memory) ByteAt(offset uint32) byte

ByteAt returns the byte stored at the given offset.

func (*Memory) Bytes

func (m *Memory) Bytes() []byte

Bytes returns the memory's bytes.

func (*Memory) Float32

func (m *Memory) Float32(base, offset uint32) float32

Float32 returns the float32 stored at the given effective address.

func (*Memory) Float32At

func (m *Memory) Float32At(offset uint32) float32

Float32At returns the float32 stored at the given offset.

func (*Memory) Float64

func (m *Memory) Float64(base, offset uint32) float64

Float64 returns the float64 stored at the given effective address.

func (*Memory) Float64At

func (m *Memory) Float64At(offset uint32) float64

Float64At returns the float64 stored at the given offset.

func (*Memory) Grow

func (m *Memory) Grow(pages uint32) (uint32, error)

Grow grows the memory by the given number of pages. It returns the old size of the memory in pages and an error if growing the memory by the requested amount would exceed the memory's maximum size.

func (*Memory) Limits

func (m *Memory) Limits() (min, max uint32)

Limits returns the minimum and maximum size of the memory in pages.

func (*Memory) PutByte

func (m *Memory) PutByte(v byte, base, offset uint32)

PutByte writes the given byte to the given effective address.

func (*Memory) PutByteAt

func (m *Memory) PutByteAt(v byte, offset uint32)

PutByteAt writes the given byte to the given offset.

func (*Memory) PutFloat32

func (m *Memory) PutFloat32(v float32, base, offset uint32)

PutFloat32 writes the given float32 to the given effective address.

func (*Memory) PutFloat32At

func (m *Memory) PutFloat32At(v float32, offset uint32)

PutFloat32At writes the given float32 to the given offset.

func (*Memory) PutFloat64

func (m *Memory) PutFloat64(v float64, base, offset uint32)

PutFloat64 writes the given float64 to the given effective address.

func (*Memory) PutFloat64At

func (m *Memory) PutFloat64At(v float64, offset uint32)

PutFloat64At writes the given float64 to the given offset.

func (*Memory) PutUint16

func (m *Memory) PutUint16(v uint16, base, offset uint32)

PutUint16 writes the given uint16 to the given effective address.

func (*Memory) PutUint16At

func (m *Memory) PutUint16At(v uint16, offset uint32)

PutUint16At writes the given uint16 to the given offset.

func (*Memory) PutUint32

func (m *Memory) PutUint32(v uint32, base, offset uint32)

PutUint32 writes the given uint32 to the given effective address.

func (*Memory) PutUint32At

func (m *Memory) PutUint32At(v uint32, offset uint32)

PutUint32At writes the given uint32 to the given offset.

func (*Memory) PutUint64

func (m *Memory) PutUint64(v uint64, base, offset uint32)

PutUint64 writes the given uint64 to the given effective address.

func (*Memory) PutUint64At

func (m *Memory) PutUint64At(v uint64, offset uint32)

PutUint64 writes the given uint64 to the given offset.

func (*Memory) PutUint8

func (m *Memory) PutUint8(v byte, base, offset uint32)

PutUint8 writes the given byte to the given effective address.

func (*Memory) PutUint8At

func (m *Memory) PutUint8At(v byte, offset uint32)

PutUint8At writes the given byte to the given offset.

func (*Memory) Size

func (m *Memory) Size() uint32

Size returns the current size of the memory in pages.

func (*Memory) Start

func (m *Memory) Start() uintptr

func (*Memory) Uint16

func (m *Memory) Uint16(base, offset uint32) uint16

Uint16 returns the uint16 stored at the given effective address.

func (*Memory) Uint16At

func (m *Memory) Uint16At(offset uint32) uint16

Uint16At returns the uint16 stored at the given offset.

func (*Memory) Uint32

func (m *Memory) Uint32(base, offset uint32) uint32

Uint32 returns the uint32 stored at the given effective address.

func (*Memory) Uint32At

func (m *Memory) Uint32At(offset uint32) uint32

Uint32At returns the uint32 stored at the given offset.

func (*Memory) Uint64

func (m *Memory) Uint64(base, offset uint32) uint64

Uint64 returns the uint64 stored at the given effective address.

func (*Memory) Uint64At

func (m *Memory) Uint64At(offset uint32) uint64

Uint64 returns the uint64 stored at the given offset.

func (*Memory) Uint8

func (m *Memory) Uint8(base, offset uint32) byte

Uint8 returns the byte stored at the given effective address.

func (*Memory) Uint8At

func (m *Memory) Uint8At(offset uint32) byte

Uint8At returns the byte stored at the given offset.

type Module

type Module interface {
	// Name returns the name of this module.
	Name() string
	// GetFunction returns the exported function with the given name. If the function does not exist or the name
	// refers to an export of a different kind, this function returns an error.
	GetFunction(name string) (Function, error)
	// GetTable returns the exported table with the given name. If the table does not exist or the name
	// refers to an export of a different kind, this function returns an error.
	GetTable(name string) (*Table, error)
	// GetMemory returns the exported memory with the given name. If the memory does not exist or the name
	// refers to an export of a different kind, this function returns an error.
	GetMemory(name string) (*Memory, error)
	// GetGlobal returns the exported global with the given name. If the global does not exist or the name
	// refers to an export of a different kind, this function returns an error.
	GetGlobal(name string) (*Global, error)
}

A Module is an instantiated WASM module.

func NewHostModule

func NewHostModule(name string, v interface{}) Module

type ModuleDefinition

type ModuleDefinition interface {
	// Allocate creates an allocated, uninitialized module with the given name from this module definition.
	Allocate(name string) (AllocatedModule, error)
}

ModuleDefinition represents a WASM module definition.

func NewHostModuleDefinition

func NewHostModuleDefinition(instantiate interface{}) ModuleDefinition

instantiate must be a func() T. instantiate will be called to instantiate a host module.

type ModuleEventHandler

type ModuleEventHandler interface {
	ModuleAllocated(m AllocatedModule) error
	ModuleInstantiated(m Module) error
}

A ModuleEventHandler responds to module allocations and instantiations.

type ModuleResolver

type ModuleResolver interface {
	// ResolveModule resolves the given module name to a module definition.
	ResolveModule(name string) (ModuleDefinition, error)
}

A ModuleResolver resolves module names to module definitions.

type Store

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

A Store is responsible for instantiating modules.

func NewStore

func NewStore(resolver ModuleResolver, handlers ...ModuleEventHandler) *Store

NewStore creates a new store that will use the given resolver to resolve modules.

func (*Store) InstantiateModule

func (s *Store) InstantiateModule(name string) (Module, error)

InstantiateModule instantiates the given module. The name is resolved to a module definition using the store's ModuleResolver.

func (*Store) InstantiateModuleDefinition

func (s *Store) InstantiateModuleDefinition(name string, def ModuleDefinition) (Module, error)

InstantiateModuleDefinition instantiates the given module definition.

func (*Store) RegisterModule

func (s *Store) RegisterModule(name string, module Module)

RegisterModule registers an instantiated module with the store, replacing any existing module with the same name.

type Table

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

Table is a WASM table.

func NewTable

func NewTable(min, max uint32) Table

NewTable creates a new WASM table.

func (*Table) Entries

func (t *Table) Entries() []Function

Entries returns the table's entries.

func (*Table) Limits

func (t *Table) Limits() (min uint32, max uint32)

Limits returns the minimum and maximum size of the table in elements.

type Thread

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

A Thread carries information about a single WASM thread.

func NewDebugThread

func NewDebugThread(trace io.Writer, maxDepth uint) Thread

NewDebugThread creates a new, debuggable thread with the given tracer and max depth, if any.

func NewThread

func NewThread(maxDepth uint) Thread

NewThread creates a new thread with the given max depth, if any.

func (*Thread) Close

func (t *Thread) Close() error

Close closes the thread.

func (*Thread) Debug

func (t *Thread) Debug() bool

Debug returns true if this thread's frames should be recorded for debugging.

func (*Thread) Enter

func (t *Thread) Enter()

Enter pushes a new frame onto the thread's stack. Each call to Enter must be balanced with a call to Leave.

func (*Thread) EnterFrame

func (t *Thread) EnterFrame(f *Frame)

EnterFrame pushes a new frame onto the thread's stack. Each call to EnterFrame must be balanced with a call to LeaveFrame.

func (*Thread) Leave

func (t *Thread) Leave()

Leave pops the top of the thread's stack.

func (*Thread) LeaveFrame

func (t *Thread) LeaveFrame()

LeaveFrame pops the top of the thread's stack.

func (*Thread) MaxDepth

func (t *Thread) MaxDepth() uint

MaxDepth returns the maximum call stack depth, if any.

func (*Thread) Trace

func (t *Thread) Trace() (io.Writer, bool)

Trace returns the writer for this thread's tracer, if any.

type Trap

type Trap string

A Trap represents a WASM trap.

func TranslateRuntimeError

func TranslateRuntimeError(err runtime.Error) (Trap, bool)

TranslateRuntimeError is a utility function that translates between Go runtime errors and WASM traps.

func (Trap) Error

func (t Trap) Error() string

Jump to

Keyboard shortcuts

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