wasmer2

package
v1.5.21 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: GPL-3.0 Imports: 10 Imported by: 1

Documentation

Overview

Package wasmer2 is a Go library to run WebAssembly binaries.

Index

Constants

This section is empty.

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 GetLastError

func GetLastError() (string, error)

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

func SetLogLevel

func SetLogLevel(logLevel LogLevel)

SetLogLevel sets the log level for the Executor.

Types

type LogLevel

type LogLevel uint64

Executor logger.

const (
	LogLevelOff LogLevel = iota
	LogLevelError
	LogLevelWarn
	LogLevelInfo
	LogLevelDebug
	LogLevelTrace
)

type OpcodeCost

type OpcodeCost struct {
	Block              uint32
	Br                 uint32
	BrIf               uint32
	BrTable            uint32
	Call               uint32
	CallIndirect       uint32
	Catch              uint32
	CatchAll           uint32
	Delegate           uint32
	Drop               uint32
	Else               uint32
	End                uint32
	GlobalGet          uint32
	GlobalSet          uint32
	I32Add             uint32
	I32And             uint32
	I32Clz             uint32
	I32Const           uint32
	I32Ctz             uint32
	I32DivS            uint32
	I32DivU            uint32
	I32Eq              uint32
	I32Eqz             uint32
	I32Extend16S       uint32
	I32Extend8S        uint32
	I32GeS             uint32
	I32GeU             uint32
	I32GtS             uint32
	I32GtU             uint32
	I32LeS             uint32
	I32LeU             uint32
	I32Load            uint32
	I32Load16S         uint32
	I32Load16U         uint32
	I32Load8S          uint32
	I32Load8U          uint32
	I32LtS             uint32
	I32LtU             uint32
	I32Mul             uint32
	I32Ne              uint32
	I32Or              uint32
	I32Popcnt          uint32
	I32RemS            uint32
	I32RemU            uint32
	I32Rotl            uint32
	I32Rotr            uint32
	I32Shl             uint32
	I32ShrS            uint32
	I32ShrU            uint32
	I32Store           uint32
	I32Store16         uint32
	I32Store8          uint32
	I32Sub             uint32
	I32WrapI64         uint32
	I32Xor             uint32
	I64Add             uint32
	I64And             uint32
	I64Clz             uint32
	I64Const           uint32
	I64Ctz             uint32
	I64DivS            uint32
	I64DivU            uint32
	I64Eq              uint32
	I64Eqz             uint32
	I64Extend16S       uint32
	I64Extend32S       uint32
	I64Extend8S        uint32
	I64ExtendI32S      uint32
	I64ExtendI32U      uint32
	I64GeS             uint32
	I64GeU             uint32
	I64GtS             uint32
	I64GtU             uint32
	I64LeS             uint32
	I64LeU             uint32
	I64Load            uint32
	I64Load16S         uint32
	I64Load16U         uint32
	I64Load32S         uint32
	I64Load32U         uint32
	I64Load8S          uint32
	I64Load8U          uint32
	I64LtS             uint32
	I64LtU             uint32
	I64Mul             uint32
	I64Ne              uint32
	I64Or              uint32
	I64Popcnt          uint32
	I64RemS            uint32
	I64RemU            uint32
	I64Rotl            uint32
	I64Rotr            uint32
	I64Shl             uint32
	I64ShrS            uint32
	I64ShrU            uint32
	I64Store           uint32
	I64Store16         uint32
	I64Store32         uint32
	I64Store8          uint32
	I64Sub             uint32
	I64Xor             uint32
	If                 uint32
	LocalGet           uint32
	LocalSet           uint32
	LocalTee           uint32
	LocalAllocate      uint32
	Loop               uint32
	MemoryGrow         uint32
	MemorySize         uint32
	Nop                uint32
	RefFunc            uint32
	RefIsNull          uint32
	RefNull            uint32
	Rethrow            uint32
	Return             uint32
	ReturnCall         uint32
	ReturnCallIndirect uint32
	Select             uint32
	TableGet           uint32
	TableGrow          uint32
	TableInit          uint32
	TableSet           uint32
	TableSize          uint32
	Throw              uint32
	Try                uint32
	TypedSelect        uint32
	Unreachable        uint32
	Unwind             uint32
}

type Wasmer2Executor

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

WasmerExecutor oversees the creation of Wasmer instances and execution.

func CreateExecutor

func CreateExecutor() (*Wasmer2Executor, error)

CreateExecutor creates a new wasmer executor.

func (*Wasmer2Executor) FunctionNames

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

func (*Wasmer2Executor) IsInterfaceNil

func (wasmerExecutor *Wasmer2Executor) IsInterfaceNil() bool

IsInterfaceNil returns true if underlying object is nil

func (*Wasmer2Executor) NewInstanceFromCompiledCodeWithOptions

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

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

func (*Wasmer2Executor) NewInstanceWithOptions

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

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

func (*Wasmer2Executor) SetOpcodeCosts

func (wasmerExecutor *Wasmer2Executor) SetOpcodeCosts(wasmOps *executor.WASMOpcodeCost)

SetOpcodeCosts sets gas costs globally inside the Wasmer executor.

func (*Wasmer2Executor) SetRkyvSerializationEnabled

func (wasmerExecutor *Wasmer2Executor) SetRkyvSerializationEnabled(enabled bool)

SetRkyvSerializationEnabled controls a Wasmer flag.

func (*Wasmer2Executor) SetSIGSEGVPassthrough

func (wasmerExecutor *Wasmer2Executor) SetSIGSEGVPassthrough()

SetSIGSEGVPassthrough controls a Wasmer flag.

type Wasmer2ExecutorFactory

type Wasmer2ExecutorFactory struct{}

Wasmer2ExecutorFactory builds Wasmer2 Executors.

func ExecutorFactory

func ExecutorFactory() *Wasmer2ExecutorFactory

ExecutorFactory returns the Wasmer executor factory.

func (*Wasmer2ExecutorFactory) CreateExecutor

CreateExecutor creates a new Executor instance.

func (*Wasmer2ExecutorFactory) IsInterfaceNil

func (wef *Wasmer2ExecutorFactory) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

type Wasmer2Instance

type Wasmer2Instance struct {
	AlreadyClean bool
	// contains filtered or unexported fields
}

Wasmer2Instance represents a WebAssembly instance.

func (*Wasmer2Instance) Cache

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

Cache caches the instance

func (*Wasmer2Instance) CallFunction

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

CallFunction executes given function from loaded contract.

func (*Wasmer2Instance) Clean

func (instance *Wasmer2Instance) Clean() bool

Clean cleans instance

func (*Wasmer2Instance) GetBreakpointValue

func (instance *Wasmer2Instance) GetBreakpointValue() uint64

GetBreakpointValue returns the breakpoint value

func (*Wasmer2Instance) GetFunctionNames

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

GetFunctionNames returns a list of the function names exported by the contract.

func (*Wasmer2Instance) GetPointsUsed

func (instance *Wasmer2Instance) GetPointsUsed() uint64

GetPointsUsed returns the internal instance gas counter

func (*Wasmer2Instance) GetVMHooksPtr

func (instance *Wasmer2Instance) GetVMHooksPtr() uintptr

GetVMHooksPtr returns the VM hooks pointer

func (*Wasmer2Instance) HasFunction

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

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

func (*Wasmer2Instance) HasMemory

func (instance *Wasmer2Instance) HasMemory() bool

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

func (*Wasmer2Instance) ID

func (instance *Wasmer2Instance) ID() string

Id returns an identifier for the instance, unique at runtime

func (*Wasmer2Instance) IsAlreadyCleaned

func (instance *Wasmer2Instance) IsAlreadyCleaned() bool

IsAlreadyCleaned returns the internal field AlreadyClean

func (*Wasmer2Instance) IsFunctionImported

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

IsFunctionImported returns true if the instance imports the specified function

func (*Wasmer2Instance) IsInterfaceNil

func (instance *Wasmer2Instance) IsInterfaceNil() bool

IsInterfaceNil returns true if underlying object is nil

func (*Wasmer2Instance) MemDump

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

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

func (*Wasmer2Instance) MemGrow

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

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

func (*Wasmer2Instance) MemLength

func (instance *Wasmer2Instance) MemLength() uint32

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

func (*Wasmer2Instance) MemLoad

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

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

func (*Wasmer2Instance) MemStore

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

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

func (*Wasmer2Instance) Reset

func (instance *Wasmer2Instance) Reset() bool

Reset resets the instance memories and globals

func (*Wasmer2Instance) SetBreakpointValue

func (instance *Wasmer2Instance) SetBreakpointValue(value uint64)

SetBreakpointValue sets the breakpoint value for the instance

func (*Wasmer2Instance) SetGasLimit

func (instance *Wasmer2Instance) SetGasLimit(gasLimit uint64)

SetGasLimit sets the gas limit for the instance

func (*Wasmer2Instance) SetPointsUsed

func (instance *Wasmer2Instance) SetPointsUsed(points uint64)

SetPointsUsed sets the internal instance gas counter

func (*Wasmer2Instance) SetVMHooksPtr

func (instance *Wasmer2Instance) SetVMHooksPtr(vmHooksPtr uintptr)

SetVMHooksPtr sets the VM hooks pointer

func (*Wasmer2Instance) ValidateFunctionArities

func (instance *Wasmer2Instance) 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.

type Wasmer2Memory

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

Wasmer2Instance represents a WebAssembly instance.

func (*Wasmer2Memory) Data

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

Data returns a slice of bytes over the WebAssembly memory. nolint

func (*Wasmer2Memory) Destroy

func (memory *Wasmer2Memory) Destroy()

Destroy destroys inner memory. Does nothing in wasmer2.

func (*Wasmer2Memory) Grow

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

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

func (*Wasmer2Memory) IsInterfaceNil

func (memory *Wasmer2Memory) IsInterfaceNil() bool

IsInterfaceNil returns true if underlying object is nil

func (*Wasmer2Memory) Length

func (memory *Wasmer2Memory) Length() uint32

Length calculates the memory length (in bytes).

Jump to

Keyboard shortcuts

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