exec

package
v0.0.0-...-640f24c Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2018 License: LGPL-3.0, BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package exec provides functions for executing WebAssembly bytecode.

Index

Constants

View Source
const (
	CONTRACT_METHOD_NAME = "invoke"
	PARAM_SPLITER        = "|"
	VM_STACK_DEPTH       = 10
)

Variables

View Source
var (
	// ErrSignatureMismatch is the error value used while trapping the VM when
	// a signature mismatch between the table entry and the type entry is found
	// in a call_indirect operation.
	ErrSignatureMismatch = errors.New("exec: signature mismatch in call_indirect")
	// ErrUndefinedElementIndex is the error value used while trapping the VM when
	// an invalid index to the module's table space is used as an operand to
	// call_indirect
	ErrUndefinedElementIndex = errors.New("exec: undefined element index")
)
View Source
var (
	// ErrMultipleLinearMemories is returned by (*VM).NewVM when the module
	// has more then one entries in the linear memory space.
	ErrMultipleLinearMemories = errors.New("exec: more than one linear memories in module")
	// ErrInvalidArgumentCount is returned by (*VM).ExecCode when an invalid
	// number of arguments to the WebAssembly function are passed to it.
	ErrInvalidArgumentCount = errors.New("exec: invalid number of arguments to function")
)
View Source
var ErrOutOfBoundsMemoryAccess = errors.New("exec: out of bounds memory access")

ErrOutOfBoundsMemoryAccess is the error value used while trapping the VM when it detects an out of bounds access to the linear memory.

View Source
var ErrUnreachable = errors.New("exec: reached unreachable")

ErrUnreachable is the error value used while trapping the VM when an unreachable operator is reached during execution.

Functions

func GetCaller

func GetCaller(engine *ExecutionEngine) (bool, error)

func GetCodeHash

func GetCodeHash(engine *ExecutionEngine) (bool, error)

Types

type Args

type Args struct {
	Params []Param `json:"Params"`
}

type EnvCall

type EnvCall struct {
	Message []interface{} //the 'Message' field is for the EOS contract like parameters
	// contains filtered or unexported fields
}

store env call message

func (*EnvCall) GetParams

func (ec *EnvCall) GetParams() []uint64

func (*EnvCall) GetReturns

func (ec *EnvCall) GetReturns() bool

type ExecutionEngine

type ExecutionEngine struct {
	CodeContainer interfaces.CodeContainer
	// contains filtered or unexported fields
}

func NewExecutionEngine

func NewExecutionEngine(container interfaces.CodeContainer, crypto interfaces.Crypto, table interfaces.CodeTable, service InteropServiceInterface, ver string) *ExecutionEngine

todo add parameters

func (*ExecutionEngine) Call

func (e *ExecutionEngine) Call(caller common.Address, code, input []byte) (returnbytes []byte, er error)

the input format should be "methodname | args"

func (*ExecutionEngine) CallInf

func (e *ExecutionEngine) CallInf(caller common.Address, code []byte, input []interface{}, message []interface{}) ([]byte, error)

use this method just for test

func (*ExecutionEngine) Create

func (e *ExecutionEngine) Create(caller common.Address, code []byte) ([]byte, error)

func (*ExecutionEngine) GetMemory

func (e *ExecutionEngine) GetMemory() *memory.VMmemory

func (*ExecutionEngine) GetVM

func (e *ExecutionEngine) GetVM() *VM

func (*ExecutionEngine) RestoreVM

func (e *ExecutionEngine) RestoreVM() error

for call other contract, 1.pop stored vm 2.reset vm

func (*ExecutionEngine) SetNewVM

func (e *ExecutionEngine) SetNewVM(vm *VM) error

for call other contract, 1.store current vm 2.load new vm

type InteropService

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

func NewInteropService

func NewInteropService() *InteropService

func (*InteropService) Exists

func (i *InteropService) Exists(name string) bool

func (*InteropService) GetServiceMap

func (i *InteropService) GetServiceMap() map[string]func(*ExecutionEngine) (bool, error)

func (*InteropService) Invoke

func (i *InteropService) Invoke(methodName string, engine *ExecutionEngine) (bool, error)

func (*InteropService) MergeMap

func (i *InteropService) MergeMap(mMap map[string]func(*ExecutionEngine) (bool, error)) bool

func (*InteropService) Register

func (i *InteropService) Register(name string, handler func(*ExecutionEngine) (bool, error)) bool

type InteropServiceInterface

type InteropServiceInterface interface {
	Register(method string, handler func(*ExecutionEngine) (bool, error)) bool
	GetServiceMap() map[string]func(*ExecutionEngine) (bool, error)
}

type InvalidFunctionIndexError

type InvalidFunctionIndexError int64

InvalidFunctionIndexError is returned by (*VM).ExecCode when the function index provided is invalid.

func (InvalidFunctionIndexError) Error

type InvalidReturnTypeError

type InvalidReturnTypeError int8

InvalidReturnTypeError is returned by (*VM).ExecCode when the module specifies an invalid return type value for the executed function.

func (InvalidReturnTypeError) Error

func (e InvalidReturnTypeError) Error() string

type Param

type Param struct {
	Ptype string `json:"type"`
	Pval  string `json:"value"`
}

type Result

type Result struct {
	Ptype string `json:"type"`
	Pval  string `json:"value"`
}

type VM

type VM struct {
	Services map[string]func(engine *ExecutionEngine) (bool, error)

	//store a engine pointer
	CodeHash common.Address
	Caller   common.Address
	Engine   *ExecutionEngine
	// contains filtered or unexported fields
}

VM is the execution context for executing WebAssembly bytecode.

func NewVM

func NewVM(module *wasm.Module) (*VM, error)

NewVM creates a new VM from a given module. If the module defines a start function, it will be executed.

func (*VM) CallContract

func (vm *VM) CallContract(module *wasm.Module, methodName string, args ...uint64) (uint64, error)

todo implement the "call other contract function" this is for the "test" version call

func (*VM) CallProductContract

func (vm *VM) CallProductContract(module *wasm.Module, actionName []byte, arg []byte) (uint64, error)

start a new vm

func (*VM) ExecCode

func (vm *VM) ExecCode(insideCall bool, fnIndex int64, args ...uint64) (interface{}, error)

ExecCode calls the function with the given index and arguments. fnIndex should be a valid index into the function index space of the VM's module. insideCall :true (call contract)

func (*VM) GetEnvCall

func (vm *VM) GetEnvCall() *EnvCall

func (*VM) GetMemory

func (vm *VM) GetMemory() *memory.VMmemory

func (*VM) GetMessageBytes

func (vm *VM) GetMessageBytes() ([]byte, error)

func (*VM) GetPointerMemSize

func (vm *VM) GetPointerMemSize(addr uint64) int

func (*VM) GetPointerMemory

func (vm *VM) GetPointerMemory(addr uint64) ([]byte, error)

when wasm returns a pointer, call this function to get the pointed memory

func (*VM) Malloc

func (vm *VM) Malloc(size int) (int, error)

alloc memory and return the first index

func (*VM) MallocPointer

func (vm *VM) MallocPointer(size int, ptype memory.PType) (int, error)

alloc memory for pointer and return the first index

func (*VM) Memory

func (vm *VM) Memory() []byte

Memory returns the linear memory space for the VM.

func (*VM) PushResult

func (vm *VM) PushResult(res uint64)

func (*VM) RestoreCtx

func (vm *VM) RestoreCtx() bool

func (*VM) SetMemory

func (vm *VM) SetMemory(val interface{}) (int, error)

func (*VM) SetMessage

func (vm *VM) SetMessage(message []interface{})

support EOS like message

func (*VM) SetPointerMemory

func (vm *VM) SetPointerMemory(val interface{}) (int, error)

alloc memory for any pointer type

func (*VM) SetStructMemory

func (vm *VM) SetStructMemory(val interface{}) (int, error)

alloc memory for struct todo move to the SetPointerMemory

Directories

Path Synopsis
internal
compile
Package compile is used internally by wagon to convert standard structured WebAssembly bytecode into an unstructured form suitable for execution by it's VM.
Package compile is used internally by wagon to convert standard structured WebAssembly bytecode into an unstructured form suitable for execution by it's VM.

Jump to

Keyboard shortcuts

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