package wazevoapi
import "github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi"
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
- func ExitCodeCallGoFunctionWithIndex(index int, withListener bool) ExitCode
- func ExitCodeCallGoModuleFunctionWithIndex(index int, withListener bool) ExitCode
- func (e ExitCode) String() string
- type IDedPool
- func NewIDedPool[T any](resetFn func(*T)) IDedPool[T]
- func (p *IDedPool[T]) Get(id int) *T
- func (p *IDedPool[T]) GetOrAllocate(id int) *T
- func (p *IDedPool[T]) MaxIDEncountered() int
- func (p *IDedPool[T]) Reset()
- type ModuleContextOffsetData
- func NewModuleContextOffsetData(m *wasm.Module, withListener bool) 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
- func (f *Perfmap) AddEntry(addr uintptr, size uint64, name string)
- func (f *Perfmap) AddModuleEntry(index int, offset int64, size uint64, name string)
- func (f *Perfmap) Clear()
- func (f *Perfmap) Flush(addr uintptr, functionOffsets []int)
- func (f *Perfmap) Lock()
- func (f *Perfmap) Unlock()
- type Pool
- func NewPool[T any](resetFn func(*T)) Pool[T]
- func (p *Pool[T]) Allocate() *T
- func (p *Pool[T]) Allocated() int
- func (p *Pool[T]) Reset()
- func (p *Pool[T]) View(i int) *T
- type Queue
- func (q *Queue[T]) Dequeue() (ret T)
- func (q *Queue[T]) Empty() bool
- func (q *Queue[T]) Enqueue(v T)
- func (q *Queue[T]) Reset()
- type VarLength
- func NewNilVarLength[T any]() VarLength[T]
- func (i VarLength[T]) Append(p *VarLengthPool[T], items ...T) VarLength[T]
- func (i VarLength[T]) Cut(n int)
- func (i VarLength[T]) View() []T
- type VarLengthPool
Constants ¶
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 -----
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 ¶
DeterministicCompilationVerifierRandomizeIndexes randomizes the indexes for the deterministic compilation verifier. To get the randomized index, use DeterministicCompilationVerifierGetRandomizedLocalFunctionIndex.
func GetCurrentFunctionIndex ¶
GetCurrentFunctionIndex returns the current function index.
func GetCurrentFunctionName ¶
GetCurrentFunctionName returns the current function name.
func GoFunctionIndexFromExitCode ¶
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 ¶
PrintEnabledIndex returns true if the current function index is the print target.
func PtrFromUintptr ¶
PtrFromUintptr resurrects the original *T from the given uintptr. The caller of this function MUST be sure that ptr is valid.
func ResetMap ¶
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 ¶
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 ExitCodeMemoryWait32 ExitCodeMemoryWait64 ExitCodeMemoryNotify ExitCodeUnalignedAtomic )
func ExitCodeCallGoFunctionWithIndex ¶
func ExitCodeCallGoModuleFunctionWithIndex ¶
func (ExitCode) String ¶
String implements fmt.Stringer.
type IDedPool ¶
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 ¶
NewIDedPool returns a new IDedPool.
func (*IDedPool[T]) Get ¶
Get returns the T with the given id, or nil if it's not allocated.
func (*IDedPool[T]) GetOrAllocate ¶
GetOrAllocate returns the T with the given id.
func (*IDedPool[T]) MaxIDEncountered ¶
MaxIDEncountered returns the maximum id encountered so far.
func (*IDedPool[T]) Reset ¶
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 ¶
I64 encodes an Offset as int64 for convenience.
func (Offset) U32 ¶
U32 encodes an Offset as uint32 for convenience.
func (Offset) U64 ¶
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 ¶
AddEntry writes a perfmap entry directly into the perfmap file, not using the entries.
func (*Perfmap) AddModuleEntry ¶
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 ¶
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 ¶
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 ¶
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 ¶
View returns the pointer to i-th item from the pool.
type Queue ¶
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 ¶
func (q *Queue[T]) Dequeue() (ret T)
func (*Queue[T]) Empty ¶
func (*Queue[T]) Enqueue ¶
func (q *Queue[T]) Enqueue(v T)
func (*Queue[T]) Reset ¶
func (q *Queue[T]) Reset()
type VarLength ¶
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 ¶
NewNilVarLength returns a new VarLength[T] with a nil backing.
func (VarLength[T]) Append ¶
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 ¶
Cut cuts the backing slice to the given length. Precondition: n <= len(i.backing).
func (VarLength[T]) View ¶
func (i VarLength[T]) View() []T
View returns the backing slice.
type VarLengthPool ¶
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 ¶
func NewVarLengthPool[T any]() VarLengthPool[T]
NewVarLengthPool returns a new VarLengthPool.
func (*VarLengthPool[T]) Allocate ¶
func (p *VarLengthPool[T]) Allocate(knownMin int) VarLength[T]
Allocate allocates a new VarLength[T] from the pool.
func (*VarLengthPool[T]) Reset ¶
func (p *VarLengthPool[T]) Reset()
Reset resets the pool.
Source Files ¶
debug_options.go exitcode.go offsetdata.go perfmap.go perfmap_disabled.go pool.go ptr.go queue.go resetmap.go
- Version
- v1.9.0 (latest)
- Published
- Feb 18, 2025
- Platform
- linux/amd64
- Imports
- 10 packages
- Last checked
- 4 days ago –
Tools for package owners.