wasmer

package
v1.4.74 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package wasmer is a Go library to run WebAssembly binaries.

Index

Constants

View Source
const (
	OpcodeUnreachable = iota
	OpcodeNop
	OpcodeBlock
	OpcodeLoop
	OpcodeIf
	OpcodeElse
	OpcodeEnd
	OpcodeBr
	OpcodeBrIf
	OpcodeBrTable
	OpcodeReturn
	OpcodeCall
	OpcodeCallIndirect
	OpcodeDrop
	OpcodeSelect
	OpcodeTypedSelect
	OpcodeLocalGet
	OpcodeLocalSet
	OpcodeLocalTee
	OpcodeGlobalGet
	OpcodeGlobalSet
	OpcodeI32Load
	OpcodeI64Load
	OpcodeF32Load
	OpcodeF64Load
	OpcodeI32Load8S
	OpcodeI32Load8U
	OpcodeI32Load16S
	OpcodeI32Load16U
	OpcodeI64Load8S
	OpcodeI64Load8U
	OpcodeI64Load16S
	OpcodeI64Load16U
	OpcodeI64Load32S
	OpcodeI64Load32U
	OpcodeI32Store
	OpcodeI64Store
	OpcodeF32Store
	OpcodeF64Store
	OpcodeI32Store8
	OpcodeI32Store16
	OpcodeI64Store8
	OpcodeI64Store16
	OpcodeI64Store32
	OpcodeMemorySize
	OpcodeMemoryGrow
	OpcodeI32Const
	OpcodeI64Const
	OpcodeF32Const
	OpcodeF64Const
	OpcodeRefNull
	OpcodeRefIsNull
	OpcodeRefFunc
	OpcodeI32Eqz
	OpcodeI32Eq
	OpcodeI32Ne
	OpcodeI32LtS
	OpcodeI32LtU
	OpcodeI32GtS
	OpcodeI32GtU
	OpcodeI32LeS
	OpcodeI32LeU
	OpcodeI32GeS
	OpcodeI32GeU
	OpcodeI64Eqz
	OpcodeI64Eq
	OpcodeI64Ne
	OpcodeI64LtS
	OpcodeI64LtU
	OpcodeI64GtS
	OpcodeI64GtU
	OpcodeI64LeS
	OpcodeI64LeU
	OpcodeI64GeS
	OpcodeI64GeU
	OpcodeF32Eq
	OpcodeF32Ne
	OpcodeF32Lt
	OpcodeF32Gt
	OpcodeF32Le
	OpcodeF32Ge
	OpcodeF64Eq
	OpcodeF64Ne
	OpcodeF64Lt
	OpcodeF64Gt
	OpcodeF64Le
	OpcodeF64Ge
	OpcodeI32Clz
	OpcodeI32Ctz
	OpcodeI32Popcnt
	OpcodeI32Add
	OpcodeI32Sub
	OpcodeI32Mul
	OpcodeI32DivS
	OpcodeI32DivU
	OpcodeI32RemS
	OpcodeI32RemU
	OpcodeI32And
	OpcodeI32Or
	OpcodeI32Xor
	OpcodeI32Shl
	OpcodeI32ShrS
	OpcodeI32ShrU
	OpcodeI32Rotl
	OpcodeI32Rotr
	OpcodeI64Clz
	OpcodeI64Ctz
	OpcodeI64Popcnt
	OpcodeI64Add
	OpcodeI64Sub
	OpcodeI64Mul
	OpcodeI64DivS
	OpcodeI64DivU
	OpcodeI64RemS
	OpcodeI64RemU
	OpcodeI64And
	OpcodeI64Or
	OpcodeI64Xor
	OpcodeI64Shl
	OpcodeI64ShrS
	OpcodeI64ShrU
	OpcodeI64Rotl
	OpcodeI64Rotr
	OpcodeF32Abs
	OpcodeF32Neg
	OpcodeF32Ceil
	OpcodeF32Floor
	OpcodeF32Trunc
	OpcodeF32Nearest
	OpcodeF32Sqrt
	OpcodeF32Add
	OpcodeF32Sub
	OpcodeF32Mul
	OpcodeF32Div
	OpcodeF32Min
	OpcodeF32Max
	OpcodeF32Copysign
	OpcodeF64Abs
	OpcodeF64Neg
	OpcodeF64Ceil
	OpcodeF64Floor
	OpcodeF64Trunc
	OpcodeF64Nearest
	OpcodeF64Sqrt
	OpcodeF64Add
	OpcodeF64Sub
	OpcodeF64Mul
	OpcodeF64Div
	OpcodeF64Min
	OpcodeF64Max
	OpcodeF64Copysign
	OpcodeI32WrapI64
	OpcodeI32TruncF32S
	OpcodeI32TruncF32U
	OpcodeI32TruncF64S
	OpcodeI32TruncF64U
	OpcodeI64ExtendI32S
	OpcodeI64ExtendI32U
	OpcodeI64TruncF32S
	OpcodeI64TruncF32U
	OpcodeI64TruncF64S
	OpcodeI64TruncF64U
	OpcodeF32ConvertI32S
	OpcodeF32ConvertI32U
	OpcodeF32ConvertI64S
	OpcodeF32ConvertI64U
	OpcodeF32DemoteF64
	OpcodeF64ConvertI32S
	OpcodeF64ConvertI32U
	OpcodeF64ConvertI64S
	OpcodeF64ConvertI64U
	OpcodeF64PromoteF32
	OpcodeI32ReinterpretF32
	OpcodeI64ReinterpretF64
	OpcodeF32ReinterpretI32
	OpcodeF64ReinterpretI64
	OpcodeI32Extend8S
	OpcodeI32Extend16S
	OpcodeI64Extend8S
	OpcodeI64Extend16S
	OpcodeI64Extend32S
	OpcodeI32TruncSatF32S
	OpcodeI32TruncSatF32U
	OpcodeI32TruncSatF64S
	OpcodeI32TruncSatF64U
	OpcodeI64TruncSatF32S
	OpcodeI64TruncSatF32U
	OpcodeI64TruncSatF64S
	OpcodeI64TruncSatF64U
	OpcodeMemoryInit
	OpcodeDataDrop
	OpcodeMemoryCopy
	OpcodeMemoryFill
	OpcodeTableInit
	OpcodeElemDrop
	OpcodeTableCopy
	OpcodeTableFill
	OpcodeTableGet
	OpcodeTableSet
	OpcodeTableGrow
	OpcodeTableSize
	OpcodeAtomicNotify
	OpcodeI32AtomicWait
	OpcodeI64AtomicWait
	OpcodeAtomicFence
	OpcodeI32AtomicLoad
	OpcodeI64AtomicLoad
	OpcodeI32AtomicLoad8U
	OpcodeI32AtomicLoad16U
	OpcodeI64AtomicLoad8U
	OpcodeI64AtomicLoad16U
	OpcodeI64AtomicLoad32U
	OpcodeI32AtomicStore
	OpcodeI64AtomicStore
	OpcodeI32AtomicStore8
	OpcodeI32AtomicStore16
	OpcodeI64AtomicStore8
	OpcodeI64AtomicStore16
	OpcodeI64AtomicStore32
	OpcodeI32AtomicRmwAdd
	OpcodeI64AtomicRmwAdd
	OpcodeI32AtomicRmw8AddU
	OpcodeI32AtomicRmw16AddU
	OpcodeI64AtomicRmw8AddU
	OpcodeI64AtomicRmw16AddU
	OpcodeI64AtomicRmw32AddU
	OpcodeI32AtomicRmwSub
	OpcodeI64AtomicRmwSub
	OpcodeI32AtomicRmw8SubU
	OpcodeI32AtomicRmw16SubU
	OpcodeI64AtomicRmw8SubU
	OpcodeI64AtomicRmw16SubU
	OpcodeI64AtomicRmw32SubU
	OpcodeI32AtomicRmwAnd
	OpcodeI64AtomicRmwAnd
	OpcodeI32AtomicRmw8AndU
	OpcodeI32AtomicRmw16AndU
	OpcodeI64AtomicRmw8AndU
	OpcodeI64AtomicRmw16AndU
	OpcodeI64AtomicRmw32AndU
	OpcodeI32AtomicRmwOr
	OpcodeI64AtomicRmwOr
	OpcodeI32AtomicRmw8OrU
	OpcodeI32AtomicRmw16OrU
	OpcodeI64AtomicRmw8OrU
	OpcodeI64AtomicRmw16OrU
	OpcodeI64AtomicRmw32OrU
	OpcodeI32AtomicRmwXor
	OpcodeI64AtomicRmwXor
	OpcodeI32AtomicRmw8XorU
	OpcodeI32AtomicRmw16XorU
	OpcodeI64AtomicRmw8XorU
	OpcodeI64AtomicRmw16XorU
	OpcodeI64AtomicRmw32XorU
	OpcodeI32AtomicRmwXchg
	OpcodeI64AtomicRmwXchg
	OpcodeI32AtomicRmw8XchgU
	OpcodeI32AtomicRmw16XchgU
	OpcodeI64AtomicRmw8XchgU
	OpcodeI64AtomicRmw16XchgU
	OpcodeI64AtomicRmw32XchgU
	OpcodeI32AtomicRmwCmpxchg
	OpcodeI64AtomicRmwCmpxchg
	OpcodeI32AtomicRmw8CmpxchgU
	OpcodeI32AtomicRmw16CmpxchgU
	OpcodeI64AtomicRmw8CmpxchgU
	OpcodeI64AtomicRmw16CmpxchgU
	OpcodeI64AtomicRmw32CmpxchgU
	OpcodeV128Load
	OpcodeV128Store
	OpcodeV128Const
	OpcodeI8x16Splat
	OpcodeI8x16ExtractLaneS
	OpcodeI8x16ExtractLaneU
	OpcodeI8x16ReplaceLane
	OpcodeI16x8Splat
	OpcodeI16x8ExtractLaneS
	OpcodeI16x8ExtractLaneU
	OpcodeI16x8ReplaceLane
	OpcodeI32x4Splat
	OpcodeI32x4ExtractLane
	OpcodeI32x4ReplaceLane
	OpcodeI64x2Splat
	OpcodeI64x2ExtractLane
	OpcodeI64x2ReplaceLane
	OpcodeF32x4Splat
	OpcodeF32x4ExtractLane
	OpcodeF32x4ReplaceLane
	OpcodeF64x2Splat
	OpcodeF64x2ExtractLane
	OpcodeF64x2ReplaceLane
	OpcodeI8x16Eq
	OpcodeI8x16Ne
	OpcodeI8x16LtS
	OpcodeI8x16LtU
	OpcodeI8x16GtS
	OpcodeI8x16GtU
	OpcodeI8x16LeS
	OpcodeI8x16LeU
	OpcodeI8x16GeS
	OpcodeI8x16GeU
	OpcodeI16x8Eq
	OpcodeI16x8Ne
	OpcodeI16x8LtS
	OpcodeI16x8LtU
	OpcodeI16x8GtS
	OpcodeI16x8GtU
	OpcodeI16x8LeS
	OpcodeI16x8LeU
	OpcodeI16x8GeS
	OpcodeI16x8GeU
	OpcodeI32x4Eq
	OpcodeI32x4Ne
	OpcodeI32x4LtS
	OpcodeI32x4LtU
	OpcodeI32x4GtS
	OpcodeI32x4GtU
	OpcodeI32x4LeS
	OpcodeI32x4LeU
	OpcodeI32x4GeS
	OpcodeI32x4GeU
	OpcodeF32x4Eq
	OpcodeF32x4Ne
	OpcodeF32x4Lt
	OpcodeF32x4Gt
	OpcodeF32x4Le
	OpcodeF32x4Ge
	OpcodeF64x2Eq
	OpcodeF64x2Ne
	OpcodeF64x2Lt
	OpcodeF64x2Gt
	OpcodeF64x2Le
	OpcodeF64x2Ge
	OpcodeV128Not
	OpcodeV128And
	OpcodeV128AndNot
	OpcodeV128Or
	OpcodeV128Xor
	OpcodeV128Bitselect
	OpcodeI8x16Neg
	OpcodeI8x16AnyTrue
	OpcodeI8x16AllTrue
	OpcodeI8x16Shl
	OpcodeI8x16ShrS
	OpcodeI8x16ShrU
	OpcodeI8x16Add
	OpcodeI8x16AddSaturateS
	OpcodeI8x16AddSaturateU
	OpcodeI8x16Sub
	OpcodeI8x16SubSaturateS
	OpcodeI8x16SubSaturateU
	OpcodeI8x16MinS
	OpcodeI8x16MinU
	OpcodeI8x16MaxS
	OpcodeI8x16MaxU
	OpcodeI8x16Mul
	OpcodeI16x8Neg
	OpcodeI16x8AnyTrue
	OpcodeI16x8AllTrue
	OpcodeI16x8Shl
	OpcodeI16x8ShrS
	OpcodeI16x8ShrU
	OpcodeI16x8Add
	OpcodeI16x8AddSaturateS
	OpcodeI16x8AddSaturateU
	OpcodeI16x8Sub
	OpcodeI16x8SubSaturateS
	OpcodeI16x8SubSaturateU
	OpcodeI16x8Mul
	OpcodeI16x8MinS
	OpcodeI16x8MinU
	OpcodeI16x8MaxS
	OpcodeI16x8MaxU
	OpcodeI32x4Neg
	OpcodeI32x4AnyTrue
	OpcodeI32x4AllTrue
	OpcodeI32x4Shl
	OpcodeI32x4ShrS
	OpcodeI32x4ShrU
	OpcodeI32x4Add
	OpcodeI32x4Sub
	OpcodeI32x4Mul
	OpcodeI32x4MinS
	OpcodeI32x4MinU
	OpcodeI32x4MaxS
	OpcodeI32x4MaxU
	OpcodeI64x2Neg
	OpcodeI64x2AnyTrue
	OpcodeI64x2AllTrue
	OpcodeI64x2Shl
	OpcodeI64x2ShrS
	OpcodeI64x2ShrU
	OpcodeI64x2Add
	OpcodeI64x2Sub
	OpcodeI64x2Mul
	OpcodeF32x4Abs
	OpcodeF32x4Neg
	OpcodeF32x4Sqrt
	OpcodeF32x4Add
	OpcodeF32x4Sub
	OpcodeF32x4Mul
	OpcodeF32x4Div
	OpcodeF32x4Min
	OpcodeF32x4Max
	OpcodeF64x2Abs
	OpcodeF64x2Neg
	OpcodeF64x2Sqrt
	OpcodeF64x2Add
	OpcodeF64x2Sub
	OpcodeF64x2Mul
	OpcodeF64x2Div
	OpcodeF64x2Min
	OpcodeF64x2Max
	OpcodeI32x4TruncSatF32x4S
	OpcodeI32x4TruncSatF32x4U
	OpcodeI64x2TruncSatF64x2S
	OpcodeI64x2TruncSatF64x2U
	OpcodeF32x4ConvertI32x4S
	OpcodeF32x4ConvertI32x4U
	OpcodeF64x2ConvertI64x2S
	OpcodeF64x2ConvertI64x2U
	OpcodeV8x16Swizzle
	OpcodeV8x16Shuffle
	OpcodeV8x16LoadSplat
	OpcodeV16x8LoadSplat
	OpcodeV32x4LoadSplat
	OpcodeV64x2LoadSplat
	OpcodeI8x16NarrowI16x8S
	OpcodeI8x16NarrowI16x8U
	OpcodeI16x8NarrowI32x4S
	OpcodeI16x8NarrowI32x4U
	OpcodeI16x8WidenLowI8x16S
	OpcodeI16x8WidenHighI8x16S
	OpcodeI16x8WidenLowI8x16U
	OpcodeI16x8WidenHighI8x16U
	OpcodeI32x4WidenLowI16x8S
	OpcodeI32x4WidenHighI16x8S
	OpcodeI32x4WidenLowI16x8U
	OpcodeI32x4WidenHighI16x8U
	OpcodeI16x8Load8x8S
	OpcodeI16x8Load8x8U
	OpcodeI32x4Load16x4S
	OpcodeI32x4Load16x4U
	OpcodeI64x2Load32x2S
	OpcodeI64x2Load32x2U
	OpcodeI8x16RoundingAverageU
	OpcodeI16x8RoundingAverageU
	OpcodeLocalAllocate
)

These constants are used as indices in the an opcode costs array

View Source
const OpcodeCount = 448

OpcodeCount is the total number of WASM opcodes currently supported by Wasmer

Variables

View Source
var ErrCachingFailed = errors.New("instance caching failed")

ErrCachingFailed indicates that creating the precompilation cache of an instance has failed

View Source
var ErrExportNotFound = errors.New("export not found")

ErrExportNotFound indicates that the requested name was not found among the exports

View Source
var ErrFailedCacheImports = errors.New("could not cache imports")

ErrFailedCacheImports indicates that the imports could not be cached

View Source
var ErrFailedInstantiation = errors.New("could not create wasmer instance")

ErrFailedInstantiation indicates that a Wasmer instance could not be created

View Source
var ErrInvalidBytecode = errors.New("invalid bytecode")

ErrInvalidBytecode indicates that the bytecode is invalid

Functions

func GetLastError

func GetLastError() (string, error)

GetLastError returns the last error message if any, otherwise returns an error.

func SetImports

func SetImports(imports *Imports) error

SetImports creates a static imports object and sets it into Wasmer

func SetOpcodeCosts

func SetOpcodeCosts(opcodeCosts *[OpcodeCount]uint32)

SetOpcodeCosts sets the opcode costs in Wasmer

func SetRkyvSerializationEnabled

func SetRkyvSerializationEnabled(enabled bool)

SetRkyvSerializationEnabled enables or disables RKYV serialization of instances in Wasmer

func SetSIGSEGVPassthrough

func SetSIGSEGVPassthrough()

SetSIGSEGVPassthrough instructs Wasmer to never register a handler for SIGSEGV. Only has effect if called before creating the first Wasmer instance since the process started. Calling this function after the first Wasmer instance will not unregister the signal handler set by Wasmer.

Types

type CompilationOptions

type CompilationOptions struct {
	GasLimit           uint64
	UnmeteredLocals    uint64
	MaxMemoryGrow      uint64
	MaxMemoryGrowDelta uint64
	OpcodeTrace        bool
	Metering           bool
	RuntimeBreakpoints bool
}

CompilationOptions contains options for creating a Wasmer instance

type ExportSignaturesMap

type ExportSignaturesMap map[string]*ExportedFunctionSignature

ExportSignaturesMap is a map of names to ExportedFunctionSignatures

type ExportedFunctionCallInfo

type ExportedFunctionCallInfo struct {
	FuncName       string
	InputArity     cUint32T
	InputSignature []cWasmerValueTag
	OutputArity    cUint32T
}

ExportedFunctionCallInfo contains information required to call an exported WASM function

type ExportedFunctionCallback

type ExportedFunctionCallback func(...interface{}) (Value, error)

ExportedFunctionCallback is the type of an exported WASM function

type ExportedFunctionError

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

ExportedFunctionError represents any kind of errors related to a WebAssembly exported function. It is returned by `Instance` functions only.

func NewExportedFunctionError

func NewExportedFunctionError(functionName string, message string) *ExportedFunctionError

NewExportedFunctionError constructs a new `ExportedFunctionError`, where `functionName` is the name of the exported function, and `message` is the error message. If the error message contains `%s`, then this parameter will be replaced by `functionName`.

func (*ExportedFunctionError) Error

func (error *ExportedFunctionError) Error() string

ExportedFunctionError is an actual error. The `Error` function returns the error message.

type ExportedFunctionSignature

type ExportedFunctionSignature struct {
	InputArity  int
	OutputArity int
}

ExportedFunctionSignature holds information about the input/output arities of an exported function

type ExportsMap

type ExportsMap map[string]*ExportedFunctionCallInfo

ExportsMap is a map of names to ExportedFunctionCallback values

type Import

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

Import represents an WebAssembly instance imported function.

type Imports

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

Imports represents a set of imported functions for a WebAssembly instance.

func ConvertImports

func ConvertImports(eiFunctions *vmhooksmeta.EIFunctions) *Imports

ConvertImports creates an Imports object from an EIFunctions struct

func NewImports

func NewImports() *Imports

NewImports constructs a new empty `Imports`.

func (*Imports) Close

func (imports *Imports) Close()

Close closes/frees all imported functions that have been registered by Wasmer.

func (*Imports) Count

func (imports *Imports) Count() int

Count returns the number of imports

func (*Imports) Names

func (imports *Imports) Names() vmcommon.FunctionNames

Names returns a map of function names

func (*Imports) Namespace

func (imports *Imports) Namespace(namespace string) *Imports

Namespace changes the current namespace of the next imported functions.

type Instance

type Instance struct {

	// All functions exported by the WebAssembly instance, indexed
	// by their name as a string. An exported function is a
	// regular variadic Go closure. Arguments are untyped. Since
	// WebAssembly only supports: `i32`, `i64`, `f32` and `f64`
	// types, the accepted Go types are: `int8`, `uint8`, `int16`,
	// `uint16`, `int32`, `uint32`, `int64`, `int`, `uint`, `float32`
	// and `float64`. In addition to those types, the `Value` type
	// (from this project) is accepted. The conversion from a Go
	// value to a WebAssembly value is done automatically except for
	// the `Value` type (where type is coerced, that's the intent
	// here). The WebAssembly type is automatically inferred. Note
	// that the returned value is of kind `Value`, and not a
	// standard Go type.
	Exports ExportsMap

	Signatures ExportSignaturesMap

	// The exported memory of a WebAssembly instance.
	Memory MemoryHandler

	Data        *uintptr
	DataPointer unsafe.Pointer

	InstanceCtx InstanceContext

	AlreadyClean bool
	// contains filtered or unexported fields
}

Instance represents a WebAssembly instance.

func NewInstanceFromCompiledCodeWithOptions

func NewInstanceFromCompiledCodeWithOptions(
	compiledCode []byte,
	options CompilationOptions,
) (*Instance, error)

NewInstanceFromCompiledCodeWithOptions creates a new Wasmer instance from precompiled code with the provided compilation options

func NewInstanceWithOptions

func NewInstanceWithOptions(
	bytes []byte,
	options CompilationOptions,
) (*Instance, error)

NewInstanceWithOptions creates a new Wasmer instance from WASM bytecode with the provided compilation options

func (*Instance) AlreadyCleaned

func (instance *Instance) AlreadyCleaned() bool

AlreadyCleaned returns the internal field AlreadyClean

func (*Instance) Cache

func (instance *Instance) Cache() ([]byte, error)

Cache caches the instance

func (*Instance) CallFunction

func (instance *Instance) CallFunction(funcName string) (Value, error)

CallFunction calls an exported function of the instance

func (*Instance) Clean

func (instance *Instance) Clean() bool

Clean cleans instance

func (*Instance) GetBreakpointValue

func (instance *Instance) GetBreakpointValue() uint64

GetBreakpointValue returns the breakpoint value

func (*Instance) GetData

func (instance *Instance) GetData() uintptr

GetData returns a pointer for the current instance's data

func (*Instance) GetExports

func (instance *Instance) GetExports() ExportsMap

GetExports returns the exports map for the current instance

func (*Instance) GetInstanceCtxMemory

func (instance *Instance) GetInstanceCtxMemory() MemoryHandler

GetInstanceCtxMemory returns the memory for the instance context

func (*Instance) GetMemory

func (instance *Instance) GetMemory() MemoryHandler

GetMemory returns the memory for the instance

func (*Instance) GetPointsUsed

func (instance *Instance) GetPointsUsed() uint64

GetPointsUsed returns the internal instance gas counter

func (*Instance) GetSignature

func (instance *Instance) GetSignature(functionName string) (*ExportedFunctionSignature, bool)

GetSignature returns the signature for the given functionName

func (*Instance) HasFunction

func (instance *Instance) HasFunction(funcName string) bool

HasFunction checks whether the instance has a specific exported function

func (*Instance) HasMemory

func (instance *Instance) HasMemory() bool

HasMemory checks whether the instance has at least one exported memory.

func (*Instance) ID

func (instance *Instance) ID() string

ID returns an identifier for the instance, unique at runtime

func (*Instance) IsFunctionImported

func (instance *Instance) IsFunctionImported(name string) bool

IsFunctionImported returns true if the instance imports the specified function

func (*Instance) IsInterfaceNil

func (instance *Instance) IsInterfaceNil() bool

IsInterfaceNil returns true if underlying object is nil

func (*Instance) Reset

func (instance *Instance) Reset() bool

Reset resets the instance memories and globals

func (*Instance) SetBreakpointValue

func (instance *Instance) SetBreakpointValue(value uint64)

SetBreakpointValue sets the breakpoint value for the instance

func (*Instance) SetContextData

func (instance *Instance) SetContextData(data uintptr)

SetContextData assigns a data that can be used by all imported functions. Indeed, each imported function receives as its first argument an instance context (see `InstanceContext`). An instance context can hold a pointer to any kind of data. It is important to understand that this data is shared by all imported function, it's global to the instance.

func (*Instance) SetGasLimit

func (instance *Instance) SetGasLimit(gasLimit uint64)

SetGasLimit sets the gas limit for the instance

func (*Instance) SetMemory

func (instance *Instance) SetMemory(data []byte) bool

SetMemory sets the memory for the instance returns true if success

func (*Instance) SetPointsUsed

func (instance *Instance) SetPointsUsed(points uint64)

SetPointsUsed sets the internal instance gas counter

type InstanceContext

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

InstanceContext represents a way to access instance API from within an imported context.

func IntoInstanceContext

func IntoInstanceContext(instanceContext unsafe.Pointer) InstanceContext

IntoInstanceContext casts the first `context unsafe.Pointer` argument of an imported function into an `InstanceContext`.

func IntoInstanceContextDirect

func IntoInstanceContextDirect(instanceContext *cWasmerInstanceContextT) InstanceContext

IntoInstanceContextDirect retrieves the Wasmer instance context directly from the Wasmer instance. This context can be stored as long as the instance itself.

func (*InstanceContext) Data

func (instanceContext *InstanceContext) Data() unsafe.Pointer

Data returns the instance context data as an `unsafe.Pointer`. It's up to the user to cast it appropriately as a pointer to a data.

func (*InstanceContext) Memory

func (instanceContext *InstanceContext) Memory() MemoryHandler

Memory returns the current instance memory.

type InstanceError

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

InstanceError represents any kind of errors related to a WebAssembly instance. It is returned by `Instance` functions only.

func NewInstanceError

func NewInstanceError(message string) *InstanceError

NewInstanceError constructs a new `InstanceError`.

func (*InstanceError) Error

func (error *InstanceError) Error() string

`InstanceError` is an actual error. The `Error` function returns the error message.

type InstanceHandler

type InstanceHandler interface {
	HasMemory() bool
	HasFunction(funcName string) bool
	CallFunction(funcName string) (Value, error)
	SetContextData(data uintptr)
	GetPointsUsed() uint64
	SetPointsUsed(points uint64)
	SetGasLimit(gasLimit uint64)
	SetBreakpointValue(value uint64)
	GetBreakpointValue() uint64
	Cache() ([]byte, error)
	Clean() bool
	AlreadyCleaned() bool
	GetExports() ExportsMap
	GetSignature(functionName string) (*ExportedFunctionSignature, bool)
	GetData() uintptr
	GetInstanceCtxMemory() MemoryHandler
	GetMemory() MemoryHandler
	SetMemory(data []byte) bool
	IsFunctionImported(name string) bool
	IsInterfaceNil() bool
	Reset() bool
	ID() string
}

InstanceHandler defines the functionality of a Wasmer instance

type Memory

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

Memory represents an exported memory of a WebAssembly instance. To read and write data, please see the `Data` function.

func (*Memory) Data

func (memory *Memory) Data() []byte

Data returns a slice of bytes over the WebAssembly memory.

func (*Memory) Destroy

func (memory *Memory) Destroy()

Destroy destroys inner memory

func (*Memory) Grow

func (memory *Memory) Grow(numberOfPages uint32) error

Grow the memory by a number of pages (65kb each).

func (*Memory) IsInterfaceNil

func (memory *Memory) IsInterfaceNil() bool

IsInterfaceNil returns true if underlying object is nil

func (*Memory) Length

func (memory *Memory) Length() uint32

Length calculates the memory length (in bytes).

type MemoryError

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

MemoryError represents any kind of errors related to a WebAssembly memory. It is returned by `Memory` functions only.

func NewMemoryError

func NewMemoryError(message string) *MemoryError

NewMemoryError constructs a new `MemoryError`.

func (*MemoryError) Error

func (error *MemoryError) Error() string

`MemoryError` is an actual error. The `Error` function returns the error message.

type MemoryHandler

type MemoryHandler interface {
	Length() uint32
	Data() []byte
	Grow(pages uint32) error
	Destroy()
	IsInterfaceNil() bool
}

MemoryHandler defines the functionality of the memory of a Wasmer instance

type Value

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

Value represents a WebAssembly value of a particular type.

func I32

func I32(value int32) Value

I32 constructs a WebAssembly value of type `i32`.

func I64

func I64(value int64) Value

I64 constructs a WebAssembly value of type `i64`.

func Void

func Void() Value

Void constructs an empty WebAssembly value.

func (Value) GetType

func (value Value) GetType() ValueType

GetType gets the type of the WebAssembly value.

func (Value) IsVoid

func (value Value) IsVoid() bool

IsVoid returns true if the value is void

func (Value) String

func (value Value) String() string

String formats the WebAssembly value as a Go string.

func (Value) ToI32

func (value Value) ToI32() int32

ToI32 reads the WebAssembly value bits as an `int32`. The WebAssembly value type is ignored.

func (Value) ToI64

func (value Value) ToI64() int64

ToI64 reads the WebAssembly value bits as an `int64`. The WebAssembly value type is ignored.

func (Value) ToVoid

func (value Value) ToVoid() interface{}

ToVoid reads the WebAssembly value bits as a `nil`. The WebAssembly value type is ignored.

type ValueType

type ValueType int

ValueType represents the `Value` type.

const (
	// TypeI32 represents the WebAssembly `i32` type.
	TypeI32 ValueType = iota

	// TypeI64 represents the WebAssembly `i64` type.
	TypeI64

	// TypeVoid represents nothing.
	// WebAssembly doesn't have “void” type, but it is introduced
	// here to represent the returned value of a WebAssembly exported
	// function that returns nothing.
	TypeVoid
)

Jump to

Keyboard shortcuts

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