exec

package
v2.0.1-beta+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2019 License: Apache-2.0, BSD-3-Clause Imports: 25 Imported by: 4

Documentation

Overview

  • Copyright (C) 2018 The DNA Authors
  • This file is part of The DNA library. *
  • The DNA is free software: you can redistribute it and/or modify
  • it under the terms of the GNU Lesser General Public License as published by
  • the Free Software Foundation, either version 3 of the License, or
  • (at your option) any later version. *
  • The DNA is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU Lesser General Public License for more details. *
  • You should have received a copy of the GNU Lesser General Public License
  • along with The DNA. If not, see <http://www.gnu.org/licenses/>.

Package exec provides functions for executing WebAssembly bytecode.

Index

Constants

View Source
const (
	CONTRACT_METHOD_NAME = "invoke"
	CONTRACT_INIT_METHOD = "init"
	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

This section is empty.

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, service InteropServiceInterface) *ExecutionEngine

todo add parameters

func (*ExecutionEngine) Call

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

Call Main interface of wasm vm excution engine caller common.Address :call address code []byte :wasm smart contract code actionName string :action name of the contract input []byte :arguments ver byte :contract version require > 0 for production

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

GetVM return vm pointer

func (*ExecutionEngine) InitCall

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

Call init method on deployment caller common.Address :call address code []byte :wasm smart contract code input []byte :arguments ver byte :contract version require > 0 for production TODO TBD whether we need to call init method after deploy automatically

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"`
	Psucceed int    `json:"succeed"`
}

type VM

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

	//store a engine pointer
	ContractAddress common.Address
	Caller          common.Address
	Engine          *ExecutionEngine
	VMCode          []byte
	// 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(caller common.Address, contractAddress common.Address, module *wasm.Module, actionName []byte, arg []byte) (uint64, error)

CallContract start a new vm this method is replaced with wasm_service :callContract

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)

GetMessageBytes for further extension

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

SetMessage for further extension 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