Documentation ¶
Index ¶
- Constants
- Variables
- func ImportGasFunc(vm *VirtualMachine, frame *Frame) (uint64, error)
- func ParseModuleAndFunc(code []byte, gasPolicy compiler.GasPolicy) (*compiler.Module, []compiler.InterpreterCode, error)
- type DynamicModule
- type Execute
- type Frame
- type FunctionImport
- type GasCost
- type ImportResolver
- type Instruction
- type MemBlock
- type MemPool
- type Memory
- type NopResolver
- type StateDB
- type TreePool
- type VMConfig
- type VMContext
- type VMMemory
- type VirtualMachine
- func (vm *VirtualMachine) AddAndCheckGas(delta uint64)
- func (vm *VirtualMachine) Execute()
- func (vm *VirtualMachine) GenerateCodeForFunction(functionID int) bool
- func (vm *VirtualMachine) GetCurrentFrame() *Frame
- func (vm *VirtualMachine) GetFunctionExport(key string) (int, bool)
- func (vm *VirtualMachine) GetGlobalExport(key string) (int, bool)
- func (vm *VirtualMachine) Ignite(functionID int, params ...int64)
- func (vm *VirtualMachine) PrintStackTrace()
- func (vm *VirtualMachine) Run(entryID int, params ...int64) (int64, error)
- func (vm *VirtualMachine) RunWithGasLimit(entryID, limit int, params ...int64) (int64, error)
- func (vm *VirtualMachine) Stop() (err error)
Constants ¶
const ( // DefaultCallStackSize is the default call stack size. DefaultCallStackSize = 512 // DefaultPageSize is the linear memory page size. 65536 DefaultPageSize = 65536 // JITCodeSizeThreshold is the lower-bound code size threshold for the JIT compiler. JITCodeSizeThreshold = 30 DefaultMemoryPages = 16 DynamicMemoryPages = 16 DefaultMemPoolCount = 5 DefaultMemBlockSize = 5 DefaultMemTreeMaxPage = 8 )
Variables ¶
var (
EmptyPage = make([]byte, DefaultPageSize)
)
var GasTable = [256]Instruction{}/* 161 elements not displayed */
var LE = binary.LittleEndian
LE is a simple alias to `binary.LittleEndian`.
Functions ¶
func ImportGasFunc ¶
func ImportGasFunc(vm *VirtualMachine, frame *Frame) (uint64, error)
func ParseModuleAndFunc ¶
Types ¶
type DynamicModule ¶
type DynamicModule struct { }
func CompileDynamicModule ¶
func CompileDynamicModule(source string) *DynamicModule
func (*DynamicModule) Run ¶
func (m *DynamicModule) Run(vm *VirtualMachine, ret *int64) int32
type Execute ¶
type Execute func(vm *VirtualMachine) int64
type Frame ¶
type Frame struct { FunctionID int Code []byte JITInfo interface{} Regs []int64 Locals []int64 IP int ReturnReg int Continuation int32 }
Frame represents a call frame.
func (*Frame) Destroy ¶
func (f *Frame) Destroy(vm *VirtualMachine)
Destroy destroys a frame. Must be called on return.
func (*Frame) Init ¶
func (f *Frame) Init(vm *VirtualMachine, functionID int, code compiler.InterpreterCode)
Init initializes a frame. Must be called on `call` and `call_indirect`.
type FunctionImport ¶
FunctionImport represents the function import type. If len(sig.ReturnTypes) == 0, the return value will be ignored.
type GasCost ¶
type GasCost func(vm *VirtualMachine) (uint64, error)
type ImportResolver ¶
type ImportResolver interface { ResolveFunc(module, field string) *FunctionImport ResolveGlobal(module, field string) int64 }
ImportResolver is an interface for allowing one to define imports to WebAssembly modules ran under a single VirtualMachine instance.
type Instruction ¶
type Instruction struct { Execute executionFunc GasCost gasFunc }
type MemBlock ¶
type MemBlock struct { FreeMem [][]byte // contains filtered or unexported fields }
func NewMemBlock ¶
type MemPool ¶
func NewMemPool ¶
type Memory ¶
type NopResolver ¶
type NopResolver struct{}
NopResolver is a nil WebAssembly module import resolver.
func (*NopResolver) ResolveFunc ¶
func (r *NopResolver) ResolveFunc(module, field string) *FunctionImport
func (*NopResolver) ResolveGlobal ¶
func (r *NopResolver) ResolveGlobal(module, field string) int64
type StateDB ¶
type StateDB interface { GasPrice() int64 BlockHash(num uint64) common.Hash BlockNumber() *big.Int GasLimimt() uint64 Time() *big.Int Coinbase() common.Address GetBalance(addr common.Address) *big.Int Origin() common.Address Caller() common.Address GetCode(addr common.Address) []byte Address() common.Address CallValue() *big.Int IsOwner(contractAddress common.Address, accountAddress common.Address) int64 AddLog(address common.Address, topics []common.Hash, data []byte, bn uint64) SetState(key []byte, value []byte) GetState(key []byte) []byte GetCallerNonce() int64 Transfer(addr common.Address, value *big.Int) (ret []byte, leftOverGas uint64, err error) DelegateCall(addr, params []byte) ([]byte, error) Call(addr, params []byte) ([]byte, error) }
type TreePool ¶
type TreePool struct {
// contains filtered or unexported fields
}
func NewTreePool ¶
type VMConfig ¶
type VMConfig struct { EnableJIT bool DynamicMemoryPages int MaxMemoryPages int MaxTableSize int MaxValueSlots int MaxCallStackDepth int DefaultMemoryPages int DefaultTableSize int GasLimit uint64 DisableFree bool }
VMConfig denotes a set of options passed to a single VirtualMachine insta.ce
type VirtualMachine ¶
type VirtualMachine struct { Context *VMContext Module *compiler.Module FunctionCode []compiler.InterpreterCode FunctionImports []*FunctionImport JumpTable [256]Instruction CallStack []Frame CurrentFrame int Table []uint32 Globals []int64 //Memory *VMMemory Memory *Memory NumValueSlots int Yielded int64 InsideExecute bool Delegate func() Exited bool ExitError interface{} ReturnValue int64 Gas uint64 ExternalParams []int64 InitEntryID int }
VirtualMachine is a WebAssembly execution environment.
func NewVirtualMachine ¶
func NewVirtualMachine(code []byte, context *VMContext, impResolver ImportResolver, gasPolicy compiler.GasPolicy) (_retVM *VirtualMachine, retErr error)
NewVirtualMachine instantiates a virtual machine for a given WebAssembly module, with specific execution options specified under a VMConfig, and a WebAssembly module import resolver.
func NewVirtualMachineWithModule ¶
func NewVirtualMachineWithModule(m *compiler.Module, functionCode []compiler.InterpreterCode, context *VMContext, impResolver ImportResolver, gasPolicy compiler.GasPolicy) (_retVM *VirtualMachine, retErr error)
func (*VirtualMachine) AddAndCheckGas ¶
func (vm *VirtualMachine) AddAndCheckGas(delta uint64)
func (*VirtualMachine) Execute ¶
func (vm *VirtualMachine) Execute()
Execute starts the virtual machines main instruction processing loop. This function may return at any point and is guaranteed to return at least once every 10000 instructions. Caller is responsible for detecting VM status in a loop.
func (*VirtualMachine) GenerateCodeForFunction ¶
func (vm *VirtualMachine) GenerateCodeForFunction(functionID int) bool
GenerateCodeForFunction generates C code for the given function. Returns true if codegen succeeds, or false if the current function cannot be code-generated.
func (*VirtualMachine) GetCurrentFrame ¶
func (vm *VirtualMachine) GetCurrentFrame() *Frame
GetCurrentFrame returns the current frame.
func (*VirtualMachine) GetFunctionExport ¶
func (vm *VirtualMachine) GetFunctionExport(key string) (int, bool)
GetFunctionExport returns the function export with the given name.
func (*VirtualMachine) GetGlobalExport ¶
func (vm *VirtualMachine) GetGlobalExport(key string) (int, bool)
GetGlobalExport returns the global export with the given name.
func (*VirtualMachine) Ignite ¶
func (vm *VirtualMachine) Ignite(functionID int, params ...int64)
Ignite initializes the first call frame.
func (*VirtualMachine) PrintStackTrace ¶
func (vm *VirtualMachine) PrintStackTrace()
PrintStackTrace prints the entire VM stack trace for debugging.
func (*VirtualMachine) Run ¶
func (vm *VirtualMachine) Run(entryID int, params ...int64) (int64, error)
Run runs a WebAssembly modules function denoted by its ID with a specified set of parameters. Panics on logical errors.
func (*VirtualMachine) RunWithGasLimit ¶
func (vm *VirtualMachine) RunWithGasLimit(entryID, limit int, params ...int64) (int64, error)
RunWithGasLimit runs a WebAssembly modules function denoted by its ID with a specified set of parameters for a specified amount of instructions (also known as gas) denoted by `limit`. Panics on logical errors.
func (*VirtualMachine) Stop ¶
func (vm *VirtualMachine) Stop() (err error)