Wasmtime
|
Go to the source code of this file.
Typedefs | |
typedef struct wasmtime_store | wasmtime_store_t |
Convenience alias for wasmtime_store_t. | |
typedef struct wasmtime_context | wasmtime_context_t |
Convenience alias for wasmtime_context. | |
typedef uint8_t | wasmtime_update_deadline_kind_t |
An enum for the behavior before extending the epoch deadline. | |
Functions | |
wasmtime_store_t * | wasmtime_store_new (wasm_engine_t *engine, void *data, void(*finalizer)(void *)) |
Creates a new store within the specified engine. More... | |
wasmtime_context_t * | wasmtime_store_context (wasmtime_store_t *store) |
Returns the interior wasmtime_context_t pointer to this store. | |
void | wasmtime_store_limiter (wasmtime_store_t *store, int64_t memory_size, int64_t table_elements, int64_t instances, int64_t tables, int64_t memories) |
Provides limits for a store. Used by hosts to limit resource consumption of instances. Use negative value to keep the default value for the limit. More... | |
void | wasmtime_store_delete (wasmtime_store_t *store) |
Deletes a store. | |
void * | wasmtime_context_get_data (const wasmtime_context_t *context) |
Returns the user-specified data associated with the specified store. | |
void | wasmtime_context_set_data (wasmtime_context_t *context, void *data) |
Overwrites the user-specified data associated with this store. More... | |
void | wasmtime_context_gc (wasmtime_context_t *context) |
Perform garbage collection within the given context. More... | |
wasmtime_error_t * | wasmtime_context_set_fuel (wasmtime_context_t *store, uint64_t fuel) |
Set fuel to this context's store for wasm to consume while executing. More... | |
wasmtime_error_t * | wasmtime_context_get_fuel (const wasmtime_context_t *context, uint64_t *fuel) |
Returns the amount of fuel remaining in this context's store. More... | |
wasmtime_error_t * | wasmtime_context_set_wasi (wasmtime_context_t *context, wasi_config_t *wasi) |
Configures WASI state within the specified store. More... | |
void | wasmtime_context_set_epoch_deadline (wasmtime_context_t *context, uint64_t ticks_beyond_current) |
Configures the relative deadline at which point WebAssembly code will trap or invoke the callback function. More... | |
void | wasmtime_store_epoch_deadline_callback (wasmtime_store_t *store, wasmtime_error_t *(*func)(wasmtime_context_t *context, void *data, uint64_t *epoch_deadline_delta, wasmtime_update_deadline_kind_t *update_kind), void *data, void(*finalizer)(void *)) |
Configures epoch deadline callback to C function. More... | |
Wasmtime definition of a "store".
void wasmtime_context_gc | ( | wasmtime_context_t * | context | ) |
Perform 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.
wasmtime_error_t * wasmtime_context_get_fuel | ( | const wasmtime_context_t * | context, |
uint64_t * | fuel | ||
) |
Returns the amount of fuel remaining in this context's store.
If fuel consumption is not enabled via wasmtime_config_consume_fuel_set then this function will return an error. Otherwise NULL
is returned and the fuel parameter is filled in with fuel consumed so far.
Also note that fuel, if enabled, must be originally configured via wasmtime_context_set_fuel.
void wasmtime_context_set_data | ( | wasmtime_context_t * | context, |
void * | data | ||
) |
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.
void wasmtime_context_set_epoch_deadline | ( | wasmtime_context_t * | context, |
uint64_t | ticks_beyond_current | ||
) |
Configures the relative deadline at which point WebAssembly code will trap or invoke the callback function.
This function configures the store-local epoch deadline after which point WebAssembly code will trap or invoke the callback function.
See also wasmtime_config_epoch_interruption_set and wasmtime_store_epoch_deadline_callback.
wasmtime_error_t * wasmtime_context_set_fuel | ( | wasmtime_context_t * | store, |
uint64_t | fuel | ||
) |
Set 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 when fuel is entirely consumed it will cause wasm to trap.
If fuel is not enabled within this store then an error is returned. If fuel is successfully added then NULL is returned.
wasmtime_error_t * wasmtime_context_set_wasi | ( | wasmtime_context_t * | context, |
wasi_config_t * | wasi | ||
) |
Configures WASI state within the specified store.
This function is required if wasmtime_linker_define_wasi is called. This will configure the WASI state for instances defined within this store to the configuration specified.
This function does not take ownership of context
but it does take ownership of wasi
. The caller should no longer use wasi
after calling this function (even if an error is returned).
void wasmtime_store_epoch_deadline_callback | ( | wasmtime_store_t * | store, |
wasmtime_error_t *(*)(wasmtime_context_t *context, void *data, uint64_t *epoch_deadline_delta, wasmtime_update_deadline_kind_t *update_kind) | func, | ||
void * | data, | ||
void(*)(void *) | finalizer | ||
) |
Configures epoch deadline callback to C function.
This function configures a store-local callback function that will be called when the running WebAssembly function has exceeded its epoch deadline. That function can:
To use WASMTIME_UPDATE_DEADLINE_YIELD async support must be enabled for this store.
See also wasmtime_config_epoch_interruption_set and wasmtime_context_set_epoch_deadline.
void wasmtime_store_limiter | ( | wasmtime_store_t * | store, |
int64_t | memory_size, | ||
int64_t | table_elements, | ||
int64_t | instances, | ||
int64_t | tables, | ||
int64_t | memories | ||
) |
Provides limits for a store. Used by hosts to limit resource consumption of instances. Use negative value to keep the default value for the limit.
store | store where the limits should be set. |
memory_size | the maximum number of bytes a linear memory can grow to. Growing a linear memory beyond this limit will fail. By default, linear memory will not be limited. |
table_elements | the maximum number of elements in a table. Growing a table beyond this limit will fail. By default, table elements will not be limited. |
instances | the maximum number of instances that can be created for a Store. Module instantiation will fail if this limit is exceeded. This value defaults to 10,000. |
tables | the maximum number of tables that can be created for a Store. Module instantiation will fail if this limit is exceeded. This value defaults to 10,000. |
memories | the maximum number of linear memories that can be created for a Store. Instantiation will fail with an error if this limit is exceeded. This value defaults to 10,000. |
Use any negative value for the parameters that should be kept on the default values.
Note that the limits are only used to limit the creation/growth of resources in the future, this does not retroactively attempt to apply limits to the store.
wasmtime_store_t * wasmtime_store_new | ( | wasm_engine_t * | engine, |
void * | data, | ||
void(*)(void *) | finalizer | ||
) |
Creates a new store within the specified engine.
engine | the compilation environment with configuration this store is connected to |
data | user-provided data to store, can later be acquired with wasmtime_context_get_data. |
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.