Documentation
¶
Index ¶
- Constants
- func CheckStackGuardPage(s []byte)
- func DeterministicCompilationVerifierGetRandomizedLocalFunctionIndex(ctx context.Context, index int) int
- func DeterministicCompilationVerifierRandomizeIndexes(ctx context.Context)
- func GetCurrentFunctionIndex(ctx context.Context) int
- func GetCurrentFunctionName(ctx context.Context) string
- func GoFunctionIndexFromExitCode(exitCode ExitCode) int
- func NewDeterministicCompilationVerifierContext(ctx context.Context, localFunctions int) context.Context
- func PrintEnabledIndex(ctx context.Context) bool
- func PtrFromUintptr[T any](ptr uintptr) *T
- func ResetMap[K comparable, V any](m map[K]V) map[K]V
- func SetCurrentFunctionName(ctx context.Context, index int, functionName string) context.Context
- func VerifyOrSetDeterministicCompilationContextValue(ctx context.Context, scope string, newValue string)
- type ExitCode
- type IDedPool
- type ModuleContextOffsetData
- func (m *ModuleContextOffsetData) GlobalInstanceOffset(i wasm.Index) Offset
- func (m *ModuleContextOffsetData) ImportedFunctionOffset(i wasm.Index) (executableOffset, moduleCtxOffset, typeIDOffset Offset)
- func (m *ModuleContextOffsetData) LocalMemoryBase() Offset
- func (m *ModuleContextOffsetData) LocalMemoryLen() Offset
- func (m *ModuleContextOffsetData) TableOffset(tableIndex int) Offset
- type Offset
- type Perfmap
- type Pool
- type Queue
- type VarLength
- type VarLengthPool
Constants ¶
const ( FrontEndLoggingEnabled = false SSALoggingEnabled = false RegAllocLoggingEnabled = false )
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 )
const ( // StackGuardCheckEnabled enables the stack guard check to ensure that our stack bounds check works correctly. StackGuardCheckEnabled = false StackGuardCheckGuardPageSize = 8096 )
----- Stack Guard Check -----
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 )
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 )
const ExitCodeMask = 0xff
const NeedFunctionNameInContext = PrintSSA || PrintOptimizedSSA || PrintSSAToBackendIRLowering || PrintRegisterAllocated || PrintFinalizedMachineCode || PrintMachineCodeHexPerFunction || DeterministicCompilationVerifierEnabled || PerfMapEnabled
nolint
const PerfMapEnabled = false
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
DeterministicCompilationVerifierRandomizeIndexes randomizes the indexes for the deterministic compilation verifier. To get the randomized index, use DeterministicCompilationVerifierGetRandomizedLocalFunctionIndex.
func GetCurrentFunctionIndex ¶ added in v1.6.0
GetCurrentFunctionIndex returns the current function index.
func GetCurrentFunctionName ¶ added in v1.6.0
GetCurrentFunctionName returns the current function name.
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
PrintEnabledIndex returns true if the current function index is the print target.
func PtrFromUintptr ¶ added in v1.7.0
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
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 )
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
NewIDedPool returns a new IDedPool.
func (*IDedPool[T]) Get ¶ added in v1.7.0
Get returns the T with the given id, or nil if it's not allocated.
func (*IDedPool[T]) GetOrAllocate ¶ added in v1.7.0
GetOrAllocate returns the T with the given id.
func (*IDedPool[T]) MaxIDEncountered ¶ added in v1.7.0
MaxIDEncountered returns the maximum id encountered so far.
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 )
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
AddEntry writes a perfmap entry directly into the perfmap file, not using the entries.
func (*Perfmap) AddModuleEntry ¶ added in v1.6.0
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.
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 ¶
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.
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.
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
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.
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.