wasmer

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: GPL-3.0 Imports: 8 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
)

opcodes list

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 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 ForceInstallSighandlers

func ForceInstallSighandlers()

ForceInstallSighandlers triggers a forced installation of signal handlers in Wasmer 1

func GetLastError

func GetLastError() (string, error)

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

func SetOpcodeCosts

func SetOpcodeCosts(opcodeCosts *executor.WASMOpcodeCost)

SetOpcodeCosts sets gas costs globally for 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 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 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 ExportedFunctionCallInfo values

type ImportedFunctionError

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

ImportedFunctionError represents any kind of errors related to a WebAssembly imported function. It is returned by `Import` or `Imports` functions only.

func NewImportedFunctionError

func NewImportedFunctionError(functionName string, message string) *ImportedFunctionError

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

func (*ImportedFunctionError) Error

func (error *ImportedFunctionError) Error() string

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

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() executor.Memory

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 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 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 type 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
)

type WasmerExecutor

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

WasmerExecutor oversees the creation of Wasmer instances and execution.

func CreateExecutor

func CreateExecutor() (*WasmerExecutor, error)

CreateExecutor creates a new wasmer executor.

func (*WasmerExecutor) FunctionNames

func (wasmerExecutor *WasmerExecutor) FunctionNames() vmcommon.FunctionNames

FunctionNames returns the function names

func (*WasmerExecutor) IsInterfaceNil

func (wasmerExecutor *WasmerExecutor) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

func (*WasmerExecutor) NewInstanceFromCompiledCodeWithOptions

func (wasmerExecutor *WasmerExecutor) NewInstanceFromCompiledCodeWithOptions(
	compiledCode []byte,
	options executor.CompilationOptions,
) (executor.Instance, error)

NewInstanceFromCompiledCodeWithOptions creates a new Wasmer instance from precompiled machine code, respecting the provided options

func (*WasmerExecutor) NewInstanceWithOptions

func (wasmerExecutor *WasmerExecutor) NewInstanceWithOptions(
	contractCode []byte,
	options executor.CompilationOptions,
) (executor.Instance, error)

NewInstanceWithOptions creates a new Wasmer instance from WASM bytecode, respecting the provided options

func (*WasmerExecutor) SetOpcodeCosts

func (wasmerExecutor *WasmerExecutor) SetOpcodeCosts(opcodeCosts *executor.WASMOpcodeCost)

SetOpcodeCosts sets gas costs globally inside the Wasmer executor.

type WasmerExecutorFactory

type WasmerExecutorFactory struct{}

WasmerExecutorFactory builds Wasmer Executors.

func ExecutorFactory

func ExecutorFactory() *WasmerExecutorFactory

ExecutorFactory returns the Wasmer executor factory.

func (*WasmerExecutorFactory) CreateExecutor

CreateExecutor creates a new Executor instance.

func (*WasmerExecutorFactory) IsInterfaceNil

func (wef *WasmerExecutorFactory) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

type WasmerInstance

type WasmerInstance struct {
	AlreadyClean bool

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

	// The instance context.
	InstanceCtx InstanceContext
	// contains filtered or unexported fields
}

WasmerInstance represents a WebAssembly instance.

func NewInstanceFromCompiledCodeWithOptions

func NewInstanceFromCompiledCodeWithOptions(
	compiledCode []byte,
	options executor.CompilationOptions,
) (*WasmerInstance, error)

NewInstanceFromCompiledCodeWithOptions creates a new instance from compiled code

func NewInstanceWithOptions

func NewInstanceWithOptions(
	bytes []byte,
	options executor.CompilationOptions,
) (*WasmerInstance, error)

NewInstanceWithOptions creates a new instance from provided bytes & options

func (*WasmerInstance) Cache

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

Cache caches the instance

func (*WasmerInstance) CallFunction

func (instance *WasmerInstance) CallFunction(functionName string) error

CallFunction executes given function from loaded contract.

func (*WasmerInstance) Clean

func (instance *WasmerInstance) Clean() bool

Clean cleans instance

func (*WasmerInstance) GetBreakpointValue

func (instance *WasmerInstance) GetBreakpointValue() uint64

GetBreakpointValue returns the breakpoint value

func (*WasmerInstance) GetFunctionNames

func (instance *WasmerInstance) GetFunctionNames() []string

GetFunctionNames loads a list of contract function (endpoint) names. Required for validating reserved names.

func (*WasmerInstance) GetPointsUsed

func (instance *WasmerInstance) GetPointsUsed() uint64

GetPointsUsed returns the internal instance gas counter

func (*WasmerInstance) GetVMHooksPtr

func (instance *WasmerInstance) GetVMHooksPtr() uintptr

GetVMHooksPtr returns the VM hooks pointer

func (*WasmerInstance) HasFunction

func (instance *WasmerInstance) HasFunction(functionName string) bool

HasFunction checks if loaded contract has a function (endpoint) with given name.

func (*WasmerInstance) HasMemory

func (instance *WasmerInstance) HasMemory() bool

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

func (*WasmerInstance) ID

func (instance *WasmerInstance) ID() string

ID returns an identifier for the instance, unique at runtime

func (*WasmerInstance) IsAlreadyCleaned

func (instance *WasmerInstance) IsAlreadyCleaned() bool

IsAlreadyCleaned returns the internal field AlreadyClean

func (*WasmerInstance) IsFunctionImported

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

IsFunctionImported returns true if the instance imports the specified function

func (*WasmerInstance) IsInterfaceNil

func (instance *WasmerInstance) IsInterfaceNil() bool

IsInterfaceNil returns true if underlying object is nil

func (*WasmerInstance) MemDump

func (instance *WasmerInstance) MemDump() []byte

MemDump yields the entire contents of the memory. Only used in tests.

func (*WasmerInstance) MemGrow

func (instance *WasmerInstance) MemGrow(pages uint32) error

MemGrow allocates more pages to the current memory. Only called directly in tests.

func (*WasmerInstance) MemLength

func (instance *WasmerInstance) MemLength() uint32

MemLength returns the length of the allocated memory. Only called directly in tests.

func (*WasmerInstance) MemLoad

func (instance *WasmerInstance) MemLoad(memPtr executor.MemPtr, length executor.MemLength) ([]byte, error)

MemLoad returns the contents from the given offset of the WASM memory.

func (*WasmerInstance) MemStore

func (instance *WasmerInstance) MemStore(memPtr executor.MemPtr, data []byte) error

MemStore stores the given data in the WASM memory at the given offset.

func (*WasmerInstance) Reset

func (instance *WasmerInstance) Reset() bool

Reset resets the instance memories and globals

func (*WasmerInstance) SetBreakpointValue

func (instance *WasmerInstance) SetBreakpointValue(value uint64)

SetBreakpointValue sets the breakpoint value for the instance

func (*WasmerInstance) SetGasLimit

func (instance *WasmerInstance) SetGasLimit(gasLimit uint64)

SetGasLimit sets the gas limit for the instance

func (*WasmerInstance) SetPointsUsed

func (instance *WasmerInstance) SetPointsUsed(points uint64)

SetPointsUsed sets the internal instance gas counter

func (*WasmerInstance) SetVMHooksPtr

func (instance *WasmerInstance) SetVMHooksPtr(vmHooksPtr uintptr)

SetVMHooksPtr sets the VM hooks pointer

func (*WasmerInstance) ValidateFunctionArities

func (instance *WasmerInstance) ValidateFunctionArities() error

ValidateFunctionArities checks that no function (endpoint) of the given contract has any parameters or returns any result. All arguments and results should be transferred via the import functions.

Jump to

Keyboard shortcuts

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