exec

package
v0.0.0-...-a048d37 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxGasLimit is the maximum gas limit
	MaxGasLimit = 0xFFFFFFFF
)

Variables

View Source
var (
	// TrapOOB is raised when memory access out of bound
	TrapOOB = NewTrap("memory access out of bound")
	// TrapIntOverflow is raised when math overflow
	TrapIntOverflow = NewTrap("integer overflow on divide or truncation")
	// TrapDivByZero is raised when divide by zero
	TrapDivByZero = NewTrap("integer divide by zero")
	// TrapInvalidConvert is raised when convert from NaN to integer
	TrapInvalidConvert = NewTrap("conversion from NaN to integer")
	// TrapUnreachable is raised when unreachable instruction executed
	TrapUnreachable = NewTrap("unreachable instruction executed")
	// TrapInvalidIndirectCall is raised when run invalid call_indirect instruction
	TrapInvalidIndirectCall = NewTrap("invalid call_indirect")
	// TrapCallStackExhaustion is raised when call stack exhausted
	TrapCallStackExhaustion = NewTrap("call stack exhausted")
	// TrapGasExhaustion is raised when runnning out of gas limit
	TrapGasExhaustion = NewTrap("run out of gas limit")
	// TrapInvalidArgument is raised when running function with invalid argument
	TrapInvalidArgument = NewTrap("invalid function argument")
)

Functions

func CaptureTrap

func CaptureTrap(err *error)

CaptureTrap 用于捕获潜在的Trap,如果是其他panic则不会捕获

func GetWriter

func GetWriter(ctx Context) io.Writer

GetDebugWriter get debug writer

func SetWriter

func SetWriter(ctx Context, w io.Writer)

SetWriter set debug writer to GetContractState

func Throw

func Throw(trap Trap)

Throw 用于抛出一个Trap

func Write

func Write(ctx Context, p []byte)

Write write debug message if SetWriter is not set, message will be ignored

Types

type Codec

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

Codec helps encoding and decoding data between wasm code and go code

func NewCodec

func NewCodec(ctx Context) Codec

NewCodec instances a Codec, if memory of ctx is nil, trapNilMemory will be raised

func (Codec) Bytes

func (c Codec) Bytes(addr, length uint32) []byte

Bytes returns memory region starting from addr, limiting by length

func (Codec) CString

func (c Codec) CString(addr uint32) string

CString decodes a '\x00' terminated c style string

func (Codec) GoBytes

func (c Codec) GoBytes(sp uint32) []byte

GoBytes decodes Go []byte start from sp

func (Codec) GoString

func (c Codec) GoString(sp uint32) string

GoString decodes Go string start from sp

func (Codec) SetUint32

func (c Codec) SetUint32(addr uint32, val uint32)

SetUint32 set val to memory[addr:addr+4]

func (Codec) String

func (c Codec) String(addr, length uint32) string

String decodes memory[addr:addr+length] to string

func (Codec) Uint32

func (c Codec) Uint32(addr uint32) uint32

Uint32 decodes memory[addr:addr+4] to uint32

func (Codec) Uint64

func (c Codec) Uint64(addr uint32) uint64

Uint64 decodes memory[addr:addr+8] to uint64

type Context

type Context interface {
	Exec(name string, param []int64) (ret int64, err error)
	GasUsed() int64
	ResetGasUsed()
	Memory() []byte
	StaticTop() uint32
	SetUserData(key string, value interface{})
	GetUserData(key string) interface{}
	Release()
}

GetContractState hold the context data when running a wasm instance

type ContextConfig

type ContextConfig struct {
	GasLimit int64
}

ContextConfig configures an execution context

func DefaultContextConfig

func DefaultContextConfig() *ContextConfig

DefaultContextConfig returns the default configuration of ContextConfig

type ErrFuncNotFound

type ErrFuncNotFound struct {
	Name string
}

func (*ErrFuncNotFound) Error

func (e *ErrFuncNotFound) Error() string

type GasMapper

type GasMapper struct {
}

GasMapper map instruction name to gas cost

func (*GasMapper) MapGas

func (g *GasMapper) MapGas(op string) (int64, bool)

type InterpCode

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

InterpCode is the WasmExec interface of interpreter mode

func NewInterpCode

func NewInterpCode(wasmCode []byte, resolver Resolver) (code *InterpCode, err error)

NewInterpCode instance a WasmExec based on the wasm code and resolver

func (*InterpCode) NewContext

func (code *InterpCode) NewContext(cfg *ContextConfig) (ictx Context, err error)

NewVM instances a new context

func (*InterpCode) Release

func (code *InterpCode) Release()

ReleaseCache releases the resources

type MapResolver

type MapResolver map[string]interface{}

MapResolver is the Resolver which stores symbols in map

func (MapResolver) ResolveFunc

func (m MapResolver) ResolveFunc(module, name string) (interface{}, bool)

ResolveFunc implements Resolver interface

func (MapResolver) ResolveGlobal

func (m MapResolver) ResolveGlobal(module, name string) (int64, bool)

ResolveGlobal implements Resolver interface

type MultiResolver

type MultiResolver []Resolver

MultiResolver chains multiple Resolvers, symbol looking up is according to the order of resolvers. The first found symbol will be returned.

func NewMultiResolver

func NewMultiResolver(resolvers ...Resolver) MultiResolver

NewMultiResolver instance a MultiResolver from resolves

func (MultiResolver) ResolveFunc

func (m MultiResolver) ResolveFunc(module, name string) (interface{}, bool)

ResolveFunc implements Resolver interface

func (MultiResolver) ResolveGlobal

func (m MultiResolver) ResolveGlobal(module, name string) (int64, bool)

ResolveGlobal implements Resolver interface

type Resolver

type Resolver interface {
	ResolveFunc(module, name string) (interface{}, bool)
	ResolveGlobal(module, name string) (int64, bool)
}

A Resolver resolves global and function symbols imported by wasm code

type Trap

type Trap interface {
	Reason() string
}

Trap 用于表示虚拟机运行过程中的错误,中断虚拟机的运行

func NewTrap

func NewTrap(reason string) Trap

NewTrap returns a trap with the given reason

type TrapError

type TrapError struct {
	Trap Trap
}

TrapError 用于包装一个Trap到Error

func (*TrapError) Error

func (t *TrapError) Error() string

type TrapFuncSignatureNotMatch

type TrapFuncSignatureNotMatch struct {
	Module string
	Name   string
}

TrapFuncSignatureNotMatch is raised when calling function signature is not matched

func (*TrapFuncSignatureNotMatch) Reason

func (s *TrapFuncSignatureNotMatch) Reason() string

Reason implements Trap interface

type TrapInvalidAddress

type TrapInvalidAddress uint32

TrapInvalidAddress is the trap raised when encounter an invalid address

func (TrapInvalidAddress) Reason

func (t TrapInvalidAddress) Reason() string

Reason implements Trap interface

type TrapSymbolNotFound

type TrapSymbolNotFound struct {
	Module string
	Name   string
}

TrapSymbolNotFound is raised when resolving symbol failed

func (*TrapSymbolNotFound) Reason

func (s *TrapSymbolNotFound) Reason() string

Reason implements Trap interface

type WasmExec

type WasmExec interface {
	NewContext(cfg *ContextConfig) (ictx Context, err error)
	Release()
}

Jump to

Keyboard shortcuts

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