exec

package
v0.0.0-...-35ce171 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package pointer exchange pointer between cgo and go

Index

Constants

This section is empty.

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 PointerDelete

func PointerDelete(token uintptr)

PointerDelete deletes token from internal cache

func PointerRestore

func PointerRestore(token uintptr) interface{}

PointerRestore restore the token to go object, a invalid token will return nil

func PointerSave

func PointerSave(p interface{}) uintptr

PointerSave convert a go object to a unique token which can be safely passed to cgo The token must be deleted by calling Delete after used

func Throw

func Throw(trap Trap)

Throw 用于抛出一个Trap

func ThrowError

func ThrowError(err error)

ThrowError throws an error as an trap

func ThrowMessage

func ThrowMessage(msg string)

ThrowMessage throws a string message as an trap

Types

type Code

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

func NewAOTCode

func NewAOTCode(module string, resolver Resolver) (icode Code, err error)

NewAOTCode instances a Code object from file path of native shared library

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() uint64
	ResetGasUsed()
	SetGasUsed(uint64)
	Memory() []byte
	StaticTop() uint32
	SetUserData(key string, value interface{})
	GetUserData(key string) interface{}
	Release()
}

Context hold the context data when running a wasm instance

type ContextConfig

type ContextConfig struct {
	GasLimit int64
}

ContextConfig configures an execution context

type ErrFuncNotFound

type ErrFuncNotFound struct {
	Name string
}

func (*ErrFuncNotFound) Error

func (e *ErrFuncNotFound) Error() string

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

Jump to

Keyboard shortcuts

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