nativeapi

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 native.functionInstance.
	FunctionInstanceSize = 24
	// FunctionInstanceExecutableOffset is an offset of `executable` field in native.functionInstance
	FunctionInstanceExecutableOffset = 0
	// FunctionInstanceModuleContextOpaquePtrOffset is an offset of `moduleContextOpaquePtr` field in native.functionInstance
	FunctionInstanceModuleContextOpaquePtrOffset = 8
	// FunctionInstanceTypeIDOffset is an offset of `typeID` field in native.functionInstance
	FunctionInstanceTypeIDOffset = 16
)
View Source
const (
	// GStackguard0Offset is the offset of stackguard0 in the runtime's g, right
	// after g.stack (two words).
	GStackguard0Offset = 16
	// StackPreempt is what the runtime stores in g.stackguard0 to ask a
	// goroutine to stop: runtime/stack.go's uintptrMask & -1314.
	StackPreempt = uint64(0xfffffffffffffade)
)

Go cannot preempt compiled wasm: asynchronous preemption declines a PC that is not Go's. A loop that never returns to Go therefore holds up every stop-the-world, and with it every goroutine in the process, until it ends. Compiled loops read the word the runtime uses to ask a goroutine to stop instead, the one a Go function prologue reads, and return to Go when it is set. Both facts below are runtime internals; TestPreemptWordLayout pins them against the toolchain's own sources.

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 AssertSavedRegistersFit added in v0.2.0

func AssertSavedRegistersFit(end int64)

AssertSavedRegistersFit panics if a save/restore layout that ends at absolute offset end (exclusive) within native.executionContext would run past savedRegisters and into the fields after it -- which, since the store is a raw offset off the execution context pointer, would silently corrupt trampoline addresses and guest state rather than fault. Every backend layout of that region goes through here; see ExecutionContextOffsetSavedRegistersEnd.

func CheckStackGuardPage

func CheckStackGuardPage(s []byte)

CheckStackGuardPage checks the given stack guard page is not corrupted.

func DeterministicCompilationVerifierRandomizeIndexes

func DeterministicCompilationVerifierRandomizeIndexes(ctx context.Context) []int

DeterministicCompilationVerifierRandomizeIndexes randomizes the indexes for the deterministic compilation verifier. Returns a slice that maps an index to the randomized index.

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

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

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

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 CatchClauseInstance

type CatchClauseInstance struct {
	Kind     byte   // wasm.CatchKindCatch, etc.
	TagIndex uint32 // module-local tag index
}

CatchClauseInstance is a runtime catch clause with resolved tag index.

type EhClause

type EhClause struct {
	// Kind is one of wasm.CatchKindCatch, CatchKindCatchRef, CatchKindCatchAll,
	// CatchKindCatchAllRef.
	Kind byte
	// TagIndex is the module-local tag index (meaningful for Catch/CatchRef only).
	TagIndex uint32
	// LandingPad is the executable offset of this clause's handler block.
	// Function-relative as constructed by the compiler; rebased to an
	// absolute address (like sourceMap.executableOffsets) when the
	// compiledModule's executable is finalized / deserialized from cache.
	LandingPad uintptr
}

EhClause is one compiled catch clause belonging to an EhEntry. Unlike the interpreter's exceptionTableCatchClause (which has a single targetPC per clause), the compiled analogue needs a per-clause LandingPad because the native frontend compiles one dedicated handler block per catch clause (each reloading a different set of exception params / exnref and jumping to a different wasm target block).

type EhEntry

type EhEntry struct {
	// StartOffset/EndOffset delimit one contiguous run of native code
	// belonging to this try_table's body: any return address in
	// [StartOffset, EndOffset) is considered "inside" this try for the
	// purposes of exception matching. Function-relative as constructed;
	// rebased to absolute addresses at the same time as LandingPad.
	//
	// A single try_table may be represented by *multiple* EhEntry values
	// (one per contiguous run) if block layout did not keep its body's
	// native code contiguous; all such runs share the same Clauses and
	// TryTableID.
	StartOffset, EndOffset uintptr
	// Clauses are this try_table's catch clauses, in declaration order (the
	// same order used for first-match semantics today).
	Clauses []EhClause
	// TryTableID indexes into compiledModule.tryTableInfo, giving access to
	// NumLocals/ReuseLocals so the throw path can correctly restore
	// execCtx.localsSaveAreaPtr when unwinding past an abandoned frame that
	// had its own (now-discarded) locals save area.
	TryTableID int
}

EhEntry is one PC-range entry in a function's exception side table: the compiled analogue of the interpreter's exceptionTableEntry (interpreter/interpreter.go). Entries for a given function are stored in *encounter order* -- i.e. a nested try_table's entry is appended after its lexically-enclosing try_table's entry, exactly mirroring how the interpreter builds its exceptionTable during lowering. A throw searches a function's entries **backwards**, so this ordering alone (no separate depth field) gives innermost-try-first matching, identical to searchExceptionTable's `for i := len(table) - 1; i >= 0; i--` loop.

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 is how a preemption check returns to Go when the runtime asked
	// the goroutine to stop (see ssa.OpcodePreemptRequested): Go yields there, and unwinds the
	// call instead of resuming it if the module was closed or the call's context is done.
	ExitCodeCheckModuleExitCode
	ExitCodeCallListenerBefore
	ExitCodeCallListenerAfter
	ExitCodeCallGoModuleFunctionWithListener
	ExitCodeCallGoFunctionWithListener
	ExitCodeTableGrow
	ExitCodeRefFunc
	ExitCodeMemoryWait32
	ExitCodeMemoryWait64
	ExitCodeMemoryNotify
	ExitCodeUnalignedAtomic
	// ExitCodeThrowAlloc is the first phase of wasm throw: Go allocates the
	// Exception heap object (with Params sized to the tag's param count) and
	// writes its Params data pointer to execCtx.exceptionParamsPtr.
	// Compiled code then stores params directly into the Exception.Params slice,
	// followed by ExitCodeThrow to search for a matching handler.
	ExitCodeThrowAlloc
	// ExitCodeThrow is the shared throw/throw_ref exit code.
	// The exnref is passed on the stack. The handler searches for a
	// matching catch clause and restores the stack checkpoint.
	ExitCodeThrow
	// ExitCodeNullReference is an exit code for a null reference trap (throw_ref with null exnref).
	ExitCodeNullReference
	// ExitCodeGCCheck is the shared exit code for the GC proposal's runtime type checks: ref.test,
	// ref.cast, and the subtype-aware call_indirect check. Which one is meant is the trampoline's mode
	// operand; see gcCheckMode.
	ExitCodeGCCheck
)

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

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

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

NewIDedPool returns a new IDedPool.

func (*IDedPool[T]) Get

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

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

GetOrAllocate returns the T with the given id.

func (*IDedPool[T]) MaxIDEncountered

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

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,

	MemoriesBegin,
	ImportedFunctionsBegin,
	GlobalsBegin,
	TypeIDs1stElement,
	TablesBegin,
	TagsBegin,
	BeforeListenerTrampolines1stElement,
	AfterListenerTrampolines1stElement,
	DataInstances1stElement,
	ElementInstances1stElement Offset
}

ModuleContextOffsetData allows the compilers to get the information about offsets to the fields of native.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 native.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 native.functionInstance whose size matches FunctionInstanceSize.

func (*ModuleContextOffsetData) LocalMemoryInstancePtrOffset added in v0.2.0

func (m *ModuleContextOffsetData) LocalMemoryInstancePtrOffset(memoryIndex int) Offset

LocalMemoryInstancePtrOffset returns the offset, within the memoryIndex-th local memory's record, of the *wasm.MemoryInstance pointer field (only meaningful for a local, i.e. non-imported, memory -- see MemoriesBegin).

func (*ModuleContextOffsetData) MemoryOffset added in v0.2.0

func (m *ModuleContextOffsetData) MemoryOffset(memoryIndex int) Offset

MemoryOffset returns the offset of the memoryIndex-th memory's record.

func (*ModuleContextOffsetData) TableOffset

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

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

func (*ModuleContextOffsetData) TagOffset

func (m *ModuleContextOffsetData) TagOffset(tagIndex int) Offset

TagOffset returns an offset of the i-th tag instance pointer.

type Offset

type Offset int32

Offset represents an offset of a field of a struct.

const (
	// ExecutionContextOffsetExitCodeOffset is an offset of `exitCode` field in native.executionContext
	ExecutionContextOffsetExitCodeOffset Offset = 0
	// ExecutionContextOffsetGCPause is the flag the collector writes 1 into to stop the world, which a call reads
	// where it can park (see callEngine.parkIfPaused). It sits in the padding
	// after the exit code, so the collector costs this struct nothing at all -- which matters because it is
	// embedded in the per-call callEngine, close enough to a Go size class boundary that eight bytes would cost
	// 256 per call.
	ExecutionContextOffsetGCPause Offset = 4
	// ExecutionContextOffsetCallerModuleContextPtr is an offset of `callerModuleContextPtr` field in native.executionContext
	ExecutionContextOffsetCallerModuleContextPtr Offset = 8
	// ExecutionContextOffsetOriginalFramePointer is an offset of `originalFramePointer` field in native.executionContext
	ExecutionContextOffsetOriginalFramePointer Offset = 16
	// ExecutionContextOffsetOriginalStackPointer is an offset of `originalStackPointer` field in native.executionContext
	ExecutionContextOffsetOriginalStackPointer Offset = 24
	// ExecutionContextOffsetGoReturnAddress is an offset of `goReturnAddress` field in native.executionContext
	ExecutionContextOffsetGoReturnAddress Offset = 32
	// ExecutionContextOffsetStackBottomPtr is an offset of `stackBottomPtr` field in native.executionContext.
	// NOTE: the value at this offset is the stack-bounds-check LIMIT, i.e. the
	// buffer bottom biased UP by backend.StackBoundsCheckMarginBytes (H7's
	// MARGIN); the prologue/go-call checks compare SP directly against it. See
	// callEngine.stackCheckLimitPtr and the proof on StackBoundsCheckMarginBytes.
	ExecutionContextOffsetStackBottomPtr Offset = 40
	// ExecutionContextOffsetGoCallReturnAddress is an offset of `goCallReturnAddress` field in native.executionContext
	ExecutionContextOffsetGoCallReturnAddress Offset = 48
	// ExecutionContextOffsetStackPointerBeforeGoCall is an offset of `StackPointerBeforeGoCall` field in native.executionContext
	ExecutionContextOffsetStackPointerBeforeGoCall Offset = 56
	// ExecutionContextOffsetStackGrowRequiredSize is an offset of `stackGrowRequiredSize` field in native.executionContext
	ExecutionContextOffsetStackGrowRequiredSize Offset = 64
	// ExecutionContextOffsetMemoryGrowTrampolineAddress is an offset of `memoryGrowTrampolineAddress` field in native.executionContext
	ExecutionContextOffsetMemoryGrowTrampolineAddress Offset = 72
	// ExecutionContextOffsetStackGrowCallTrampolineAddress is an offset of `stackGrowCallTrampolineAddress` field in native.executionContext.
	ExecutionContextOffsetStackGrowCallTrampolineAddress Offset = 80
	// ExecutionContextOffsetCheckModuleExitCodeTrampolineAddress is an offset of `checkModuleExitCodeTrampolineAddress` field in native.executionContext.
	ExecutionContextOffsetCheckModuleExitCodeTrampolineAddress Offset = 88
	// ExecutionContextOffsetSavedRegistersBegin is an offset of the first element of `savedRegisters` field in native.executionContext
	ExecutionContextOffsetSavedRegistersBegin Offset = 96
	// ExecutionContextOffsetSavedRegistersEnd is one past the last byte of `savedRegisters`.
	//
	// The field is sized to the largest layout either ISA actually writes there, not to a round
	// number: amd64's stackGrowSaveVRegs needs 464 bytes (29 registers x a 16-byte slot each) and
	// arm64's saveRequiredRegs needs 496 (stp/ldp-paired, see registerSaveRestoreSlots). The
	// remaining slack is deliberately small -- savedRegisters sits inside the per-call callEngine,
	// so every unused byte here is paid on every invocation, and the 1024 bytes this used to be
	// pushed that allocation a whole Go size class up.
	//
	// AssertSavedRegistersFit is what keeps it honest: both backends run it over every register
	// list they lay out, so a list that outgrows this bound fails loudly at code-generation time
	// (i.e. on the first module ever compiled) rather than silently writing over the fields below.
	ExecutionContextOffsetSavedRegistersEnd Offset = 608
	// ExecutionContextOffsetGoFunctionCallCalleeModuleContextOpaque is an offset of `goFunctionCallCalleeModuleContextOpaque` field in native.executionContext
	ExecutionContextOffsetGoFunctionCallCalleeModuleContextOpaque Offset = 608
	// ExecutionContextOffsetTableGrowTrampolineAddress is an offset of `tableGrowTrampolineAddress` field in native.executionContext
	ExecutionContextOffsetTableGrowTrampolineAddress Offset = 616
	// ExecutionContextOffsetRefFuncTrampolineAddress is an offset of `refFuncTrampolineAddress` field in native.executionContext
	ExecutionContextOffsetRefFuncTrampolineAddress      Offset = 624
	ExecutionContextOffsetMemmoveAddress                Offset = 632
	ExecutionContextOffsetFramePointerBeforeGoCall      Offset = 640
	ExecutionContextOffsetMemoryWait32TrampolineAddress Offset = 648
	ExecutionContextOffsetMemoryWait64TrampolineAddress Offset = 656
	ExecutionContextOffsetMemoryNotifyTrampolineAddress Offset = 664
	// ExecutionContextOffsetThrowAllocTrampolineAddress is the address of the
	// throw-alloc trampoline, which allocates the Exception heap object,
	// sets exceptionParamsPtr, and returns the exnref.
	ExecutionContextOffsetThrowAllocTrampolineAddress Offset = 672
	ExecutionContextOffsetThrowTrampolineAddress      Offset = 680
	// ExecutionContextOffsetExceptionRef holds the exnref of the caught exception,
	// used on the throw side and by catch_ref/catch_all_ref handlers.
	ExecutionContextOffsetExceptionRef Offset = 688
	// ExecutionContextOffsetExceptionParamsPtr points into the Exception's
	// Params slice backing array. Used by both throw (store params) and
	// catch (load params) sides.
	ExecutionContextOffsetExceptionParamsPtr Offset = 696
	// ExecutionContextOffsetCaughtExceptionClauseIdx is the caught flag: non-zero
	// while a throw resumes a catching frame, read by the check after every call
	// that can throw inside a try_table and cleared by its landing pad.
	ExecutionContextOffsetCaughtExceptionClauseIdx Offset = 704
	// ExecutionContextOffsetThrownTag is the *wasm.TagInstance of the exception
	// being caught, which the landing pad compares against its catch clauses.
	ExecutionContextOffsetThrownTag Offset = 712
	// ExecutionContextOffsetGCCheckTrampolineAddress is the address of the trampoline behind ref.test,
	// ref.cast and the subtype-aware call_indirect check. See nativeapi.ExitCodeGCCheck.
	ExecutionContextOffsetGCCheckTrampolineAddress Offset = 720
	// ExecutionContextOffsetMemclrAddress is the offset of `memclrAddress`, the entry PC of
	// the Go runtime's memclrNoHeapPointers, called by the memory.fill lowering.
	ExecutionContextOffsetMemclrAddress Offset = 728
	// ExecutionContextOffsetPreemptWordAddress is the offset of `preemptWordAddress`, the address
	// of the calling goroutine's g.stackguard0. See StackPreempt.
	ExecutionContextOffsetPreemptWordAddress Offset = 736
	// ExecutionContextOffsetYieldSavedLR is the offset of `yieldSavedLR`, where arm64 code keeps
	// the link register while it yields from a preemption check. See ssa.OpcodeYield.
	ExecutionContextOffsetYieldSavedLR Offset = 744
)

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) ClearFunction added in v0.6.0

func (f *Perfmap) ClearFunction(index int)

ClearFunction drops the entries not yet flushed for the function at index, whose code is being laid out again. Other functions' entries stay: a module's are flushed together.

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.

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 (q *Queue[T]) Empty() bool

func (*Queue[T]) Enqueue

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

func (*Queue[T]) Len added in v0.7.0

func (q *Queue[T]) Len() int

Len returns how many values are queued.

func (*Queue[T]) Reset

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

type ThrowFrame

type ThrowFrame struct {
	ReturnAddress uintptr
	SP, FP        uintptr
}

ThrowFrame is one frame yielded by the throw-time stack walk (the exception-handling variant of unwindStack that additionally recovers each frame's own base, not just its return address). Populated differently per ISA:

  • arm64 (backend/isa/arm64/unwind_stack.go): frames are chained via an in-stack frame_size word, so SP is directly, self-containedly recoverable during the walk; FP is unused (left zero) since arm64 has no dedicated frame-pointer register.
  • amd64 (backend/isa/amd64/stack.go): frames are chained via the classic RBP chain, so FP (=RBP) is directly recoverable during the walk, but SP is not (amd64 has no on-stack frame_size marker); the caller (call_engine.go) computes SP = FP - FrameSize() for whichever single frame turns out to match, using the compiled function's FrameSize (backend.Machine.FrameSize) recorded at compile time.

type TryTableInfo

type TryTableInfo struct {
	CatchClauses []CatchClauseInstance
	NumLocals    int
	// ReuseLocals is true for nested same-function try_tables that share
	// the enclosing try_table's locals save area instead of allocating.
	ReuseLocals bool
	// FloorSize is the number of wasm operand-stack values present *below*
	// this try_table's own block params at the point it is entered (the
	// "operand floor" -- see docs/design/eh-side-table.md sec 4.1, category
	// 4). These are values computed before the try that a catch
	// continuation may still consume; nothing inside the try body can
	// observe or mutate them (they are below its own floor), so a single
	// entry-time snapshot would suffice to reconstruct them -- but doing so
	// generally requires threading them through the catch target's block
	// params (so the SSA builder can merge the normal-path value with a
	// landing-pad reload), which touches every branch site that can target
	// a catch label; that is deferred (see call_engine.go's
	// activeCatchScope.savedRegisters doc comment).
	//
	// NOT currently used to skip the callee-saved-register snapshot/restore
	// (an earlier version of this pass gated it on FloorSize == 0 and
	// reverted that after it crashed a real C++/Emscripten-compiled module,
	// see activeCatchScope's doc comment for the full story): FloorSize
	// only accounts for *wasm-level* operand-stack values, but handler
	// blocks unconditionally call reloadAfterCall(), which reads through
	// moduleCtxPtrValue -- a per-function SSA value live across the entire
	// function body regardless of the wasm operand stack, and just as
	// vulnerable to living in a callee-saved register across the enter
	// call as any category-4 value. So FloorSize is computed and
	// serialized but currently inert; a future pass (Opus) should either
	// give moduleCtxPtrValue (and anything else with a whole-function live
	// range) its own memory-based reload in handler blocks -- symmetric to
	// how locals are reloaded -- or otherwise account for it, before this
	// field can safely gate anything.
	FloorSize int
}

TryTableInfo holds try_table metadata assigned during compilation and looked up at runtime by try_table ID.

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

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

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

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

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.

Jump to

Keyboard shortcuts

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