image

package
v0.0.0-...-5eca219 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: BSD-3-Clause Imports: 36 Imported by: 1

Documentation

Index

Constants

View Source
const TextRevision = 0

Variables

View Source
var ErrInvalidState = errors.New("instance state is invalid")
View Source
var Memory mem

Memory implements Storage. It doesn't support program or instance persistence.

Functions

This section is empty.

Types

type Build

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

Build a program and optionally an instance. FinishText, FinishProgram and (optionally) FinishInstance must be called in that order.

func NewBuild

func NewBuild(storage Storage, moduleSize, maxTextSize int, objectMap *object.CallMap, instance bool) (*Build, error)

NewBuild for a program and optionally an instance.

func (*Build) Close

func (b *Build) Close() (err error)

func (*Build) FinishInstance

func (b *Build) FinishInstance(prog *Program, maxMemorySize, entryFuncIndex int) (*Instance, error)

FinishInstance after FinishProgram. Applicable only if an instance storage was specified in NewBuild call.

func (*Build) FinishProgram

func (b *Build) FinishProgram(sectionMap SectionMap, mod compile.Module, startFuncIndex int, entryFuncs bool, snap *snapshot.Snapshot, bufferSectionHeaderLength int) (*Program, error)

FinishProgram after module, stack, globals and memory have been populated.

func (*Build) FinishText

func (b *Build) FinishText(stackSize, stackUsage, globalsSize, memorySize int) error

FinishText after TextBuffer has been populated.

func (*Build) GlobalsMemoryBuffer

func (b *Build) GlobalsMemoryBuffer() interface {
	Bytes() []byte
	ResizeBytes(n int) []byte
}

GlobalsMemoryBuffer is valid after FinishText. It must be populated before FinishProgram is called.

func (*Build) ImportResolver

func (b *Build) ImportResolver() interface {
	ResolveFunc(module, field string, sig wa.FuncType) (index uint32, err error)
	ResolveGlobal(module, field string, t wa.Type) (value uint64, err error)
}

func (*Build) MemoryAlignment

func (b *Build) MemoryAlignment() int

MemoryAlignment of GlobalsMemoryBuffer.

func (*Build) ModuleWriter

func (b *Build) ModuleWriter() io.Writer

ModuleWriter is valid after NewBuild. The module must be written before FinishProgram is called.

func (*Build) ObjectMap

func (b *Build) ObjectMap() *object.CallMap

func (*Build) ReadStack

func (b *Build) ReadStack(r io.Reader, types []wa.FuncType, funcTypeIndexes []uint32) error

ReadStack if FinishText has been called with nonzero stackUsage. It must not be called after FinishProgram.

func (*Build) TextBuffer

func (b *Build) TextBuffer() interface {
	Bytes() []byte
	Extend(n int) []byte
	PutByte(byte)
	PutUint32(uint32) // Little-endian byte order.
}

TextBuffer is valid after NewBuild. It must be populated before FinishText is called.

type Filesystem

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

Filesystem implements Storage. It supports program and instance persistence.

func NewFilesystem

func NewFilesystem(root string) (*Filesystem, error)

func NewFilesystemWithOwnership

func NewFilesystemWithOwnership(root string, uid, gid int) (fs *Filesystem, err error)

func (*Filesystem) Close

func (fs *Filesystem) Close() error

func (*Filesystem) Instances

func (fs *Filesystem) Instances() ([]string, error)

func (*Filesystem) LoadInstance

func (fs *Filesystem) LoadInstance(name string) (inst *Instance, err error)

func (*Filesystem) LoadProgram

func (fs *Filesystem) LoadProgram(name string) (*Program, error)

func (*Filesystem) Programs

func (fs *Filesystem) Programs() ([]string, error)

type Instance

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

Instance is a program state. It may be undergoing mutation.

func NewInstance

func NewInstance(prog *Program, maxMemorySize, maxStackSize, entryFuncIndex int) (*Instance, error)

func (*Instance) BeginMutation

func (inst *Instance) BeginMutation(textAddr uint64) (file interface{ Fd() uintptr }, err error)

BeginMutation must be invoked when mutation starts. CheckMutation and Close may be called during the mutation. The returned file handle is valid until the next Instance method call.

func (*Instance) Breakpoints

func (inst *Instance) Breakpoints() []uint64

Breakpoints are in ascending order and unique.

func (*Instance) CheckHaltedMutation

func (inst *Instance) CheckHaltedMutation(result wa.ScalarCategory) (uint64, error)

CheckHaltedMutation is like CheckMutation, but it also returns the result of the top-level function. The result is undefined if the program terminated in some other way.

This is useful only with ReplaceCallStack, if you know that the program exits by returning.

func (*Instance) CheckMutation

func (inst *Instance) CheckMutation() error

CheckMutation can be invoked after the mutation has ended.

func (*Instance) Close

func (inst *Instance) Close() error

func (*Instance) EntryAddr

func (inst *Instance) EntryAddr() uint32

func (*Instance) ExportStack

func (inst *Instance) ExportStack(textMap stack.TextMap) ([]byte, error)

func (*Instance) Final

func (inst *Instance) Final() bool

func (*Instance) Flags

func (inst *Instance) Flags() snapshot.Flags

func (*Instance) Globals

func (inst *Instance) Globals(prog *Program) ([]uint64, error)

func (*Instance) GlobalsSize

func (inst *Instance) GlobalsSize() int

func (*Instance) MaxMemorySize

func (inst *Instance) MaxMemorySize() int

func (*Instance) MemorySize

func (inst *Instance) MemorySize() int

func (*Instance) MonotonicTime

func (inst *Instance) MonotonicTime() uint64

func (*Instance) ReplaceCallStack

func (inst *Instance) ReplaceCallStack(funcAddr uint32, funcArgs []uint64) error

ReplaceCallStack with a "suspended" function call with given arguments. Pending start function, entry function, and existing suspended state are discarded. Arguments are not checked against function signature.

This is a low-level API primarily useful for testing.

func (*Instance) Result

func (inst *Instance) Result() int32

func (*Instance) SetBreakpoints

func (inst *Instance) SetBreakpoints(a []uint64)

SetBreakpoints which must have been sorted and deduplicated.

func (*Instance) SetEntryFunc

func (inst *Instance) SetEntryFunc(prog *Program, index int) error

func (*Instance) SetFinal

func (inst *Instance) SetFinal()

func (*Instance) SetResult

func (inst *Instance) SetResult(n int32)

func (*Instance) SetTrap

func (inst *Instance) SetTrap(id trap.ID)

func (*Instance) StackSize

func (inst *Instance) StackSize() int

func (*Instance) StackUsage

func (inst *Instance) StackUsage() int

func (*Instance) Stacktrace

func (inst *Instance) Stacktrace(textMap stack.TextMap, funcTypes []wa.FuncType) ([]stack.Frame, error)

func (*Instance) StartAddr

func (inst *Instance) StartAddr() uint32

func (*Instance) Store

func (inst *Instance) Store(name, progName string, prog *Program) error

Store the instance. The names must not contain path separators.

func (*Instance) TextAddr

func (inst *Instance) TextAddr() uint64

func (*Instance) Trap

func (inst *Instance) Trap() trap.ID

func (*Instance) Unstore

func (inst *Instance) Unstore() error

type InstanceStorage

type InstanceStorage interface {
	Instances() (names []string, err error)
	LoadInstance(name string) (*Instance, error)
	// contains filtered or unexported methods
}

func PersistentMemory

func PersistentMemory(storage *Filesystem) InstanceStorage

PersistentMemory supports instance persistence by copying data to and from a Filesystem.

func PrepareInstances

func PrepareInstances(ctx context.Context, storage InstanceStorage, bufsize int) InstanceStorage

PrepareInstances wraps an InstanceStorage. The wrapper creates instance resources in advance.

type Program

type Program struct {
	Map object.CallMap
	// contains filtered or unexported fields
}

func Snapshot

func Snapshot(oldProg *Program, inst *Instance, buffers snapshot.Buffers, suspended bool) (*Program, error)

func (*Program) Breakpoints

func (prog *Program) Breakpoints() []uint64

Breakpoints are in ascending order and unique.

func (*Program) Close

func (prog *Program) Close() error

func (*Program) LoadBuffers

func (prog *Program) LoadBuffers() (bs snapshot.Buffers, err error)

func (*Program) ModuleSize

func (prog *Program) ModuleSize() int64

func (*Program) NewModuleReader

func (prog *Program) NewModuleReader() io.Reader

func (*Program) PageSize

func (prog *Program) PageSize() int

func (*Program) Random

func (prog *Program) Random() bool

func (*Program) ResolveEntryFunc

func (prog *Program) ResolveEntryFunc(exportName string, started bool) (int, error)

ResolveEntryFunc index or the implicit _start function index. The started argument is disregarded if the program is a snapshot.

func (*Program) Store

func (prog *Program) Store(name string) error

Store the program. The name must not contain path separators.

func (*Program) Text

func (prog *Program) Text() (file interface{ Fd() uintptr }, err error)

func (*Program) TextSize

func (prog *Program) TextSize() int

type ProgramStorage

type ProgramStorage interface {
	Programs() (names []string, err error)
	// contains filtered or unexported methods
}

func PreparePrograms

func PreparePrograms(ctx context.Context, storage ProgramStorage, bufsize int) ProgramStorage

PreparePrograms wraps a ProgramStorage. The wrapper creates program resources in advance.

type SectionMap

type SectionMap struct {
	section.Map

	Snapshot   section.ByteRange
	ExportWrap section.ByteRange
	Buffer     section.ByteRange
	Stack      section.ByteRange
}

type Storage

type Storage interface {
	ProgramStorage
	InstanceStorage

	LoadProgram(name string) (*Program, error)
}

func CombinedStorage

func CombinedStorage(prog ProgramStorage, inst InstanceStorage) Storage

Jump to

Keyboard shortcuts

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