wazevoapi

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FrontEndLoggingEnabled = false
	SSALoggingEnabled      = false
	RegAllocLoggingEnabled = false
)
View Source
const (
	PrintSSA                       = false
	PrintOptimizedSSA              = false
	PrintSSAToBackendIRLowering    = false
	PrintRegisterAllocated         = false
	PrintFinalizedMachineCode      = false
	PrintMachineCodeHexPerFunction = printMachineCodeHexPerFunctionUnmodified || PrintMachineCodeHexPerFunctionDisassemblable //nolint

	// PrintMachineCodeHexPerFunctionDisassemblable prints the machine code while modifying the actual result
	// to make it disassemblable. This is useful when debugging the final machine code. See the places where this is used for detail.
	// When this is enabled, functions must not be called.
	PrintMachineCodeHexPerFunctionDisassemblable = false
)
View Source
const (
	// StackGuardCheckEnabled enables the stack guard check to ensure that our stack bounds check works correctly.
	StackGuardCheckEnabled       = false
	StackGuardCheckGuardPageSize = 8096
)

----- Stack Guard Check -----

View Source
const (
	// DeterministicCompilationVerifierEnabled enables the deterministic compilation verifier. This is disabled by default
	// since the operation is expensive. But when in doubt, enable this to make sure the compilation is deterministic.
	DeterministicCompilationVerifierEnabled = false
	DeterministicCompilationVerifyingIter   = 5
)
View Source
const (
	// FunctionInstanceSize is the size of wazevo.functionInstance.
	FunctionInstanceSize = 24
	// FunctionInstanceExecutableOffset is an offset of `executable` field in wazevo.functionInstance
	FunctionInstanceExecutableOffset = 0
	// FunctionInstanceModuleContextOpaquePtrOffset is an offset of `moduleContextOpaquePtr` field in wazevo.functionInstance
	FunctionInstanceModuleContextOpaquePtrOffset = 8
	// FunctionInstanceTypeIDOffset is an offset of `typeID` field in wazevo.functionInstance
	FunctionInstanceTypeIDOffset = 16
)
View Source
const ExitCodeMask = 0xff

nolint

View Source
const PerfMapEnabled = false
View Source
const (
	// SSAValidationEnabled enables the SSA validation. This is disabled by default since the operation is expensive.
	SSAValidationEnabled = false
)

----- Validations -----

Variables

This section is empty.

Functions

func CheckStackGuardPage added in v1.6.0

func CheckStackGuardPage(s []byte)

CheckStackGuardPage checks the given stack guard page is not corrupted.

func DeterministicCompilationVerifierGetRandomizedLocalFunctionIndex added in v1.6.0

func DeterministicCompilationVerifierGetRandomizedLocalFunctionIndex(ctx context.Context, index int) int

DeterministicCompilationVerifierGetRandomizedLocalFunctionIndex returns the randomized index for the given `index` which is assigned by DeterministicCompilationVerifierRandomizeIndexes.

func DeterministicCompilationVerifierRandomizeIndexes added in v1.6.0

func DeterministicCompilationVerifierRandomizeIndexes(ctx context.Context)

DeterministicCompilationVerifierRandomizeIndexes randomizes the indexes for the deterministic compilation verifier. To get the randomized index, use DeterministicCompilationVerifierGetRandomizedLocalFunctionIndex.

func GetCurrentFunctionIndex added in v1.6.0

func GetCurrentFunctionIndex(ctx context.Context) int

GetCurrentFunctionIndex returns the current function index.

func GetCurrentFunctionName added in v1.6.0

func GetCurrentFunctionName(ctx context.Context) string

GetCurrentFunctionName returns the current function name.

func GoFunctionIndexFromExitCode

func GoFunctionIndexFromExitCode(exitCode ExitCode) int

func NewDeterministicCompilationVerifierContext added in v1.6.0

func NewDeterministicCompilationVerifierContext(ctx context.Context, localFunctions int) context.Context

NewDeterministicCompilationVerifierContext creates a new context with the deterministic compilation verifier used per wasm.Module.

func PrintEnabledIndex added in v1.6.0

func PrintEnabledIndex(ctx context.Context) bool

PrintEnabledIndex returns true if the current function index is the print target.

func PtrFromUintptr added in v1.7.0

func PtrFromUintptr[T any](ptr uintptr) *T

PtrFromUintptr resurrects the original *T from the given uintptr. The caller of this function MUST be sure that ptr is valid.

func ResetMap added in v1.7.0

func ResetMap[K comparable, V any](m map[K]V) map[K]V

ResetMap resets the map to an empty state, or creates a new map if it is nil.

func SetCurrentFunctionName added in v1.6.0

func SetCurrentFunctionName(ctx context.Context, index int, functionName string) context.Context

SetCurrentFunctionName sets the current function name to the given `functionName`.

func VerifyOrSetDeterministicCompilationContextValue added in v1.6.0

func VerifyOrSetDeterministicCompilationContextValue(ctx context.Context, scope string, newValue string)

VerifyOrSetDeterministicCompilationContextValue verifies that the `newValue` is the same as the previous value for the given `scope` and the current function name. If the previous value doesn't exist, it sets the value to the given `newValue`.

If the verification fails, this prints the diff and exits the process.

Types

type ExitCode

type ExitCode uint32

ExitCode is an exit code of an execution of a function.

const (
	ExitCodeOK ExitCode = iota
	ExitCodeGrowStack
	ExitCodeGrowMemory
	ExitCodeUnreachable
	ExitCodeMemoryOutOfBounds
	// ExitCodeCallGoModuleFunction is an exit code for a call to an api.GoModuleFunction.
	ExitCodeCallGoModuleFunction
	// ExitCodeCallGoFunction is an exit code for a call to an api.GoFunction.
	ExitCodeCallGoFunction
	ExitCodeTableOutOfBounds
	ExitCodeIndirectCallNullPointer
	ExitCodeIndirectCallTypeMismatch
	ExitCodeIntegerDivisionByZero
	ExitCodeIntegerOverflow
	ExitCodeInvalidConversionToInteger
	ExitCodeCheckModuleExitCode
	ExitCodeCallListenerBefore
	ExitCodeCallListenerAfter
	ExitCodeCallGoModuleFunctionWithListener
	ExitCodeCallGoFunctionWithListener
	ExitCodeTableGrow
	ExitCodeRefFunc
	ExitCodeMemoryWait32
	ExitCodeMemoryWait64
	ExitCodeMemoryNotify
	ExitCodeUnalignedAtomic
)

func ExitCodeCallGoFunctionWithIndex

func ExitCodeCallGoFunctionWithIndex(index int, withListener bool) ExitCode

func ExitCodeCallGoModuleFunctionWithIndex

func ExitCodeCallGoModuleFunctionWithIndex(index int, withListener bool) ExitCode

func (ExitCode) String

func (e ExitCode) String() string

String implements fmt.Stringer.

type IDedPool added in v1.7.0

type IDedPool[T any] struct {
	// contains filtered or unexported fields
}

IDedPool is a pool of T that can be allocated and reset, with a way to get T by an ID.

func NewIDedPool added in v1.7.0

func NewIDedPool[T any](resetFn func(*T)) IDedPool[T]

NewIDedPool returns a new IDedPool.

func (*IDedPool[T]) Get added in v1.7.0

func (p *IDedPool[T]) Get(id int) *T

Get returns the T with the given id, or nil if it's not allocated.

func (*IDedPool[T]) GetOrAllocate added in v1.7.0

func (p *IDedPool[T]) GetOrAllocate(id int) *T

GetOrAllocate returns the T with the given id.

func (*IDedPool[T]) MaxIDEncountered added in v1.7.0

func (p *IDedPool[T]) MaxIDEncountered() int

MaxIDEncountered returns the maximum id encountered so far.

func (*IDedPool[T]) Reset added in v1.7.0

func (p *IDedPool[T]) Reset()

Reset resets the pool.

type ModuleContextOffsetData

type ModuleContextOffsetData struct {
	TotalSize int
	ModuleInstanceOffset,
	LocalMemoryBegin,
	ImportedMemoryBegin,
	ImportedFunctionsBegin,
	GlobalsBegin,
	TypeIDs1stElement,
	TablesBegin,
	BeforeListenerTrampolines1stElement,
	AfterListenerTrampolines1stElement,
	DataInstances1stElement,
	ElementInstances1stElement Offset
}

ModuleContextOffsetData allows the compilers to get the information about offsets to the fields of wazevo.moduleContextOpaque, This is unique per module.

func NewModuleContextOffsetData

func NewModuleContextOffsetData(m *wasm.Module, withListener bool) ModuleContextOffsetData

NewModuleContextOffsetData creates a ModuleContextOffsetData determining the structure of moduleContextOpaque for the given Module. The structure is described in the comment of wazevo.moduleContextOpaque.

func (*ModuleContextOffsetData) GlobalInstanceOffset

func (m *ModuleContextOffsetData) GlobalInstanceOffset(i wasm.Index) Offset

GlobalInstanceOffset returns an offset of the i-th global instance.

func (*ModuleContextOffsetData) ImportedFunctionOffset

func (m *ModuleContextOffsetData) ImportedFunctionOffset(i wasm.Index) (
	executableOffset, moduleCtxOffset, typeIDOffset Offset,
)

ImportedFunctionOffset returns an offset of the i-th imported function. Each item is stored as wazevo.functionInstance whose size matches FunctionInstanceSize.

func (*ModuleContextOffsetData) LocalMemoryBase

func (m *ModuleContextOffsetData) LocalMemoryBase() Offset

LocalMemoryBase returns an offset of the first byte of the local memory.

func (*ModuleContextOffsetData) LocalMemoryLen

func (m *ModuleContextOffsetData) LocalMemoryLen() Offset

LocalMemoryLen returns an offset of the length of the local memory buffer.

func (*ModuleContextOffsetData) TableOffset

func (m *ModuleContextOffsetData) TableOffset(tableIndex int) Offset

TableOffset returns an offset of the i-th table instance.

type Offset

type Offset int32

Offset represents an offset of a field of a struct.

const (
	// ExecutionContextOffsetExitCodeOffset is an offset of `exitCode` field in wazevo.executionContext
	ExecutionContextOffsetExitCodeOffset Offset = 0
	// ExecutionContextOffsetCallerModuleContextPtr is an offset of `callerModuleContextPtr` field in wazevo.executionContext
	ExecutionContextOffsetCallerModuleContextPtr Offset = 8
	// ExecutionContextOffsetOriginalFramePointer is an offset of `originalFramePointer` field in wazevo.executionContext
	ExecutionContextOffsetOriginalFramePointer Offset = 16
	// ExecutionContextOffsetOriginalStackPointer is an offset of `originalStackPointer` field in wazevo.executionContext
	ExecutionContextOffsetOriginalStackPointer Offset = 24
	// ExecutionContextOffsetGoReturnAddress is an offset of `goReturnAddress` field in wazevo.executionContext
	ExecutionContextOffsetGoReturnAddress Offset = 32
	// ExecutionContextOffsetStackBottomPtr is an offset of `stackBottomPtr` field in wazevo.executionContext
	ExecutionContextOffsetStackBottomPtr Offset = 40
	// ExecutionContextOffsetGoCallReturnAddress is an offset of `goCallReturnAddress` field in wazevo.executionContext
	ExecutionContextOffsetGoCallReturnAddress Offset = 48
	// ExecutionContextOffsetStackPointerBeforeGoCall is an offset of `StackPointerBeforeGoCall` field in wazevo.executionContext
	ExecutionContextOffsetStackPointerBeforeGoCall Offset = 56
	// ExecutionContextOffsetStackGrowRequiredSize is an offset of `stackGrowRequiredSize` field in wazevo.executionContext
	ExecutionContextOffsetStackGrowRequiredSize Offset = 64
	// ExecutionContextOffsetMemoryGrowTrampolineAddress is an offset of `memoryGrowTrampolineAddress` field in wazevo.executionContext
	ExecutionContextOffsetMemoryGrowTrampolineAddress Offset = 72
	// ExecutionContextOffsetStackGrowCallTrampolineAddress is an offset of `stackGrowCallTrampolineAddress` field in wazevo.executionContext.
	ExecutionContextOffsetStackGrowCallTrampolineAddress Offset = 80
	// ExecutionContextOffsetCheckModuleExitCodeTrampolineAddress is an offset of `checkModuleExitCodeTrampolineAddress` field in wazevo.executionContext.
	ExecutionContextOffsetCheckModuleExitCodeTrampolineAddress Offset = 88
	// ExecutionContextOffsetSavedRegistersBegin is an offset of the first element of `savedRegisters` field in wazevo.executionContext
	ExecutionContextOffsetSavedRegistersBegin Offset = 96
	// ExecutionContextOffsetGoFunctionCallCalleeModuleContextOpaque is an offset of `goFunctionCallCalleeModuleContextOpaque` field in wazevo.executionContext
	ExecutionContextOffsetGoFunctionCallCalleeModuleContextOpaque Offset = 1120
	// ExecutionContextOffsetTableGrowTrampolineAddress is an offset of `tableGrowTrampolineAddress` field in wazevo.executionContext
	ExecutionContextOffsetTableGrowTrampolineAddress Offset = 1128
	// ExecutionContextOffsetRefFuncTrampolineAddress is an offset of `refFuncTrampolineAddress` field in wazevo.executionContext
	ExecutionContextOffsetRefFuncTrampolineAddress      Offset = 1136
	ExecutionContextOffsetMemmoveAddress                Offset = 1144
	ExecutionContextOffsetFramePointerBeforeGoCall      Offset = 1152
	ExecutionContextOffsetMemoryWait32TrampolineAddress Offset = 1160
	ExecutionContextOffsetMemoryWait64TrampolineAddress Offset = 1168
	ExecutionContextOffsetMemoryNotifyTrampolineAddress Offset = 1176
)

func (Offset) I64

func (o Offset) I64() int64

I64 encodes an Offset as int64 for convenience.

func (Offset) U32

func (o Offset) U32() uint32

U32 encodes an Offset as uint32 for convenience.

func (Offset) U64

func (o Offset) U64() uint64

U64 encodes an Offset as int64 for convenience.

type Perfmap added in v1.6.0

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

Perfmap holds perfmap entries to be flushed into a perfmap file.

var PerfMap *Perfmap

func (*Perfmap) AddEntry added in v1.6.0

func (f *Perfmap) AddEntry(addr uintptr, size uint64, name string)

AddEntry writes a perfmap entry directly into the perfmap file, not using the entries.

func (*Perfmap) AddModuleEntry added in v1.6.0

func (f *Perfmap) AddModuleEntry(index int, offset int64, size uint64, name string)

AddModuleEntry adds a perfmap entry into the perfmap file. index is the index of the function in the module, offset is the offset of the function in the module, size is the size of the function, and name is the name of the function.

Note that the entries are not flushed into the perfmap file until Flush is called, and the entries are module-scoped; Perfmap must be locked until Flush is called.

func (*Perfmap) Clear added in v1.6.0

func (f *Perfmap) Clear()

Clear clears the perfmap entries not yet flushed.

func (*Perfmap) Flush added in v1.6.0

func (f *Perfmap) Flush(addr uintptr, functionOffsets []int)

Flush writes the perfmap entries into the perfmap file where the entries are adjusted by the given `addr` and `functionOffsets`.

func (*Perfmap) Lock added in v1.6.0

func (f *Perfmap) Lock()

func (*Perfmap) Unlock added in v1.6.0

func (f *Perfmap) Unlock()

type Pool

type Pool[T any] struct {
	// contains filtered or unexported fields
}

Pool is a pool of T that can be allocated and reset. This is useful to avoid unnecessary allocations.

func NewPool

func NewPool[T any](resetFn func(*T)) Pool[T]

NewPool returns a new Pool. resetFn is called when a new T is allocated in Pool.Allocate.

func (*Pool[T]) Allocate

func (p *Pool[T]) Allocate() *T

Allocate allocates a new T from the pool.

func (*Pool[T]) Allocated

func (p *Pool[T]) Allocated() int

Allocated returns the number of allocated T currently in the pool.

func (*Pool[T]) Reset

func (p *Pool[T]) Reset()

Reset resets the pool.

func (*Pool[T]) View

func (p *Pool[T]) View(i int) *T

View returns the pointer to i-th item from the pool.

type Queue added in v1.7.0

type Queue[T any] struct {
	Data []T
	// contains filtered or unexported fields
}

Queue is the resettable queue where the underlying slice is reused.

func (*Queue[T]) Dequeue added in v1.7.0

func (q *Queue[T]) Dequeue() (ret T)

func (*Queue[T]) Empty added in v1.7.0

func (q *Queue[T]) Empty() bool

func (*Queue[T]) Enqueue added in v1.7.0

func (q *Queue[T]) Enqueue(v T)

func (*Queue[T]) Reset added in v1.7.0

func (q *Queue[T]) Reset()

type VarLength added in v1.7.0

type VarLength[T any] struct {
	// contains filtered or unexported fields
}

VarLength is a variable length array that can be reused via a pool.

func NewNilVarLength added in v1.7.0

func NewNilVarLength[T any]() VarLength[T]

NewNilVarLength returns a new VarLength[T] with a nil backing.

func (VarLength[T]) Append added in v1.7.0

func (i VarLength[T]) Append(p *VarLengthPool[T], items ...T) VarLength[T]

Append appends items to the backing slice just like the `append` builtin function in Go.

func (VarLength[T]) Cut added in v1.7.0

func (i VarLength[T]) Cut(n int)

Cut cuts the backing slice to the given length. Precondition: n <= len(i.backing).

func (VarLength[T]) View added in v1.7.0

func (i VarLength[T]) View() []T

View returns the backing slice.

type VarLengthPool added in v1.7.0

type VarLengthPool[T any] struct {
	// contains filtered or unexported fields
}

VarLengthPool is a pool of VarLength[T] that can be allocated and reset.

func NewVarLengthPool added in v1.7.0

func NewVarLengthPool[T any]() VarLengthPool[T]

NewVarLengthPool returns a new VarLengthPool.

func (*VarLengthPool[T]) Allocate added in v1.7.0

func (p *VarLengthPool[T]) Allocate(knownMin int) VarLength[T]

Allocate allocates a new VarLength[T] from the pool.

func (*VarLengthPool[T]) Reset added in v1.7.0

func (p *VarLengthPool[T]) Reset()

Reset resets the pool.

Jump to

Keyboard shortcuts

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