wasmtimex

package
v0.0.0-...-052ef2a Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExternKindFunc   = ExternKind(C.WASMTIME_EXTERN_FUNC)
	ExternKindGlobal = ExternKind(C.WASMTIME_EXTERN_GLOBAL)
	ExternKindTable  = ExternKind(C.WASMTIME_EXTERN_TABLE)
	ExternKindMemory = ExternKind(C.WASMTIME_EXTERN_MEMORY)
)
View Source
const (
	MutabilityConst = Mutability(C.WASM_CONST)
	MutabilityVar   = Mutability(C.WASM_VAR)
)
View Source
const (
	// StackOverflow the current stack space was exhausted.
	StackOverflow = TrapCode(C.WASMTIME_TRAP_CODE_STACK_OVERFLOW)
	// MemoryOutOfBounds out-of-bounds memory access.
	MemoryOutOfBounds = TrapCode(C.WASMTIME_TRAP_CODE_MEMORY_OUT_OF_BOUNDS)
	// HeapMisaligned a wasm atomic operation was presented with a not-naturally-aligned linear-memory address.
	HeapMisaligned = TrapCode(C.WASMTIME_TRAP_CODE_HEAP_MISALIGNED)
	// TableOutOfBounds out-of-bounds access to a table.
	TableOutOfBounds = TrapCode(C.WASMTIME_TRAP_CODE_TABLE_OUT_OF_BOUNDS)
	// IndirectCallToNull indirect call to a null table entry.
	IndirectCallToNull = TrapCode(C.WASMTIME_TRAP_CODE_INDIRECT_CALL_TO_NULL)
	// BadSignature signature mismatch on indirect call.
	BadSignature = TrapCode(C.WASMTIME_TRAP_CODE_BAD_SIGNATURE)
	// IntegerOverflow an integer arithmetic operation caused an overflow.
	IntegerOverflow = TrapCode(C.WASMTIME_TRAP_CODE_INTEGER_OVERFLOW)
	// IntegerDivisionByZero integer division by zero.
	IntegerDivisionByZero = TrapCode(C.WASMTIME_TRAP_CODE_INTEGER_DIVISION_BY_ZERO)
	// BadConversionToInteger failed float-to-int conversion.
	BadConversionToInteger = TrapCode(C.WASMTIME_TRAP_CODE_BAD_CONVERSION_TO_INTEGER)
	// UnreachableCodeReached code that was supposed to have been unreachable was reached.
	UnreachableCodeReached = TrapCode(C.WASMTIME_TRAP_CODE_UNREACHABLE_CODE_REACHED)
	// Interrupt execution has been interrupted.
	Interrupt = TrapCode(C.WASMTIME_TRAP_CODE_INTERRUPT)
)

Variables

Functions

func DefaultConfig

func DefaultConfig(cfg *Config)

func Deserialize

func Deserialize(engine *Engine, serialized []byte) (*Module, *Error)

Deserialize builds a module from serialized data.

This function does not take ownership of its arguments, but the returned error and module are owned by the caller.

This function is not safe to receive arbitrary user input. See the Rust documentation for more information on what inputs are safe to pass in here (e.g. only that of #wasmtime_module_serialize)

func EpochInterval

func EpochInterval() time.Duration

func GoTick

func GoTick()

func IsEpochThreadRunning

func IsEpochThreadRunning() bool

func NewEpochDeadline

func NewEpochDeadline(duration time.Duration) uint64

func NewGlobal

func NewGlobal(ctx *Context, ty *GlobalType, val Val) (*Global, *Error)

NewGlobal \brief Creates a new global value.

Creates a new host-defined global value within the provided `store`

\param store the store in which to create the global \param type the wasm type of the global being created \param val the initial value of the global \param ret a return pointer for the created global.

This function may return an error if the `val` argument does not match the specified type of the global, or if `val` comes from a different store than the one provided.

This function does not take ownership of its arguments but error is owned by the caller.

func NewInstance

func NewInstance(ctx *Context, module *Module, imports ...Extern) (instance Instance, trap *Trap, err *Error)

NewInstance instantiates a wasm module.

This function will instantiate a WebAssembly module with the provided imports, creating a WebAssembly instance. The returned instance can then afterwards be inspected for exports.

\param store the store in which to create the instance \param module the module that's being instantiated \param imports the imports provided to the module \param nimports the size of `imports` \param instance where to store the returned instance \param trap where to store the returned trap

This function requires that `imports` is the same size as the imports that `module` has. Additionally, the `imports` array must be 1:1 lined up with the imports of the `module` specified. This is intended to be relatively low level, and #wasmtime_linker_instantiate is provided for a more ergonomic name-based resolution API.

The states of return values from this function are similar to #wasmtime_func_call where an error can be returned meaning something like a link error in this context. A trap can be returned (meaning no error or instance is returned), or an instance can be returned (meaning no error or trap is returned).

Note that this function requires that all `imports` specified must be owned by the `store` provided as well.

This function does not take ownership of its arguments, but all return values are owned by the caller.

func NewMemory

func NewMemory(context *Context, memoryType *MemoryType) (Memory, *Error)

NewMemory creates a new WebAssembly linear memory

\param store the store to create the memory within
\param ty the type of the memory to create
\param ret where to store the returned memory

If an error happens when creating the memory it's returned and owned by the
caller. If an error happens then `ret` is not filled in.

func NewModule

func NewModule(engine *Engine, wasm ByteVec) (*Module, *Error)

NewModule compiles a WebAssembly binary into a #wasmtime_module_t

This function will compile a WebAssembly binary into an owned #wasm_module_t. This performs the same as #wasm_module_new except that it returns a #wasmtime_error_t type to get richer error information.

On success the returned #wasmtime_error_t is `NULL` and the `ret` pointer is filled in with a #wasm_module_t. On failure the #wasmtime_error_t is non-`NULL` and the `ret` pointer is unmodified.

This function does not take ownership of its arguments, but the returned error and module are owned by the caller.

func NewModuleFromBytes

func NewModuleFromBytes(engine *Engine, wasm []byte) (*Module, *Error)

NewModuleFromBytes compiles a WebAssembly binary into a #wasmtime_module_t

This function will compile a WebAssembly binary into an owned #wasm_module_t. This performs the same as #wasm_module_new except that it returns a #wasmtime_error_t type to get richer error information.

On success the returned #wasmtime_error_t is `NULL` and the `ret` pointer is filled in with a #wasm_module_t. On failure the #wasmtime_error_t is non-`NULL` and the `ret` pointer is unmodified.

This function does not take ownership of its arguments, but the returned error and module are owned by the caller.

func NewTable

func NewTable(context *Context, tableType *TableType, init Val) (Table, *Error)

NewTable Creates a new host-defined wasm table.

\param store the store to create the table within \param ty the type of the table to create \param init the initial value for this table's elements \param table where to store the returned table

This function does not take ownership of its parameters, but yields ownership of returned error. This function may return an error if the `init` value does not match `ty`, for example.

func RemoveEpochEngine

func RemoveEpochEngine(engine *Engine)

func SizeofvalTypeVec

func SizeofvalTypeVec() int

func StartEpochThread

func StartEpochThread(duration time.Duration, engine *Engine)

StartEpochThread starts a native thread that increments the epoch at an interval specified by the supplied duration. If a thread is active, then it will stop that thread and start a new thread with the specified duration.

func StartEpochThreadMultiple

func StartEpochThreadMultiple(duration time.Duration, engines ...*Engine)

func StopEpochThread

func StopEpochThread()

StopEpochThread stops the epoch thread if running.

func Wat2Wasm

func Wat2Wasm(wat string) (ByteVec, *Error)

Wat2Wasm converts the text format of WebAssembly to the binary format.

Takes the text format in-memory as input, and returns either the binary encoding of the text format or an error if parsing fails.

func Wat2WasmVec

func Wat2WasmVec(wat ByteVec) (ByteVec, *Error)

Wat2WasmVec converts the text format of WebAssembly to the binary format.

Takes the text format in-memory as input, and returns either the binary encoding of the text format or an error if parsing fails.

Types

type AsExternType

type AsExternType interface {
	AsExternType() *ExternType
}

AsExternType is an interface for all types which can be ExternType.

type BorrowedString

type BorrowedString string

func BorrowedStringOf

func BorrowedStringOf(data unsafe.Pointer, size int) BorrowedString

type ByteVec

type ByteVec struct {
	// contains filtered or unexported fields
}

func TempByteVec

func TempByteVec(b []byte) ByteVec

func (*ByteVec) Bytes

func (bv *ByteVec) Bytes() []byte

func (*ByteVec) Data

func (bv *ByteVec) Data() unsafe.Pointer

func (*ByteVec) Delete

func (bv *ByteVec) Delete()

func (*ByteVec) Size

func (bv *ByteVec) Size() int

func (*ByteVec) String

func (bv *ByteVec) String() string

func (*ByteVec) ToOwned

func (bv *ByteVec) ToOwned() string

func (*ByteVec) Unsafe

func (bv *ByteVec) Unsafe() []byte

func (*ByteVec) UnsafeString

func (bv *ByteVec) UnsafeString() string

type Callback

type Callback C.wasmtime_func_callback_t

Callback signature for #wasmtime_func_new.

This is the function signature for host functions that can be made accessible to WebAssembly. The arguments to this function are:

\param env user-provided argument passed to #wasmtime_func_new \param caller a temporary object that can only be used during this function call. Used to acquire #wasmtime_context_t or caller's state \param args the arguments provided to this function invocation \param nargs how many arguments are provided \param results where to write the results of this function \param nresults how many results must be produced

Callbacks are guaranteed to get called with the right types of arguments, but they must produce the correct number and types of results. Failure to do so will cause traps to get raised on the wasm side.

This callback can optionally return a #wasm_trap_t indicating that a trap should be raised in WebAssembly. It's expected that in this case the caller relinquishes ownership of the trap, and it is passed back to the engine.

type Caller

type Caller C.wasmtime_caller_t

Caller

\typedef wasmtime_caller_t
\brief Alias to #wasmtime_caller

\brief Structure used to learn about the caller of a host-defined function.
\struct wasmtime_caller

This structure is an argument to #wasmtime_func_callback_t. The purpose
of this structure is acquire a #wasmtime_context_t pointer to interact with
objects, but it can also be used for inspect the state of the caller (such as
getting memories and functions) with #wasmtime_caller_export_get.

This object is never owned and does not need to be deleted.

func (*Caller) Context

func (c *Caller) Context() *Context

Context returns the store context of the caller object.

type Config

type Config C.wasm_config_t

Config holds options used to create an Engine and customize its behavior.

func NewConfig

func NewConfig() *Config

NewConfig creates a new `Config` with all default options configured.

func (*Config) CacheConfigLoad

func (cfg *Config) CacheConfigLoad(path string) *Error

CacheConfigLoad enables compiled code caching for this `Config` using the settings specified in the configuration file `path`.

For more information about caching and configuration options see https://bytecodealliance.github.io/wasmtime/cli-cache.html

func (*Config) CacheConfigLoadDefault

func (cfg *Config) CacheConfigLoadDefault() *Error

CacheConfigLoadDefault enables compiled code caching for this `Config` using the default settings configuration can be found.

For more information about caching see https://bytecodealliance.github.io/wasmtime/cli-cache.html

func (*Config) Delete

func (cfg *Config) Delete()

func (*Config) SetConsumeFuel

func (cfg *Config) SetConsumeFuel(enabled bool)

SetConsumFuel configures whether fuel is enabled

func (*Config) SetCraneliftDebugVerifier

func (cfg *Config) SetCraneliftDebugVerifier(enabled bool)

SetCraneliftDebugVerifier configures whether the cranelift debug verifier will be active when cranelift is used to compile wasm code.

func (*Config) SetCraneliftOptLevel

func (cfg *Config) SetCraneliftOptLevel(level OptLevel)

SetCraneliftOptLevel configures the cranelift optimization level for generated code

func (*Config) SetDebugInfo

func (cfg *Config) SetDebugInfo(enabled bool)

SetDebugInfo configures whether dwarf debug information for JIT code is enabled

func (*Config) SetEpochInterruption

func (cfg *Config) SetEpochInterruption(enable bool)

SetEpochInterruption enables epoch-based instrumentation of generated code to interrupt WebAssembly execution when the current engine epoch exceeds a defined threshold.

func (*Config) SetProfiler

func (cfg *Config) SetProfiler(profiler ProfilingStrategy)

SetProfiler configures what profiler strategy to use for generated code

func (*Config) SetStrategy

func (cfg *Config) SetStrategy(strat Strategy)

SetStrategy configures what compilation strategy is used to compile wasm code

func (*Config) SetWasmBulkMemory

func (cfg *Config) SetWasmBulkMemory(enabled bool)

SetWasmBulkMemory configures whether the wasm bulk memory proposal is enabled

func (*Config) SetWasmMemory64

func (cfg *Config) SetWasmMemory64(enabled bool)

SetWasmMemory64 configures whether the wasm memory64 proposal is enabled

func (*Config) SetWasmMultiMemory

func (cfg *Config) SetWasmMultiMemory(enabled bool)

SetWasmMultiMemory configures whether the wasm multi memory proposal is enabled

func (*Config) SetWasmMultiValue

func (cfg *Config) SetWasmMultiValue(enabled bool)

SetWasmMultiValue configures whether the wasm multi value proposal is enabled

func (*Config) SetWasmReferenceTypes

func (cfg *Config) SetWasmReferenceTypes(enabled bool)

SetWasmReferenceTypes configures whether the wasm reference types proposal is enabled

func (*Config) SetWasmSIMD

func (cfg *Config) SetWasmSIMD(enabled bool)

SetWasmSIMD configures whether the wasm SIMD proposal is enabled

func (*Config) SetWasmThreads

func (cfg *Config) SetWasmThreads(enabled bool)

SetWasmThreads configures whether the wasm threads proposal is enabled

type Context

type Context C.wasmtime_context_t

Context \typedef wasmtime_context_t \brief Convenience alias for #wasmtime_context

\struct wasmtime_context \brief An interior pointer into a #wasmtime_store_t which is used as "context" for many functions.

This context pointer is used pervasively throughout Wasmtime's API. This can be acquired from #wasmtime_store_context or #wasmtime_caller_context. The context pointer for a store is the same for the entire lifetime of a store, so it can safely be stored adjacent to a #wasmtime_store_t itself.

Usage of a #wasmtime_context_t must not outlive the original #wasmtime_store_t. Additionally, #wasmtime_context_t can only be used in situations where it has explicitly been granted access to doing so. For example finalizers cannot use #wasmtime_context_t because they are not given access to it.

func (*Context) AddFuel

func (c *Context) AddFuel(fuel uint64) *Error

AddFuel adds fuel to this context's store for wasm to consume while executing.

For this method to work fuel consumption must be enabled via #wasmtime_config_consume_fuel_set. By default a store starts with 0 fuel for wasm to execute with (meaning it will immediately trap). This function must be called for the store to have some fuel to allow WebAssembly to execute.

Note that at this time when fuel is entirely consumed it will cause wasm to trap. More usages of fuel are planned for the future.

If fuel is not enabled within this store then an error is returned. If fuel is successfully added then NULL is returned.

func (*Context) ConsumeFuel

func (c *Context) ConsumeFuel(fuel uint64) (remaining uint64, err *Error)

ConsumeFuel attempts to manually consume fuel from the store.

If fuel consumption is not enabled via #wasmtime_config_consume_fuel_set then
this function will return an error. Otherwise this will attempt to consume
the specified amount of `fuel` from the store. If successful the remaining
amount of fuel is stored into `remaining`. If `fuel` couldn't be consumed
then an error is returned.

Also note that fuel, if enabled, must be originally configured via
#wasmtime_context_add_fuel.

func (*Context) Data

func (c *Context) Data() uintptr

Data returns the user-specified data associated with the specified store

func (*Context) FuelConsumed

func (c *Context) FuelConsumed() (uint64, bool)

FuelConsumed returns the amount of fuel consumed by this context's store execution

so far.

If fuel consumption is not enabled via #wasmtime_config_consume_fuel_set
then this function will return false. Otherwise, true is returned and the
fuel parameter is filled in with fuel consuemd so far.

Also note that fuel, if enabled, must be originally configured via
#wasmtime_context_add_fuel.

func (*Context) GC

func (c *Context) GC(data uintptr)

GC performs a garbage collection within the given context.

Garbage collects `externref`s that are used within this store. Any `externref`s that are discovered to be unreachable by other code or objects will have their finalizers run.

The `context` argument must not be NULL.

func (*Context) SetData

func (c *Context) SetData(data uintptr)

SetData overwrites the user-specified data associated with this store.

Note that this does not execute the original finalizer for the provided data, and the original finalizer will be executed for the provided data when the store is deleted.

func (*Context) SetEpochDeadline

func (c *Context) SetEpochDeadline(ticksBeyondCurrent uint64)

SetEpochDeadline Configures the relative deadline at which point WebAssembly code will trap.

This function configures the store-local epoch deadline after which point
WebAssembly code will trap.

See also #wasmtime_config_epoch_interruption_set.

type Engine

type Engine C.wasm_engine_t

Engine is an instance of a wasmtime engine which is used to create a `Store`.

Engines are a form of global configuration for wasm compilations and modules and such.

func NewEngine

func NewEngine() *Engine

NewEngine creates a new `Engine` with default configuration.

func NewEngineWithConfig

func NewEngineWithConfig(config *Config) *Engine

NewEngineWithConfig creates a new `Engine` with the `Config` provided

Note that once a `Config` is passed to this method it cannot be used again.

func NewEngineWithConfigBuilder

func NewEngineWithConfigBuilder(fn func(cfg *Config)) *Engine

NewEngineWithConfigBuilder creates a new `Engine` with the `Config` provided

Note that once a `Config` is passed to this method it cannot be used again.

func (*Engine) Delete

func (engine *Engine) Delete()

func (*Engine) IncrementEpoch

func (engine *Engine) IncrementEpoch()

IncrementEpoch will increase the current epoch number by 1 within the current engine which will cause any connected stores with their epoch deadline exceeded to now be interrupted.

This method is safe to call from any goroutine.

type Error

type Error C.wasmtime_error_t

func Validate

func Validate(engine *Engine, wasm []byte) *Error

Validate a WebAssembly binary.

This function will validate the provided byte sequence to determine if it is a valid WebAssembly binary within the context of the engine provided.

This function does not take ownership of its arguments but the caller is expected to deallocate the returned error if it is non-`NULL`.

If the binary validates then `NULL` is returned, otherwise the error returned describes why the binary did not validate.

func Wat2WasmBytes

func Wat2WasmBytes(wat string) ([]byte, *Error)

Wat2WasmBytes converts the text format of WebAssembly to the binary format.

Takes the text format in-memory as input, and returns either the binary encoding of the text format or an error if parsing fails.

func (*Error) Delete

func (e *Error) Delete()

func (*Error) Error

func (e *Error) Error() string

func (*Error) Message

func (e *Error) Message() (result ByteVec)

type ExportType

type ExportType C.wasm_exporttype_t

ExportType is one of the exports component

func NewExportType

func NewExportType(name ByteVec, externType *ExternType) *ExportType

func (*ExportType) Delete

func (et *ExportType) Delete()

func (*ExportType) Name

func (et *ExportType) Name() ByteVec

func (*ExportType) Type

func (et *ExportType) Type() *ExternType

type ExportTypeVec

type ExportTypeVec struct {
	// contains filtered or unexported fields
}

func NewExportTypeVec

func NewExportTypeVec(size int) ExportTypeVec

func NewExportTypeVecOf

func NewExportTypeVecOf(data []*ExportType) ExportTypeVec

func (*ExportTypeVec) Delete

func (vec *ExportTypeVec) Delete()

func (*ExportTypeVec) Get

func (vec *ExportTypeVec) Get(index int) *ExportType

func (*ExportTypeVec) Set

func (vec *ExportTypeVec) Set(index int, value *ExportType)

func (*ExportTypeVec) Unsafe

func (vec *ExportTypeVec) Unsafe() []*ExportType

type Extern

type Extern struct {
	Kind ExternKind

	Of ExternUnion
	// contains filtered or unexported fields
}

func (*Extern) Delete

func (extern *Extern) Delete()

func (*Extern) Func

func (extern *Extern) Func() *Func

func (*Extern) Global

func (extern *Extern) Global() *Global

func (*Extern) Memory

func (extern *Extern) Memory() *Memory

func (*Extern) SetFunc

func (extern *Extern) SetFunc(fn Func)

func (*Extern) SetGlobal

func (extern *Extern) SetGlobal(global Global)

func (*Extern) SetMemory

func (extern *Extern) SetMemory(memory Memory)

func (*Extern) SetTable

func (extern *Extern) SetTable(table Table)

func (*Extern) Table

func (extern *Extern) Table() *Table

func (*Extern) Type

func (extern *Extern) Type(ctx *Context) *ExternType

Type returns the type of the #wasmtime_extern_t defined within the given store.

Does not take ownership of `context` or `val`, but the returned #wasm_externtype_t is an owned value that needs to be deleted.

type ExternKind

type ExternKind uint8

type ExternType

type ExternType C.wasm_externtype_t

func (*ExternType) Copy

func (et *ExternType) Copy() *ExternType

func (*ExternType) FuncType

func (et *ExternType) FuncType() *FuncType

FuncType returns the underlying `FuncType` for this `ExternType` if it's a function type. Otherwise, returns `nil`.

func (*ExternType) GlobalType

func (et *ExternType) GlobalType() *GlobalType

GlobalType returns the underlying `GlobalType` for this `ExternType` if it's a *global* type. Otherwise, returns `nil`.

func (*ExternType) MemoryType

func (et *ExternType) MemoryType() *MemoryType

MemoryType returns the underlying `MemoryType` for this `ExternType` if it's a *memory* type. Otherwise returns `nil`.

func (*ExternType) TableType

func (et *ExternType) TableType() *TableType

TableType returns the underlying `TableType` for this `ExternType` if it's a *table* type. Otherwise, returns `nil`.

type ExternUnion

type ExternUnion C.wasmtime_extern_union_t

func (*ExternUnion) Func

func (extern *ExternUnion) Func() *Func

func (*ExternUnion) Global

func (extern *ExternUnion) Global() *Global

func (*ExternUnion) Memory

func (extern *ExternUnion) Memory() *Memory

func (*ExternUnion) SetFunc

func (eu *ExternUnion) SetFunc(fn Func)

func (*ExternUnion) SetGlobal

func (eu *ExternUnion) SetGlobal(global Global)

func (*ExternUnion) SetMemory

func (eu *ExternUnion) SetMemory(memory Memory)

func (*ExternUnion) SetTable

func (eu *ExternUnion) SetTable(table Table)

func (*ExternUnion) Table

func (extern *ExternUnion) Table() *Table

type Finalizer

type Finalizer *[0]byte

type Frame

type Frame C.wasm_frame_t

Frame is one of activation frames which carry the return arity n of the respective function, hold the values of its locals (including arguments) in the order corresponding to their static local indices, and a reference to the function’s own module instance

func (*Frame) Delete

func (f *Frame) Delete()

func (*Frame) FuncIndex

func (f *Frame) FuncIndex() (index uint32)

FuncIndex returns the function index in the wasm module that this frame represents

func (*Frame) FuncName

func (f *Frame) FuncName() BorrowedString

FuncName returns the name, if available, for this frame's function

func (*Frame) FuncOffset

func (f *Frame) FuncOffset() (offset uint64)

FuncOffset returns offset of this frame's instruction into the original function

func (*Frame) ModuleName

func (f *Frame) ModuleName() BorrowedString

ModuleName returns the name, if available, for this frame's module

func (*Frame) ModuleOffset

func (f *Frame) ModuleOffset() (offset uint64)

ModuleOffset returns offset of this frame's instruction into the original module

type FrameVec

type FrameVec struct {
	// contains filtered or unexported fields
}

func (*FrameVec) At

func (fv *FrameVec) At(index int) *Frame

func (*FrameVec) Delete

func (fv *FrameVec) Delete()

func (*FrameVec) Size

func (fv *FrameVec) Size() int

func (*FrameVec) Unsafe

func (fv *FrameVec) Unsafe() []*Frame

type Func

type Func C.wasmtime_func_t

Func is a function instance, which is the runtime representation of a function. It effectively is a closure of the original function over the runtime module instance of its originating module. The module instance is used to resolve references to other definitions during execution of the function. Read more in [spec](https://webassembly.github.io/spec/core/exec/runtime.html#function-instances)

func NewFunc

func NewFunc(context *Context, ty *FuncType, callback Callback, env uintptr, finalizer FuncFinalizer) (fn Func)

NewFunc Creates a new host-defined function.

Inserts a host-defined function into the `store` provided which can be used to then instantiate a module with or define within a #wasmtime_linker_t.

\param store the store in which to create the function \param type the wasm type of the function that's being created \param callback the host-defined callback to invoke \param env host-specific data passed to the callback invocation, can be `NULL` \param finalizer optional finalizer for `env`, can be `NULL` \param ret the #wasmtime_func_t return value to be filled in.

The returned function can only be used with the specified `store`.

func NewFuncUnchecked

func NewFuncUnchecked(context *Context, ty *FuncType, callback UncheckedCallback, env uintptr, finalizer FuncFinalizer) (fn Func)

NewFuncUnchecked creates a new host function in the same manner of #wasmtime_func_new,

but the function-to-call has no type information available at runtime.

This function is very similar to #wasmtime_func_new. The difference is that this version is "more unsafe" in that when the host callback is invoked there is no type information and no checks that the right types of values are produced. The onus is on the consumer of this API to ensure that all invariants are upheld such as:

// The host callback reads parameters correctly and interprets their types

correctly.

// If a trap doesn't happen then all results are written to the results

pointer. All results must have the correct type.

// Types such as `funcref` cannot cross stores. // Types such as `externref` have valid reference counts.

It's generally only recommended to use this if your application can wrap this in a safe embedding. This should not be frequently used due to the number of invariants that must be upheld on the wasm<->host boundary. On the upside, though, this flavor of host function will be faster to call than those created by #wasmtime_func_new (hence the reason for this function's existence)

func (*Func) AsExtern

func (f *Func) AsExtern() Extern

func (*Func) Call

func (f *Func) Call(ctx *Context, params, results []Val) (*Trap, *Error)

Call calls a WebAssembly function.

This function is used to invoke a function defined within a store. For example this might be used after extracting a function from a #wasmtime_instance_t.

\param store the store which owns `func` \param func the function to call \param args the arguments to the function call \param nargs the number of arguments provided \param results where to write the results of the function call \param nresults the number of results expected \param trap where to store a trap, if one happens.

There are three possible return states from this function:

  1. The returned error is non-null. This means `results` wasn't written to and `trap` will have `NULL` written to it. This state means that programmer error happened when calling the function, for example when the size of the arguments/results was wrong, the types of the arguments were wrong, or arguments may come from the wrong store.
  2. The trap pointer is filled in. This means the returned error is `NULL` and `results` was not written to. This state means that the function was executing but hit a wasm trap while executing.
  3. The error and trap returned are both `NULL` and `results` are written to. This means that the function call succeeded and the specified results were produced.

The `trap` pointer cannot be `NULL`. The `args` and `results` pointers may be `NULL` if the corresponding length is zero.

Does not take ownership of #wasmtime_val_t arguments. Gives ownership of #wasmtime_val_t results.

func (*Func) CallBlocking

func (f *Func) CallBlocking(ctx *Context, params, results []Val) (*Trap, *Error)

CallBlocking calls a WebAssembly function.

This function is used to invoke a function defined within a store. For example this might be used after extracting a function from a #wasmtime_instance_t.

\param store the store which owns `func` \param func the function to call \param args the arguments to the function call \param nargs the number of arguments provided \param results where to write the results of the function call \param nresults the number of results expected \param trap where to store a trap, if one happens.

There are three possible return states from this function:

  1. The returned error is non-null. This means `results` wasn't written to and `trap` will have `NULL` written to it. This state means that programmer error happened when calling the function, for example when the size of the arguments/results was wrong, the types of the arguments were wrong, or arguments may come from the wrong store.
  2. The trap pointer is filled in. This means the returned error is `NULL` and `results` was not written to. This state means that the function was executing but hit a wasm trap while executing.
  3. The error and trap returned are both `NULL` and `results` are written to. This means that the function call succeeded and the specified results were produced.

The `trap` pointer cannot be `NULL`. The `args` and `results` pointers may be `NULL` if the corresponding length is zero.

Does not take ownership of #wasmtime_val_t arguments. Gives ownership of #wasmtime_val_t results.

func (*Func) CallUnchecked

func (f *Func) CallUnchecked(ctx *Context, argsAndResults []ValRaw) *Trap

CallUnchecked calls a WebAssembly function in an "unchecked" fashion.

This function is similar to #wasmtime_func_call except that there is no type
information provided with the arguments (or sizing information). Consequently,
this is less safe to call since it's up to the caller to ensure that `args`
has an appropriate size and all the parameters are configured with their
appropriate values/types. Additionally, all the results must be interpreted
correctly if this function returns successfully.

Parameters must be specified starting at index 0 in the `args_and_results`
array. Results are written starting at index 0, which will overwrite
the arguments.

Callers must ensure that various correctness variants are upheld when this
API is called such as:

//  The `args_and_results` pointer has enough space to hold all the parameters
  and all the results (but not at the same time).
//  Parameters must all be configured as if they were the correct type.
//  Values such as `externref` and `funcref` are valid within the store being
  called.

When in doubt it's much safer to call #wasmtime_func_call. This function is
faster than that function, but the tradeoff is that embeddings must uphold
more invariants rather than relying on Wasmtime to check them for you.

func (*Func) CallUncheckedBlocking

func (f *Func) CallUncheckedBlocking(ctx *Context, argsAndResults []Val) *Trap

CallUncheckedBlocking calls a WebAssembly function in an "unchecked" fashion.

This function is similar to #wasmtime_func_call except that there is no type
information provided with the arguments (or sizing information). Consequently,
this is less safe to call since it's up to the caller to ensure that `args`
has an appropriate size and all the parameters are configured with their
appropriate values/types. Additionally, all the results must be interpreted
correctly if this function returns successfully.

Parameters must be specified starting at index 0 in the `args_and_results`
array. Results are written starting at index 0, which will overwrite
the arguments.

Callers must ensure that various correctness variants are upheld when this
API is called such as:

//  The `args_and_results` pointer has enough space to hold all the parameters
  and all the results (but not at the same time).
//  Parameters must all be configured as if they were the correct type.
//  Values such as `externref` and `funcref` are valid within the store being
  called.

When in doubt it's much safer to call #wasmtime_func_call. This function is
faster than that function, but the tradeoff is that embeddings must uphold
more invariants rather than relying on Wasmtime to check them for you.

func (*Func) Type

func (f *Func) Type(context *Context) *FuncType

Type returns the type of the function specified

The returned #wasm_functype_t is owned by the caller.

type FuncFinalizer

type FuncFinalizer C.wasmtime_func_finalizer_t

type FuncType

type FuncType C.wasm_functype_t

FuncType is one of function types which classify the signature of functions, mapping a vector of parameters to a vector of results. They are also used to classify the inputs and outputs of instructions.

func NewFuncType

func NewFuncType(params, results ValTypeVec) *FuncType

func NewFuncTypeFourOne

func NewFuncTypeFourOne(param, param2, param3, param4, result ValKind) *FuncType

func NewFuncTypeFourZero

func NewFuncTypeFourZero(param, param2, param3, param4 ValKind) *FuncType

func NewFuncTypeOneOne

func NewFuncTypeOneOne(param, result ValKind) *FuncType

func NewFuncTypeOneZero

func NewFuncTypeOneZero(param ValKind) *FuncType

func NewFuncTypeThreeOne

func NewFuncTypeThreeOne(param, param2, param3, result ValKind) *FuncType

func NewFuncTypeThreeZero

func NewFuncTypeThreeZero(param, param2, param3 ValKind) *FuncType

func NewFuncTypeTwoOne

func NewFuncTypeTwoOne(param, param2, result ValKind) *FuncType

func NewFuncTypeTwoZero

func NewFuncTypeTwoZero(param, param2 ValKind) *FuncType

func NewFuncTypeZeroOne

func NewFuncTypeZeroOne(result ValKind) *FuncType

func NewFuncTypeZeroZero

func NewFuncTypeZeroZero() *FuncType

func (*FuncType) AsExternType

func (ft *FuncType) AsExternType() *ExternType

AsExternType converts this type to an instance of `ExternType`

func (*FuncType) Delete

func (ft *FuncType) Delete()

func (*FuncType) Params

func (ft *FuncType) Params() *ValTypeVec

Params returns the parameter types of this function type

func (*FuncType) Results

func (ft *FuncType) Results() *ValTypeVec

Results returns the result types of this function type

type Global

type Global C.wasmtime_global_t

Global is a global instance, which is the runtime representation of a global variable. It holds an individual value and a flag indicating whether it is mutable. Read more in [spec](https://webassembly.github.io/spec/core/exec/runtime.html#global-instances)

func (*Global) AsExtern

func (g *Global) AsExtern() Extern

func (*Global) Get

func (g *Global) Get(ctx *Context) (val Val)

Get the value of the specified global.

\param store the store that owns `global` \param global the global to get \param out where to store the value in this global.

This function returns ownership of the contents of `out`, so #wasmtime_val_delete may need to be called on the value.

func (*Global) Set

func (g *Global) Set(ctx *Context, val Val) *Error

Set a global to a new value.

\param store the store that owns `global` \param global the global to set \param val the value to store in the global

This function may return an error if `global` is not mutable or if `val` has the wrong type for `global`.

This does not take ownership of any argument but returns ownership of the error.

func (*Global) Type

func (g *Global) Type(ctx *Context) *GlobalType

Type returns the type of this global.

type GlobalType

type GlobalType C.wasm_globaltype_t

GlobalType is a ValType, which classify global variables and hold a value and can either be mutable or immutable.

func NewGlobalType

func NewGlobalType(content *ValType, mutability Mutability) *GlobalType

NewGlobalType creates a new `GlobalType` with the `kind` provided and whether it's `mutable` or not

func (*GlobalType) AsExternType

func (gt *GlobalType) AsExternType() *ExternType

AsExternType converts this type to an instance of `ExternType`

func (*GlobalType) Content

func (gt *GlobalType) Content() *ValType

Content returns the type of value stored in this global

func (*GlobalType) Delete

func (gt *GlobalType) Delete()

func (*GlobalType) Mutability

func (gt *GlobalType) Mutability() Mutability

Mutability returns whether this global type is mutable or not

type ImportType

type ImportType C.wasm_importtype_t

ImportType is one of the imports component A module defines a set of imports that are required for instantiation.

func NewImportType

func NewImportType(module, name ByteVec, externType *ExternType) *ImportType

func (*ImportType) Delete

func (it *ImportType) Delete()

func (*ImportType) Module

func (it *ImportType) Module() ByteVec

func (*ImportType) Name

func (it *ImportType) Name() ByteVec

func (*ImportType) Type

func (it *ImportType) Type() *ExternType

type ImportTypeVec

type ImportTypeVec struct {
	// contains filtered or unexported fields
}

func NewImportTypeVec

func NewImportTypeVec(size int) ImportTypeVec

func NewImportTypeVecOf

func NewImportTypeVecOf(data []*ImportType) ImportTypeVec

func (*ImportTypeVec) Delete

func (vec *ImportTypeVec) Delete()

func (*ImportTypeVec) Get

func (vec *ImportTypeVec) Get(index int) *ImportType

func (*ImportTypeVec) Set

func (vec *ImportTypeVec) Set(index int, value *ImportType)

func (*ImportTypeVec) Unsafe

func (vec *ImportTypeVec) Unsafe() []*ImportType

type Instance

type Instance struct {
	// contains filtered or unexported fields
}

Instance is a representation of an instance in Wasmtime.

Instances are represented with a 64-bit identifying integer in Wasmtime. They do not have any destructor associated with them. Instances cannot interoperate between #wasmtime_store_t instances and if the wrong instance is passed to the wrong store then it may trigger an assertion to abort the process.

func (*Instance) ExportNamed

func (inst *Instance) ExportNamed(ctx *Context, name string) (item Extern, ok bool)

ExportNamed gets an export by name from an instance.

\param store the store that owns `instance` \param instance the instance to lookup within \param name the export name to lookup \param name_len the byte length of `name` \param item where to store the returned value

Returns nonzero if the export was found, and `item` is filled in. Otherwise returns 0.

Doesn't take ownership of any arguments but does return ownership of the #wasmtime_extern_t. /

type Linker

type Linker C.wasmtime_linker_t

Linker \typedef wasmtime_linker_t \brief Alias to #wasmtime_linker

\struct #wasmtime_linker \brief Object used to conveniently link together and instantiate wasm modules.

This type corresponds to the `wasmtime::Linker` type in Rust. This type is intended to make it easier to manage a set of modules that link together, or to make it easier to link WebAssembly modules to WASI.

A #wasmtime_linker_t is a higher level way to instantiate a module than #wasm_instance_new since it works at the "string" level of imports rather than requiring 1:1 mappings.

func NewLinker

func NewLinker(engine *Engine) *Linker

NewLinker creates a new linker for the specified engine.

This function does not take ownership of the engine argument, and the caller is expected to delete the returned linker.

func (*Linker) AllowShadowing

func (l *Linker) AllowShadowing(allow bool)

AllowShadowing configures whether this linker allows later definitions to shadow previous definitions.

By default this setting is `false`.

func (*Linker) Define

func (l *Linker) Define(module, name string, store *Context, item *Extern) *Error

Define a new item in this linker.

\param linker the linker the name is being defined in. \param module the module name the item is defined under. \param module_len the byte length of `module` \param name the field name the item is defined under \param name_len the byte length of `name` \param item the item that is being defined in this linker.

\return On success `NULL` is returned, otherwise an error is returned which describes why the definition failed.

For more information about name resolution consult the [Rust documentation](https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Linker.html#name-resolution).

func (*Linker) DefineFunc

func (l *Linker) DefineFunc(
	module, name string,
	funcType *FuncType,
	callback Callback,
	env uintptr,
	finalizer FuncFinalizer) *Error

DefineFunc defines a new function in this linker.

\param linker the linker the name is being defined in. \param module the module name the item is defined under. \param module_len the byte length of `module` \param name the field name the item is defined under \param name_len the byte length of `name` \param ty the type of the function that's being defined \param cb the host callback to invoke when the function is called \param data the host-provided data to provide as the first argument to the callback \param finalizer an optional finalizer for the `data` argument.

\return On success `NULL` is returned, otherwise an error is returned which describes why the definition failed.

For more information about name resolution consult the [Rust documentation](https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Linker.html#name-resolution).

Note that this function does not create a #wasmtime_func_t. This creates a store-independent function within the linker, allowing this function definition to be used with multiple stores.

For more information about host callbacks see #wasmtime_func_new.

func (*Linker) DefineFuncUnchecked

func (l *Linker) DefineFuncUnchecked(
	module, name string,
	funcType *FuncType,
	callback UncheckedCallback,
	env uintptr,
	finalizer FuncFinalizer) *Error

DefineFuncUnchecked Defines a new function in this linker.

This is the same as #wasmtime_linker_define_func except that it's the analog of #wasmtime_func_new_unchecked instead of #wasmtime_func_new. Be sure to consult the documentation of #wasmtime_linker_define_func for argument information as well as #wasmtime_func_new_unchecked for why this is an unsafe API.

func (*Linker) DefineInstance

func (l *Linker) DefineInstance(ctx *Context, name string, instance *Instance) *Error

DefineInstance defines an instance under the specified name in this linker.

\param linker the linker the name is being defined in. \param store the store that owns `instance` \param name the module name to define `instance` under. \param name_len the byte length of `name` \param instance a previously-created instance.

\return On success `NULL` is returned, otherwise an error is returned which describes why the definition failed.

This function will take all of the exports of the `instance` provided and defined them under a module called `name` with a field name as the export's own name.

For more information about name resolution consult the [Rust documentation](https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Linker.html#name-resolution).

func (*Linker) DefineWasi

func (l *Linker) DefineWasi() *Error

DefineWasi defines WASI functions in this linker.

\param linker the linker the name is being defined in.

\return On success `NULL` is returned, otherwise an error is returned which describes why the definition failed.

This function will provide WASI function names in the specified linker. Note that when an instance is created within a store then the store also needs to have its WASI settings configured with #wasmtime_context_set_wasi for WASI functions to work, otherwise an assert will be tripped that will abort the process.

For more information about name resolution consult the [Rust documentation](https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Linker.html#name-resolution).

func (*Linker) Delete

func (l *Linker) Delete()

func (*Linker) Get

func (l *Linker) Get(ctx *Context, module, name string) (Extern, bool)

Get loads an item by name from this linker.

\param linker the linker to load from \param store the store to load the item into \param module the name of the module to get \param module_len the byte length of `module` \param name the name of the field to get \param name_len the byte length of `name` \param item where to store the extracted item

\return A nonzero value if the item is defined, in which case `item` is also filled in. Otherwise, zero is returned.

func (*Linker) GetDefault

func (l *Linker) GetDefault(ctx *Context, name string) (Func, *Error)

GetDefault acquires the "default export" of the named module in this linker.

\param linker the linker to load from \param store the store to load a function into \param name the name of the module to get the default export for \param name_len the byte length of `name` \param func where to store the extracted default function.

\return An error is returned if the default export could not be found, or `NULL` is returned and `func` is filled in otherwise.

For more information see the [Rust documentation](https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Linker.html#method.get_default).

func (*Linker) Instantiate

func (l *Linker) Instantiate(ctx *Context, module *Module) (Instance, *Trap, *Error)

Instantiate instantiates a #wasm_module_t with the items defined in this linker.

\param linker the linker used to instantiate the provided module. \param store the store that is used to instantiate within \param module the module that is being instantiated. \param instance the returned instance, if successful. \param trap a trap returned, if the start function traps.

\return One of three things can happen as a result of this function. First the module could be successfully instantiated and returned through `instance`, meaning the return value and `trap` are both set to `NULL`. Second the start function may trap, meaning the return value and `instance` are set to `NULL` and `trap` describes the trap that happens. Finally instantiation may fail for another reason, in which case an error is returned and `trap` and `instance` are set to `NULL`.

This function will attempt to satisfy all of the imports of the `module` provided with items previously defined in this linker. If any name isn't defined in the linker than an error is returned. (or if the previously defined item is of the wrong type).

func (*Linker) Module

func (l *Linker) Module(ctx *Context, name string, module *Module) *Error

Module defines automatic instantiations of a #wasm_module_t in this linker.

\param linker the linker the module is being added to \param store the store that is used to instantiate `module` \param name the name of the module within the linker \param name_len the byte length of `name` \param module the module that's being instantiated

\return An error if the module could not be instantiated or added or `NULL` on success.

This function automatically handles [Commands and Reactors](https://github.com/WebAssembly/WASI/blob/master/design/application-abi.md#current-unstable-abi) instantiation and initialization.

For more information see the [Rust documentation](https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Linker.html#method.module).

type Memory

type Memory C.wasmtime_memory_t

func (*Memory) AsExtern

func (m *Memory) AsExtern() Extern

func (*Memory) Data

func (m *Memory) Data(context *Context) []byte

Data returns a byte slice starting where the linear memory starts

func (*Memory) Grow

func (m *Memory) Grow(context *Context, delta uint64) (prevSize uint64, err *Error)

Grow attempts to grow the specified memory by `delta` pages.

\param store the store that owns `memory`
\param memory the memory to grow
\param delta the number of pages to grow by
\param prev_size where to store the previous size of memory

If memory cannot be grown then `prev_size` is left unchanged and an error is
returned. Otherwise, `prev_size` is set to the previous size of the memory, in
WebAssembly pages, and `NULL` is returned.

func (*Memory) Size

func (m *Memory) Size(context *Context) (pages uint64)

Size returns the length, in WebAssembly pages, of this linear memory.

func (*Memory) Type

func (m *Memory) Type(context *Context) *MemoryType

Type returns the MemoryType of the Memory

type MemoryType

type MemoryType C.wasm_memorytype_t

func NewMemoryType

func NewMemoryType(min uint64, maxPresent bool, max uint64, is64 bool) *MemoryType

func (*MemoryType) AsExternType

func (mt *MemoryType) AsExternType() *ExternType

AsExternType converts this type to an instance of `ExternType`

func (*MemoryType) Delete

func (mt *MemoryType) Delete()

func (*MemoryType) Is64

func (mt *MemoryType) Is64() bool

Is64 returns whether this type of memory represents a 64-bit memory.

func (*MemoryType) Maximum

func (mt *MemoryType) Maximum() uint64

Maximum returns the maximum size, in pages, of the specified memory type.

If this memory type doesn't have a maximum size listed then `0` is returned. Otherwise, returns the maximum size in pages.

Note that this function is preferred over #wasm_memorytype_limits for compatibility with the memory64 proposal.

func (*MemoryType) Minimum

func (mt *MemoryType) Minimum() uint64

Minimum returns the minimum size, in pages, of the specified memory type.

Note that this function is preferred over #wasm_memorytype_limits for compatibility with the memory64 proposal.

type Module

type Module C.wasmtime_module_t

Module is a module which collects definitions for types, functions, tables, memories, and globals. In addition, it can declare imports and exports and provide initialization logic in the form of data and element segments or a start function. Modules organized WebAssembly programs as the unit of deployment, loading, and compilation.

func (*Module) Clone

func (m *Module) Clone() *Module

Clone creates a shallow clone of the specified module, increasing the internal reference count.

func (*Module) Delete

func (m *Module) Delete()

func (*Module) Exports

func (m *Module) Exports() ExportTypeVec

Exports same as #wasm_module_exports, but for #wasmtime_module_t.

func (*Module) Imports

func (m *Module) Imports() ImportTypeVec

Imports same as #wasm_module_imports, but for #wasmtime_module_t.

func (*Module) Serialize

func (m *Module) Serialize() (ByteVec, *Error)

Serialize serializes compiled module artifacts as blob data.

\param module the module \param ret if the conversion is successful, this byte vector is filled in with

the serialized compiled module.

\return a non-null error if parsing fails, or returns `NULL`. If parsing fails then `ret` isn't touched.

This function does not take ownership of `module`, and the caller is expected to deallocate the returned #wasmtime_error_t and #wasm_byte_vec_t.

type Mutability

type Mutability uint8

type OptLevel

type OptLevel C.wasmtime_opt_level_t

OptLevel decides what degree of optimization wasmtime will perform on generated machine code

const (
	// OptLevelNone will perform no optimizations
	OptLevelNone OptLevel = C.WASMTIME_OPT_LEVEL_NONE
	// OptLevelSpeed will optimize machine code to be as fast as possible
	OptLevelSpeed OptLevel = C.WASMTIME_OPT_LEVEL_SPEED
	// OptLevelSpeedAndSize will optimize machine code for speed, but also optimize
	// to be small, sometimes at the cost of speed.
	OptLevelSpeedAndSize OptLevel = C.WASMTIME_OPT_LEVEL_SPEED_AND_SIZE
)

type ProfilingStrategy

type ProfilingStrategy C.wasmtime_profiling_strategy_t

ProfilingStrategy decides what sort of profiling to enable, if any.

const (
	// ProfilingStrategyNone means no profiler will be used
	ProfilingStrategyNone ProfilingStrategy = C.WASMTIME_PROFILING_STRATEGY_NONE
	// ProfilingStrategyJitdump will use the "jitdump" linux support
	ProfilingStrategyJitdump ProfilingStrategy = C.WASMTIME_PROFILING_STRATEGY_JITDUMP
)

type Store

type Store C.wasmtime_store_t

Store

\typedef wasmtime_store_t
\brief Convenience alias for #wasmtime_store_t

\struct wasmtime_store
\brief Storage of WebAssembly objects

A store is the unit of isolation between WebAssembly instances in an
embedding of Wasmtime. Values in one #wasmtime_store_t cannot flow into
another #wasmtime_store_t. Stores are cheap to create and cheap to dispose.
It's expected that one-off stores are common in embeddings.

Objects stored within a #wasmtime_store_t are referenced with integer handles
rather than interior pointers. This means that most APIs require that the
store be explicitly passed in, which is done via #wasmtime_context_t. It is
safe to move a #wasmtime_store_t to any thread at any time. A store generally
cannot be concurrently used, however.

func NewStore

func NewStore(engine *Engine, data uintptr, finalizer Finalizer) *Store

NewStore

\brief Creates a new store within the specified engine.

\param engine the compilation environment with configuration this store is
connected to
\param data user-provided data to store, can later be acquired with
#wasmtime_context_get_data.
\param finalizer an optional finalizer for `data`

This function creates a fresh store with the provided configuration settings.
The returned store must be deleted with #wasmtime_store_delete.

func (*Store) Context

func (s *Store) Context() *Context

Context returns the interior #wasmtime_context_t pointer to this store

func (*Store) Delete

func (s *Store) Delete()

type Strategy

type Strategy C.wasmtime_strategy_t

Strategy is the compilation strategies for wasmtime

const (
	// StrategyAuto will let wasmtime automatically pick an appropriate compilation strategy
	StrategyAuto Strategy = C.WASMTIME_STRATEGY_AUTO
	// StrategyCranelift will force wasmtime to use the Cranelift backend
	StrategyCranelift Strategy = C.WASMTIME_STRATEGY_CRANELIFT
)

type Table

type Table C.wasmtime_table_t

func (*Table) AsExtern

func (t *Table) AsExtern() Extern

func (*Table) Get

func (t *Table) Get(context *Context, index uint32) (ok bool, val Val)

Get a value in a table.

\param store the store that owns `table` \param table the table to access \param index the table index to access \param val where to store the table's value

This function will attempt to access a table element. If a nonzero value is returned then `val` is filled in and is owned by the caller. Otherwise, zero is returned because the `index` is out-of-bounds.

func (*Table) Grow

func (t *Table) Grow(context *Context, delta uint32, init Val) (prevSize uint32, err *Error)

Grow a table.

\param store the store that owns `table` \param table the table to grow \param delta the number of elements to grow the table by \param init the initial value for new table element slots \param prev_size where to store the previous size of the table before growth

This function will attempt to grow the table by `delta` table elements. This can fail if `delta` would exceed the maximum size of the table or if `init` is the wrong type for this table. If growth is successful then `NULL` is returned and `prev_size` is filled in with the previous size of the table, in elements, before the growth happened.

This function does not take ownership of its arguments.

func (*Table) Set

func (t *Table) Set(context *Context, index uint32, val Val) *Error

Set a value in a table.

\param store the store that owns `table` \param table the table to write to \param index the table index to write \param value the value to store.

This function will store `value` into the specified index in the table. This does not take ownership of any argument but yields ownership of the error. This function can fail if `value` has the wrong type for the table, or if `index` is out of bounds.

func (*Table) Size

func (t *Table) Size(context *Context) uint32

Size returns the size, in elements, of this table.

func (*Table) Type

func (t *Table) Type(context *Context) *TableType

Type returns the TableType of the Table

type TableType

type TableType C.wasm_tabletype_t

TableType is one of table types which classify tables over elements of element types within a size range.

func NewTableType

func NewTableType(element *ValType, min uint32, hasMax bool, max uint32) *TableType

NewTableType creates a new `TableType` with the `element` type provided as well as limits on its size.

The `min` value is the minimum size, in elements, of this table. The `has_max` boolean indicates whether a maximum size is present, and if so `max` is used as the maximum size of the table, in elements.

func (*TableType) AsExternType

func (tt *TableType) AsExternType() *ExternType

AsExternType converts this type to an instance of `ExternType`

func (*TableType) Delete

func (tt *TableType) Delete()

func (*TableType) Element

func (tt *TableType) Element() *ValType

Element returns the type of value stored in this table.

func (*TableType) Limits

func (tt *TableType) Limits() (min uint32, hasMax bool, max uint32)

func (*TableType) Maximum

func (tt *TableType) Maximum() (hasMax bool, max uint32)

Maximum returns the maximum size, in elements, of this table.

If no maximum size is listed then `(false, 0)` is returned, otherwise `(true, N)` is returned where `N` is the maximum size.

func (*TableType) Minimum

func (tt *TableType) Minimum() uint32

Minimum returns the minimum size, in elements, of this table.

type Trap

type Trap C.wasm_trap_t

Trap is the trap instruction which represents the occurrence of a trap. Traps are bubbled up through nested instruction sequences, ultimately reducing the entire program to a single trap instruction, signalling abrupt termination.

func NewTrap

func NewTrap(message string) *Trap

NewTrap creates a new `Trap` with the `name` and the type provided.

func (*Trap) Code

func (t *Trap) Code() (code TrapCode, ok bool)

Code attempts to extract the trap code from this trap.

Returns `true` if the trap is an instruction trap triggered while executing Wasm. If `true` is returned then the trap code is returned through the `code` pointer. If `false` is returned then this is not an instruction trap -- traps can also be created using wasm_trap_new, or occur with WASI modules exiting with a certain exit code.

func (*Trap) Delete

func (t *Trap) Delete()

func (*Trap) Error

func (t *Trap) Error() string

func (*Trap) Frames

func (t *Trap) Frames() (frames FrameVec)

Frames returns the wasm function frames that make up this trap

func (*Trap) IsError

func (t *Trap) IsError() bool

func (*Trap) Message

func (t *Trap) Message() (message ByteVec)

func (*Trap) Origin

func (t *Trap) Origin() (origin *Frame)

type TrapCode

type TrapCode uint8

TrapCode is the code of an instruction trap.

type UncheckedCallback

type UncheckedCallback C.wasmtime_func_unchecked_callback_t

UncheckedCallback callback signature for #wasmtime_func_new_unchecked.

This is the function signature for host functions that can be made accessible to WebAssembly. The arguments to this function are:

\param env user-provided argument passed to #wasmtime_func_new_unchecked

\param caller a temporary object that can only be used during this function

call. Used to acquire #wasmtime_context_t or caller's state

\param args_and_results storage space for both the parameters to the

function and the results of the function. The size of this
array depends on the function type that the host function is created
with, but it will be the maximum of the number of parameters and
number of results.

\param num_args_and_results the size of the `args_and_results` parameter in

units of #wasmtime_val_raw_t.

This callback can optionally return a #wasm_trap_t indicating that a trap should be raised in WebAssembly. It's expected that in this case the caller relinquishes ownership of the trap, and it is passed back to the engine.

This differs from #wasmtime_func_callback_t in that the payload of `args_and_results` does not have type information, nor does it have sizing information. This is especially unsafe because it's only valid within the particular #wasm_functype_t that the function was created with. The onus is on the embedder to ensure that `args_and_results` are all read correctly for parameters and all written for results within the execution of a function.

Parameters will be listed starting at index 0 in the `args_and_results` array. Results are also written starting at index 0, which will overwrite the arguments.

type Val

type Val struct {
	Kind ValKind

	Val [16]byte
	// contains filtered or unexported fields
}

Val is a primitive numeric value. Moreover, in the definition of programs, immutable sequences of values occur to represent more complex data, such as text strings or other vectors.

func ValF32

func ValF32(val float32) Val

ValF32 converts a go float32 to a f32 Val

func ValF64

func ValF64(val float64) Val

ValF64 converts a go float64 to a f64 Val

func ValI32

func ValI32(val int32) Val

ValI32 converts a go int32 to a i32 Val

func ValI64

func ValI64(val int64) Val

ValI64 converts a go int64 to a i64 Val

func (*Val) F32

func (v *Val) F32() float32

F32 returns the underlying 32-bit float if this is an `f32`, or panics.

func (*Val) F64

func (v *Val) F64() float64

F64 returns the underlying 64-bit float if this is an `f64`, or panics.

func (*Val) Get

func (v *Val) Get() interface{}

Get returns the underlying 64-bit float if this is an `f64`, or panics.

func (*Val) I32

func (v *Val) I32() int32

I32 returns the underlying 32-bit integer if this is an `i32`, or panics.

func (*Val) I64

func (v *Val) I64() int64

I64 returns the underlying 64-bit integer if this is an `i64`, or panics.

func (*Val) SetF32

func (v *Val) SetF32(value float32)

func (*Val) SetF64

func (v *Val) SetF64(value float64)

func (*Val) SetI32

func (v *Val) SetI32(value int32)

func (*Val) SetI64

func (v *Val) SetI64(value int64)

type ValKind

type ValKind C.wasm_valkind_t

ValKind enumeration of different kinds of value types

const (
	// KindI32 is the types i32 classify 32-bit integers. Integers are not inherently signed or unsigned, their interpretation is determined by individual operations.
	KindI32 ValKind = C.WASM_I32
	// KindI64 is the types i64 classify 64-bit integers. Integers are not inherently signed or unsigned, their interpretation is determined by individual operations.
	KindI64 ValKind = C.WASM_I64
	// KindF32 is the types f32 classify 32-bit floating-point data. They correspond to the respective binary floating-point representations, also known as single and double precision, as defined by the IEEE 754-2019 standard.
	KindF32 ValKind = C.WASM_F32
	// KindF64 is the types f64 classify 64-bit floating-point data. They correspond to the respective binary floating-point representations, also known as single and double precision, as defined by the IEEE 754-2019 standard.
	KindF64  ValKind = C.WASM_F64
	KindV128 ValKind = 4
	// TODO: Unknown
	KindExternref ValKind = C.WASM_ANYREF
	// KindFuncref is the infinite union of all function types.
	KindFuncref ValKind = C.WASM_FUNCREF
)

func (ValKind) String

func (ty ValKind) String() string

String renders this kind as a string, similar to the `*.wat` format

type ValRaw

type ValRaw [16]byte

func (*ValRaw) F32

func (v *ValRaw) F32() float32

func (*ValRaw) F64

func (v *ValRaw) F64() float64

func (*ValRaw) I32

func (v *ValRaw) I32() int32

func (*ValRaw) I64

func (v *ValRaw) I64() int64

func (*ValRaw) SetF32

func (v *ValRaw) SetF32(value float32)

func (*ValRaw) SetF64

func (v *ValRaw) SetF64(value float64)

func (*ValRaw) SetI32

func (v *ValRaw) SetI32(value int32)

func (*ValRaw) SetI64

func (v *ValRaw) SetI64(value int64)

type ValType

type ValType C.wasm_valtype_t

ValType means one of the value types, which classify the individual values that WebAssembly code can compute with and the values that a variable accepts.

func NewValType

func NewValType(kind ValKind) *ValType

NewValType creates a new `ValType` with the `kind` provided

func (*ValType) Clone

func (t *ValType) Clone() *ValType

func (*ValType) Delete

func (t *ValType) Delete()

func (*ValType) Kind

func (t *ValType) Kind() ValKind

Kind returns the corresponding `ValKind` for this `ValType`

func (*ValType) String

func (t *ValType) String() string

Converts this `ValType` into a string according to the string representation of `ValKind`.

type ValTypeVec

type ValTypeVec struct {
	// contains filtered or unexported fields
}

func NewValTypeVec

func NewValTypeVec(size int) ValTypeVec

func NewValTypeVecOf

func NewValTypeVecOf(data []*ValType) ValTypeVec

func (*ValTypeVec) Delete

func (vec *ValTypeVec) Delete()

func (*ValTypeVec) Get

func (vec *ValTypeVec) Get(index int) *ValType

func (*ValTypeVec) Set

func (vec *ValTypeVec) Set(index int, value *ValType)

func (*ValTypeVec) Unsafe

func (vec *ValTypeVec) Unsafe() []*ValType

Jump to

Keyboard shortcuts

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