wasmer

package
v1.2.62 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2023 License: GPL-3.0 Imports: 6 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
)
View Source
const OPCODE_COUNT = 448

Variables

View Source
var ErrCachingFailed = errors.New("instance caching failed")
View Source
var ErrFailedCacheImports = errors.New("could not cache imports")
View Source
var ErrFailedInstantiation = errors.New("could not create wasmer instance")
View Source
var ErrInvalidBytecode = errors.New("invalid bytecode")

Functions

func ForceInstallSighandlers added in v1.2.53

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 SetImports

func SetImports(imports *Imports) error

func SetOpcodeCosts

func SetOpcodeCosts(opcode_costs *[OPCODE_COUNT]uint32)

func SetSIGSEGVPassthrough

func SetSIGSEGVPassthrough()

SetSIGSEGVPassthrough controls a Wasmer flag.

Types

type CompilationOptions

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

type ExportSignaturesMap

type ExportSignaturesMap map[string]*ExportedFunctionSignature

type ExportedFunctionCallback

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

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]ExportedFunctionCallback

type Import

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

Import represents an WebAssembly instance imported function.

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 Imports

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

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

func NewImports

func NewImports() *Imports

NewImports constructs a new empty `Imports`.

func (*Imports) Append

func (imports *Imports) Append(importName string, implementation interface{}, cgoPointer unsafe.Pointer) (*Imports, error)

Append adds a new imported function to the current set.

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

func (*Imports) Names

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

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
	// contains filtered or unexported fields
}

Instance represents a WebAssembly instance.

func NewInstanceFromCompiledCodeWithOptions

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

func NewInstanceWithOptions

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

func (*Instance) Cache

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

func (*Instance) Clean

func (instance *Instance) Clean()

func (*Instance) GetBreakpointValue

func (instance *Instance) GetBreakpointValue() uint64

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

func (*Instance) GetSignature

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

GetSignature returns the signature for the given functionName

func (*Instance) HasMemory

func (instance *Instance) HasMemory() bool

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

func (*Instance) IsFunctionImported

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

IsFunctionImported returns true if the instance imports the specified function

func (*Instance) SetBreakpointValue

func (instance *Instance) SetBreakpointValue(value uint64)

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)

func (*Instance) SetPointsUsed

func (instance *Instance) SetPointsUsed(points uint64)

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 NewInstanceContext

func NewInstanceContext(ctx *cWasmerInstanceContextT, mem Memory) *InstanceContext

NewInstanceContext creates a new wasmer context given a cWasmerInstance and a memory

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
	SetContextData(data uintptr)
	GetPointsUsed() uint64
	SetPointsUsed(points uint64)
	SetGasLimit(gasLimit uint64)
	SetBreakpointValue(value uint64)
	GetBreakpointValue() uint64
	Cache() ([]byte, error)
	Clean()
	GetExports() ExportsMap
	GetSignature(functionName string) (*ExportedFunctionSignature, bool)
	GetData() uintptr
	GetInstanceCtxMemory() MemoryHandler
	GetMemory() MemoryHandler
	IsFunctionImported(name string) bool
}

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

func (*Memory) Grow

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

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

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()
}

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

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