wazevoapi

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FrontEndLoggingEnabled = false
	SSALoggingEnabled      = false
	RegAllocLoggingEnabled = false
)
View Source
const (
	PrintSSA                       = false
	PrintOptimizedSSA              = false
	PrintBlockLaidOutSSA           = 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

func CheckStackGuardPage(s []byte)

CheckStackGuardPage checks the given stack guard page is not corrupted.

func DeterministicCompilationVerifierGetRandomizedLocalFunctionIndex

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

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

func DeterministicCompilationVerifierRandomizeIndexes

func DeterministicCompilationVerifierRandomizeIndexes(ctx context.Context)

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

func EnableHighRegisterPressure

func EnableHighRegisterPressure(ctx context.Context) context.Context

EnableHighRegisterPressure enables the high register pressure mode.

func GetCurrentFunctionIndex

func GetCurrentFunctionIndex(ctx context.Context) int

GetCurrentFunctionIndex returns the current function index.

func GetCurrentFunctionName

func GetCurrentFunctionName(ctx context.Context) string

GetCurrentFunctionName returns the current function name.

func GoFunctionIndexFromExitCode

func GoFunctionIndexFromExitCode(exitCode ExitCode) int

func IsHighRegisterPressure

func IsHighRegisterPressure(ctx context.Context) bool

IsHighRegisterPressure returns true if the current compilation is under high register pressure.

func NewDeterministicCompilationVerifierContext

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

func PrintEnabledIndex(ctx context.Context) bool

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

func SetCurrentFunctionName

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

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

func VerifyOrSetDeterministicCompilationContextValue

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
)

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

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

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

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

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

func (f *Perfmap) Clear()

Clear clears the perfmap entries not yet flushed.

func (*Perfmap) Flush

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

func (f *Perfmap) Lock()

func (*Perfmap) Unlock

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.

Jump to

Keyboard shortcuts

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