package emscripten

import "github.com/tetratelabs/wazero/internal/emscripten"

Index

Constants

const FunctionNotifyMemoryGrowth = "emscripten_notify_memory_growth"
const FunctionThrowLongjmp = "_emscripten_throw_longjmp"

Emscripten uses this host method to throw an error that can then be caught in the dynamic invoke functions. Emscripten uses this to allow for setjmp/longjmp support. When this error is seen in the invoke handler, it ignores the error and does not act on it.

const InvokePrefix = "invoke_"

InvokePrefix is the naming convention of Emscripten dynamic functions.

All `invoke_` functions have an initial "index" parameter of api.ValueTypeI32. This is the index of the desired funcref in the only table in the module. The type of the funcref is via naming convention. The first character after `invoke_` decides the result type: 'v' for no result or 'i' for api.ValueTypeI32. Any count of 'i' following that are api.ValueTypeI32 parameters.

For example, the function `invoke_iiiii` signature has five parameters, but also five i's. The five 'i's mean there are four parameters

(import "env" "invoke_iiiii" (func $invoke_iiiii
	(param i32 i32 i32 i32 i32) (result i32))))

So, the above function if invoked `invoke_iiiii(1234, 1, 2, 3, 4)` would look up the funcref at table index 1234, which has a type i32i32i3232_i32 and invoke it with the remaining parameters.

Variables

var (
	ThrowLongjmpError = errors.New("_emscripten_throw_longjmp")
	ThrowLongjmp      = &wasm.HostFunc{
		ExportName: FunctionThrowLongjmp,
		Name:       FunctionThrowLongjmp,
		ParamTypes: []wasm.ValueType{},
		ParamNames: []string{},
		Code: wasm.Code{GoFunc: api.GoModuleFunc(func(context.Context, api.Module, []uint64) {
			panic(ThrowLongjmpError)
		})},
	}
)
var NotifyMemoryGrowth = &wasm.HostFunc{
	ExportName: FunctionNotifyMemoryGrowth,
	Name:       FunctionNotifyMemoryGrowth,
	ParamTypes: []wasm.ValueType{wasm.ValueTypeI32},
	ParamNames: []string{"memory_index"},
	Code:       wasm.Code{GoFunc: api.GoModuleFunc(func(context.Context, api.Module, []uint64) {})},
}

Functions

func NewInvokeFunc

func NewInvokeFunc(importName string, params, results []api.ValueType) *wasm.HostFunc

Types

type InvokeFunc

type InvokeFunc struct {
	*wasm.FunctionType
}

func (*InvokeFunc) Call

func (v *InvokeFunc) Call(ctx context.Context, mod api.Module, stack []uint64)

Call implements api.GoModuleFunction by special casing dynamic calls needed for emscripten `invoke_` functions such as `invoke_ii` or `invoke_v`.

Source Files

emscripten.go

Version
v1.9.0 (latest)
Published
Feb 18, 2025
Platform
linux/amd64
Imports
7 packages
Last checked
4 days ago

Tools for package owners.