exec

package
v3.8.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2020 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package exec provides functions for executing WebAssembly bytecode.

Index

Constants

View Source
const (
	VM_FALSE = iota
	VM_TRUE
)
View Source
const (
	// ENTRY_FUNCTION config the entry name
	ENTRY_FUNCTION = "start"

	// VM_PERIOD_OF_VALIDITY config the VM period of validity
	VM_PERIOD_OF_VALIDITY = "1h"

	// WAIT_TIME config the wait times
	WAIT_TIME = 4

	// BOTTOS_INVALID_CODE config the status of code
	BOTTOS_INVALID_CODE = 1

	// CALL_DEP_LIMIT config the max depth of call
	CALL_DEP_LIMIT = 5
	// CALL_WID_LIMIT config the max width of call
	CALL_WID_LIMIT = 10

	CALL_MAX_VM_LIMIT = 10
	// CTX_WASM_FILE config ctx wasm file
	//CTX_WASM_FILE = "/opt/bin/go/usermng.wasm"
	//CTX_WASM_FILE = "C:\\Users\\stewa\\Desktop\\BottosCTX\\math.wasm"
	//CTX_WASM_FILE = "C:\\Users\\stewa\\Desktop\\BottosCTX\\callcontract.wasm"
	//CTX_WASM_FILE = "C:\\Users\\stewa\\go\\src\\github.com\\AssemblyScript\\assemblyscript\\examples\\example\\module.optimized.wasm"
	//CTX_WASM_FILE = "C:\\Users\\stewa\\go\\src\\github.com\\AssemblyScript\\assemblyscript\\examples\\example\\module.optimized.wasm"
	//CTX_WASM_FILE = "C:\\Users\\stewa\\Desktop\\BottosCTX\\commontoken.wasm"
	CTX_WASM_FILE = "C:\\Users\\stewa\\Desktop\\BottosCTX\\module.optimized.wasm"
	//CTX_WASM_FILE = "C:\\Users\\stewa\\Desktop\\BottosCTX\\module.optimized.coredump.wasm"
	// SUB_WASM_FILE config sub wasm file
	SUB_WASM_FILE = "/opt/bin/go/sub.wasm"
	// TST Test status
	TST = true
)
View Source
const (
	VM_NULL = iota
)

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 ERR_CALL_ENV_METHOD = errors.New("*ERROR* failed to call the env method")
View Source
var ERR_COPY_DATA = errors.New("*ERROR* failed to copy data")
View Source
var ERR_CREATE_VM = errors.New("*ERROR* failed to create a new VM instance")
View Source
var ERR_DATA_INDEX = errors.New("*ERROR* failed to get data index from memory")
View Source
var ERR_EMPTY_INVALID_PARAM = errors.New("*ERROR* empty parameter or invalid parameter")
View Source
var ERR_EOF = errors.New("EOF")
View Source
var ERR_FIND_VM_METHOD = errors.New("*ERROR* failed to find the method from the wasm module")
View Source
var ERR_FINE_MAP = errors.New("*ERROR* the specified value can't be found by the key from the map")
View Source
var ERR_GET_STORE_POS = errors.New("*ERROR* failed to get the position of data")
View Source
var ERR_GET_VM = errors.New("*ERROR* failed to get a VM instance from memory")
View Source
var ERR_INVALID_ARGUMENT_COUNT = errors.New("*ERROR* invalid number of arguments to function")

ErrInvalidArgumentCount is returned by (*VM).ExecCode when an invalid number of arguments to the WebAssembly function are passed to it.

View Source
var ERR_INVALID_WASM = errors.New("*ERROR* invalid wasm module")
View Source
var ERR_MULTIPLE_LINEAR_MEMORIES = errors.New("*ERROR* more than one linear memories in module")

ErrMultipleLinearMemories is returned by (*VM).NewVM when the module has more then one entries in the linear memory space.

View Source
var ERR_OUT_BOUNDS = errors.New("*ERROR* (array) index out of bounds")
View Source
var ERR_PARAM_COUNT = errors.New("*ERROR* parameters count is not right")
View Source
var ERR_STORE_MEMORY = errors.New("*ERROR* failed to storage data to memory")
View Source
var ERR_STORE_METHOD = errors.New("*ERROR* failed to store the method name at the memory")
View Source
var ERR_STORE_PARAM = errors.New("*ERROR* failed to store the method arguments at the memory")
View Source
var ERR_UNSUPPORT_TYPE = errors.New("*ERROR* unsupport type")
View Source
var ERR_USED_POS = errors.New("*ERROR* the specified storage pos had been used")
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 ByteArrToNum

func ByteArrToNum(numArray []byte) (byte, error)

func ByteToFloat64

func ByteToFloat64(bytes []byte) float64

ByteToFloat64 convert byte to float64

func BytesToF32

func BytesToF32(b []byte) float32

BytesToF32 convert bytes to float32

func BytesToF64

func BytesToF64(b []byte) float64

BytesToF64 convert bytes to float64

func BytesToString

func BytesToString(bytes []byte) string

BytesToString convert bytes to string

func Convert

func Convert(vm *VM, pos uint64, length uint64) ([]byte, error)

for common

func ConvertStr

func ConvertStr(param []byte, pos uint64, length uint64) ([]byte, error)

for js

func ConvertU8Byte

func ConvertU8Byte(param []byte, pos uint64, length uint64) ([]byte, error)

for js

func F32ToBytes

func F32ToBytes(f32 float32) []byte

F32ToBytes convert float32 to bytes

func F64ToBytes

func F64ToBytes(f64 float64) []byte

F64ToBytes convert float64 to bytes

func GetInstance

func GetInstance() *wasmEngine

GetInstance is to get instance of wasm engine

func GetWasmVersion

func GetWasmVersion(ctx *contract.Context) uint32

GetWasmVersion is to get wasm version

func I32ToBytes

func I32ToBytes(i32 uint32) []byte

I32ToBytes convert int32 to bytes

func I64ToBytes

func I64ToBytes(i64 uint64) []byte

I64ToBytes convert int64 to bytes

func PackStrToByteArray

func PackStrToByteArray(vm *VM, pos uint64, length uint64) ([]byte, error)

for js

func RemoveElement

func RemoveElement(slice []byte, start, end uint64) []byte

func UnConvertStr

func UnConvertStr(param []byte, pos uint64, length uint64) ([]byte, error)

Types

type ApplyContext

type ApplyContext struct {
	Msg Message
}

ApplyContext define the apply context

type Authorization

type Authorization struct {
	Accout      string
	CodeVersion common.Hash
}

Authorization define the struct of authorization

type EnvFunc

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

EnvFunc defines env for func execution

func NewEnvFunc

func NewEnvFunc() *EnvFunc

NewEnvFunc new an EnvFunc

func (*EnvFunc) GetEnvFuncMap

func (env *EnvFunc) GetEnvFuncMap() map[string]func(*VM) (bool, error)

GetEnvFuncMap retrieve a method from FuncMap

func (*EnvFunc) Register

func (env *EnvFunc) Register(method string, handler func(*VM) (bool, error))

Register register a method in VM

type FuncInfo

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

FuncInfo is function information

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 Message

type Message struct {
	WasmName    string //crx name
	MethodName  string //method name
	Auth        Authorization
	MethodParam []byte //parameter
}

Message define the message info

type ParamInfo

type ParamInfo struct {
	Type string
	Val  string
}

ParamInfo define param info

type ParamList

type ParamList struct {
	Params []ParamInfo
}

ParamList define param array

type Rtn

type Rtn struct {
	Type string
	Val  string
}

Rtn define the return type

type SrcFileType

type SrcFileType int
const (
	CPP SrcFileType = iota
	JS
	PY
)

type TYPE

type TYPE uint32
const (
	VM_NOERROR TYPE = iota
	VM_ERROR_OUT_OF_MEMORY
	VM_ERROR_INVALID_PARAMETER_COUNT
	VM_ERROR_FAIL_EXECUTE_ENVFUNC
	VM_ERROR_FAIL_STORAGE_MEMORY
)

type Type

type Type int

Type define one variable type

const (
	// Int8 type enum
	Int8 Type = iota
	// Int16 type enum
	Int16
	// Int32 type enum
	Int32
	// Int64 type enum
	Int64
	// Float32 type enum
	Float32
	// Float64 type enum
	Float64
	// String type enum
	String
	// Struct type enum
	Struct
	// Unknown type enum
	Unknown
)

type VM

type VM struct {
	// 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 NewWASM

func NewWASM(ctx *contract.Context) *VM

Search the CTX infor at the database according to apply_context

func NewWASM1

func NewWASM1(ctx *contract.Context) *VM

NewWASM Search the CTX infor at the database according to applyContext

func (*VM) ExecCode

func (vm *VM) ExecCode(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.

func (*VM) ExecEnvFunc

func (vm *VM) ExecEnvFunc(compiled compiledFunction) error

ExecEnvFunc exec function

func (*VM) GetContract

func (vm *VM) GetContract() *contract.Context

GetContract get contract

func (*VM) GetData

func (vm *VM) GetData(pos uint64) ([]byte, error)

GetData retrieve data

func (*VM) GetFuncInfo

func (vm *VM) GetFuncInfo(method string, param []byte) error

GetFuncInfo is to get function information

func (*VM) GetFuncParams

func (vm *VM) GetFuncParams() []uint64

GetFuncParams get param

func (*VM) GetMemory

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

GetMemory get memory

func (*VM) GetMsgBytes

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

GetMsgBytes get message bytes

func (*VM) Memory

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

Memory returns the linear memory space for the VM.

func (*VM) RecoverContext

func (vm *VM) RecoverContext() bool

func (*VM) SetChannel

func (vm *VM) SetChannel(channel chan []byte) error

SetChannel set channel

func (*VM) SetContract

func (vm *VM) SetContract(contract *contract.Context) error

SetContract set contract param

func (*VM) StorageData

func (vm *VM) StorageData(data interface{}) (uint64, error)

StorageData store data

func (*VM) StrLen

func (vm *VM) StrLen(pos uint64) uint64

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