exec

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2019 License: MIT, MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultCallStackSize is the default call stack size.
	DefaultCallStackSize = 512

	// DefaultPageSize is the linear memory page size.
	DefaultPageSize = 65536

	// JITCodeSizeThreshold is the lower-bound code size threshold for the JIT compiler.
	JITCodeSizeThreshold = 30
)

Variables

LE is a simple alias to `binary.LittleEndian`.

Functions

This section is empty.

Types

type AOTService

type AOTService interface {
	UnsafeInvokeFunction_0(vm *VirtualMachine, name string) uint64
	UnsafeInvokeFunction_1(vm *VirtualMachine, name string, p0 uint64) uint64
	UnsafeInvokeFunction_2(vm *VirtualMachine, name string, p0, p1 uint64) uint64
}

type Frame

type Frame struct {
	FunctionID   int
	Code         []byte
	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

type FunctionImport func(vm *VirtualMachine) int64

type FunctionImportInfo

type FunctionImportInfo struct {
	ModuleName string
	FieldName  string
	F          FunctionImport
}

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 NCompileConfig

type NCompileConfig struct {
	AliasDef             bool
	DisableMemBoundCheck bool
}

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 VMConfig

type VMConfig struct {
	EnableJIT                bool
	MaxMemoryPages           int
	MaxTableSize             int
	MaxValueSlots            int
	MaxCallStackDepth        int
	DefaultMemoryPages       int
	DefaultTableSize         int
	GasLimit                 uint64
	DisableFloatingPoint     bool
	ReturnOnGasLimitExceeded bool
}

VMConfig denotes a set of options passed to a single VirtualMachine insta.ce

type VirtualMachine

type VirtualMachine struct {
	Config           VMConfig
	Module           *compiler.Module
	FunctionCode     []compiler.InterpreterCode
	FunctionImports  []FunctionImportInfo
	CallStack        []Frame
	CurrentFrame     int
	Table            []uint32
	Globals          []int64
	Memory           memory.VMemory
	NumValueSlots    int
	Yielded          int64
	InsideExecute    bool
	Delegate         func()
	Exited           bool
	ExitError        interface{}
	ReturnValue      int64
	Gas              uint64
	GasLimitExceeded bool
	GasPolicy        compiler.GasPolicy
	ImportResolver   ImportResolver
	AOTService       AOTService
	StackTrace       string
}

VirtualMachine is a WebAssembly execution environment.

func NewVirtualMachine

func NewVirtualMachine(
	code []byte,
	config VMConfig,
	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 (*VirtualMachine) AddAndCheckGas

func (vm *VirtualMachine) AddAndCheckGas(delta uint64) bool

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) GenerateNEnv

func (vm *VirtualMachine) GenerateNEnv(config NCompileConfig) string

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) NBuildAliasDef

func (vm *VirtualMachine) NBuildAliasDef() string

func (*VirtualMachine) NCompile

func (vm *VirtualMachine) NCompile(config NCompileConfig) string

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) (retVal int64, retErr 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) SetAOTService

func (vm *VirtualMachine) SetAOTService(s AOTService)

Jump to

Keyboard shortcuts

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