5#ifndef WASMTIME_CONFIG_HH
6#define WASMTIME_CONFIG_HH
11#include <wasmtime/helpers.hh>
46#ifdef WASMTIME_FEATURE_POOLING_ALLOCATOR
55 wasmtime_pooling_allocation_config);
63 void max_unused_warm_slots(uint32_t max) {
71 void decommit_batch_size(
size_t batch_size) {
76#ifdef WASMTIME_FEATURE_ASYNC
81 void async_stack_keep_resident(
size_t size) {
91 void linear_memory_keep_resident(
size_t size) {
100 void table_keep_resident(
size_t size) {
108 void total_component_instances(uint32_t count) {
117 void max_component_instance_size(
size_t size) {
126 void max_core_instances_per_component(uint32_t count) {
135 void max_memories_per_component(uint32_t count) {
144 void max_tables_per_component(uint32_t count) {
153 void total_memories(uint32_t count) {
161 void total_tables(uint32_t count) {
165#ifdef WASMTIME_FEATURE_ASYNC
170 void total_stacks(uint32_t count) {
179 void total_core_instances(uint32_t count) {
188 void max_core_instance_size(
size_t size) {
197 void max_tables_per_module(uint32_t tables) {
206 void table_elements(
size_t elements) {
214 void max_memories_per_module(uint32_t memories) {
223 void max_memory_size(
size_t bytes) {
231 void total_gc_heaps(uint32_t count) {
247 WASMTIME_OWN_WRAPPER(
Config, wasm_config);
256 void debug_info(
bool enable) {
264 void epoch_interruption(
bool enable) {
272 void consume_fuel(
bool enable) {
279 void max_wasm_stack(
size_t stack) {
283#ifdef WASMTIME_FEATURE_THREADS
287 void wasm_threads(
bool enable) {
295 void wasm_tail_call(
bool enable) {
303 void wasm_reference_types(
bool enable) {
310 void wasm_simd(
bool enable) {
317 void wasm_relaxed_simd(
bool enable) {
325 void wasm_relaxed_simd_deterministic(
bool enable) {
332 void wasm_bulk_memory(
bool enable) {
339 void wasm_multi_value(
bool enable) {
346 void wasm_multi_memory(
bool enable) {
353 void wasm_memory64(
bool enable) {
367 void wasm_function_references(
bool enable) {
375 void wasm_wide_arithmetic(
bool enable) {
383 void wasm_exceptions(
bool enable) {
391 void wasm_custom_page_sizes(
bool enable) {
395#ifdef WASMTIME_FEATURE_COMPONENT_MODEL
400 void wasm_component_model(
bool enable) {
405#ifdef WASMTIME_FEATURE_PARALLEL_COMPILATION
410 void parallel_compilation(
bool enable) {
415#ifdef WASMTIME_FEATURE_COMPILER
427 void cranelift_debug_verifier(
bool enable) {
434 void cranelift_nan_canonicalization(
bool enable) {
441 void cranelift_opt_level(
OptLevel level) {
449 void cranelift_flag_enable(
const std::string &flag) {
456 void cranelift_flag_set(
const std::string &flag,
const std::string &value) {
472 void memory_reservation(
size_t size) {
480 void memory_reservation_for_growth(
size_t size) {
487 void memory_guard_size(
size_t size) {
495 void memory_may_move(
bool enable) {
502 void memory_init_cow(
bool enable) {
509 void native_unwind_info(
bool enable) {
516 void macos_use_mach_ports(
bool enable) {
522 void signals_based_traps(
bool enable) {
526#ifdef WASMTIME_FEATURE_CACHE
532 if (error !=
nullptr) {
535 return std::monostate();
543 if (error !=
nullptr) {
546 return std::monostate();
551 template <
typename T>
static void raw_finalize(
void *env) {
552 std::unique_ptr<T> ptr(
reinterpret_cast<T *
>(env));
555 template <
typename M>
556 static uint8_t *raw_get_memory(
void *env,
size_t *byte_size,
557 size_t *byte_capacity) {
558 M *memory =
reinterpret_cast<M *
>(env);
559 return memory->get_memory(byte_size, byte_capacity);
562 template <
typename M>
564 M *memory =
reinterpret_cast<M *
>(env);
567 return result.
err().capi_release();
571 template <
typename T>
574 size_t maximum,
size_t reserved_size_in_bytes,
575 size_t guard_size_in_bytes,
577 using Memory =
typename T::Memory;
578 T *creator =
reinterpret_cast<T *
>(env);
581 reserved_size_in_bytes, guard_size_in_bytes);
583 return result.
err().capi_release();
586 memory_ret->
env = std::make_unique<Memory>(memory).release();
587 memory_ret->
finalizer = raw_finalize<Memory>;
588 memory_ret->
get_memory = raw_get_memory<Memory>;
601 config.
env = std::make_unique<T>(creator).release();
607#ifdef WASMTIME_FEATURE_POOLING_ALLOCATOR
Configuration for Wasmtime.
Definition: config.hh:246
void host_memory_creator(T creator)
Configures a custom memory creator for this configuration and eventual Engine.
Definition: config.hh:599
void pooling_allocation_strategy(const PoolAllocationConfig &config)
Enables and configures the pooling allocation strategy.
Definition: config.hh:611
Errors coming from Wasmtime.
Definition: error.hh:26
Non-owning reference to a MemoryType, must not be used after the original owner has been deleted.
Definition: types/memory.hh:34
A WebAssembly linear memory.
Definition: memory.hh:27
Pool allocation configuration for Wasmtime.
Definition: config.hh:53
Fallible result type used for Wasmtime.
Definition: error.hh:70
E && err()
Returns the error, if present, aborts if this is not an error.
Definition: error.hh:84
T unwrap()
Returns the success, if present, aborts if this is an error.
Definition: error.hh:104
Build-time defines for how the C API was built.
Wasmtime-specific extensions to wasm_config_t.
WASM_API_EXTERN void wasmtime_pooling_allocation_config_total_gc_heaps_set(wasmtime_pooling_allocation_config_t *, uint32_t)
The maximum number of concurrent GC heaps supported (default is 1000).
WASM_API_EXTERN void wasmtime_pooling_allocation_config_total_component_instances_set(wasmtime_pooling_allocation_config_t *, uint32_t)
The maximum number of concurrent component instances supported (default is 1000).
WASM_API_EXTERN void wasmtime_pooling_allocation_config_table_keep_resident_set(wasmtime_pooling_allocation_config_t *, size_t)
How much memory, in bytes, to keep resident for each table after deallocation.
WASM_API_EXTERN void wasmtime_config_wasm_tail_call_set(wasm_config_t *, bool)
Configures whether the WebAssembly tail call proposal is enabled.
WASM_API_EXTERN void wasmtime_config_max_wasm_stack_set(wasm_config_t *, size_t)
Configures the maximum stack size, in bytes, that JIT code can use.
WASM_API_EXTERN void wasmtime_config_wasm_multi_memory_set(wasm_config_t *, bool)
Configures whether the WebAssembly multi-memory proposal is enabled.
WASM_API_EXTERN wasmtime_error_t * wasmtime_config_cache_config_load(wasm_config_t *, const char *)
Enables Wasmtime's cache and loads configuration from the specified path.
WASM_API_EXTERN void wasmtime_pooling_allocation_config_max_core_instances_per_component_set(wasmtime_pooling_allocation_config_t *, uint32_t)
The maximum number of core instances a single component may contain (default is unlimited).
WASM_API_EXTERN void wasmtime_pooling_allocation_strategy_set(wasm_config_t *, const wasmtime_pooling_allocation_config_t *)
Sets the Wasmtime allocation strategy to use the pooling allocator. It does not take ownership of the...
WASM_API_EXTERN void wasmtime_config_wasm_component_model_set(wasm_config_t *, bool)
Configures whether the WebAssembly component-model proposal will be enabled for compilation.
WASM_API_EXTERN void wasmtime_config_wasm_custom_page_sizes_set(wasm_config_t *, bool)
Configures whether the WebAssembly custom-page-sizes proposal is enabled.
uint8_t wasmtime_strategy_t
Specifier for how Wasmtime will compile code, values are in wasmtime_strategy_enum.
Definition: config.h:22
WASM_API_EXTERN void wasmtime_pooling_allocation_config_linear_memory_keep_resident_set(wasmtime_pooling_allocation_config_t *, size_t)
How much memory, in bytes, to keep resident for each linear memory after deallocation.
WASM_API_EXTERN void wasmtime_config_memory_reservation_set(wasm_config_t *, uint64_t)
Configures the size, in bytes, of initial memory reservation size for linear memories.
WASM_API_EXTERN void wasmtime_config_wasm_wide_arithmetic_set(wasm_config_t *, bool)
Configures whether the WebAssembly wide-arithmetic proposal is enabled.
WASM_API_EXTERN void wasmtime_pooling_allocation_config_max_tables_per_module_set(wasmtime_pooling_allocation_config_t *, uint32_t)
The maximum number of defined tables for a core module (default is 1).
WASM_API_EXTERN void wasmtime_pooling_allocation_config_max_tables_per_component_set(wasmtime_pooling_allocation_config_t *, uint32_t)
The maximum number of tables that a single component may transitively contain (default is unlimited).
WASM_API_EXTERN wasmtime_pooling_allocation_config_t * wasmtime_pooling_allocation_config_new()
Creates a new pooling allocation configuration object. Must be deallocated with a call to wasmtime_po...
WASM_API_EXTERN void wasmtime_config_cranelift_flag_enable(wasm_config_t *, const char *)
Enables a target-specific flag in Cranelift.
WASM_API_EXTERN void wasmtime_config_parallel_compilation_set(wasm_config_t *, bool)
Configure whether wasmtime should compile a module using multiple threads.
WASM_API_EXTERN void wasmtime_pooling_allocation_config_max_unused_warm_slots_set(wasmtime_pooling_allocation_config_t *, uint32_t)
Configures the maximum number of “unused warm slots” to retain in the pooling allocator.
WASM_API_EXTERN void wasmtime_config_wasm_gc_set(wasm_config_t *, bool)
Configures whether the WebAssembly GC proposal is enabled.
WASM_API_EXTERN void wasmtime_config_macos_use_mach_ports_set(wasm_config_t *, bool)
Configures whether, when on macOS, Mach ports are used for exception handling instead of traditional ...
WASM_API_EXTERN void wasmtime_config_wasm_memory64_set(wasm_config_t *, bool)
Configures whether the WebAssembly memory64 proposal is enabled.
WASM_API_EXTERN void wasmtime_pooling_allocation_config_max_memories_per_module_set(wasmtime_pooling_allocation_config_t *, uint32_t)
The maximum number of defined linear memories for a module (default is 1).
WASM_API_EXTERN void wasmtime_config_wasm_relaxed_simd_set(wasm_config_t *, bool)
Configures whether the WebAssembly relaxed SIMD proposal is enabled.
WASM_API_EXTERN void wasmtime_pooling_allocation_config_total_memories_set(wasmtime_pooling_allocation_config_t *, uint32_t)
The maximum number of concurrent Wasm linear memories supported (default is 1000).
WASM_API_EXTERN void wasmtime_config_wasm_bulk_memory_set(wasm_config_t *, bool)
Configures whether the WebAssembly bulk memory proposal is enabled.
uint8_t wasmtime_profiling_strategy_t
Different ways wasmtime can enable profiling JIT code.
Definition: config.h:66
WASM_API_EXTERN void wasmtime_config_cranelift_flag_set(wasm_config_t *, const char *key, const char *value)
Sets a target-specific flag in Cranelift to the specified value.
WASM_API_EXTERN void wasmtime_config_wasm_threads_set(wasm_config_t *, bool)
Configures whether the WebAssembly threading proposal is enabled.
WASM_API_EXTERN void wasmtime_pooling_allocation_config_table_elements_set(wasmtime_pooling_allocation_config_t *, size_t)
The maximum table elements for any table defined in a module (default is 20000).
WASM_API_EXTERN void wasmtime_pooling_allocation_config_max_core_instance_size_set(wasmtime_pooling_allocation_config_t *, size_t)
The maximum size, in bytes, allocated for a core instance’s VMContext metadata.
WASM_API_EXTERN void wasmtime_config_strategy_set(wasm_config_t *, wasmtime_strategy_t)
Configures how JIT code will be compiled.
WASM_API_EXTERN void wasmtime_config_signals_based_traps_set(wasm_config_t *, bool)
Configures Wasmtime to not use signals-based trap handlers, for example disables SIGILL and SIGSEGV h...
@ WASMTIME_PROFILING_STRATEGY_VTUNE
Definition: config.h:83
@ WASMTIME_PROFILING_STRATEGY_PERFMAP
Definition: config.h:87
@ WASMTIME_PROFILING_STRATEGY_NONE
No profiling is enabled at runtime.
Definition: config.h:75
@ WASMTIME_PROFILING_STRATEGY_JITDUMP
Definition: config.h:78
WASM_API_EXTERN void wasmtime_config_memory_guard_size_set(wasm_config_t *, uint64_t)
Configures the guard region size for linear memory.
WASM_API_EXTERN void wasmtime_config_cranelift_debug_verifier_set(wasm_config_t *, bool)
Configures whether Cranelift's debug verifier is enabled.
WASM_API_EXTERN void wasmtime_pooling_allocation_config_total_stacks_set(wasmtime_pooling_allocation_config_t *, uint32_t)
The maximum number of execution stacks allowed for asynchronous execution, when enabled (default is 1...
@ WASMTIME_STRATEGY_CRANELIFT
Definition: config.h:36
@ WASMTIME_STRATEGY_AUTO
Definition: config.h:32
WASM_API_EXTERN void wasmtime_pooling_allocation_config_max_memories_per_component_set(wasmtime_pooling_allocation_config_t *, uint32_t)
The maximum number of Wasm linear memories that a single component may transitively contain (default ...
WASM_API_EXTERN void wasmtime_config_cranelift_opt_level_set(wasm_config_t *, wasmtime_opt_level_t)
Configures Cranelift's optimization level for JIT code.
WASM_API_EXTERN void wasmtime_config_consume_fuel_set(wasm_config_t *, bool)
Whether or not fuel is enabled for generated code.
WASM_API_EXTERN void wasmtime_config_debug_info_set(wasm_config_t *, bool)
Configures whether DWARF debug information is constructed at runtime to describe JIT code.
WASM_API_EXTERN void wasmtime_config_wasm_relaxed_simd_deterministic_set(wasm_config_t *, bool)
Configures whether the WebAssembly relaxed SIMD proposal is in deterministic mode.
WASM_API_EXTERN void wasmtime_config_wasm_exceptions_set(wasm_config_t *, bool)
Configures whether the WebAssembly exceptions proposal is enabled.
WASM_API_EXTERN void wasmtime_config_native_unwind_info_set(wasm_config_t *, bool)
Configures whether to generate native unwind information (e.g. .eh_frame on Linux).
@ WASMTIME_OPT_LEVEL_SPEED_AND_SIZE
Definition: config.h:58
@ WASMTIME_OPT_LEVEL_NONE
Generated code will not be optimized at all.
Definition: config.h:53
@ WASMTIME_OPT_LEVEL_SPEED
Generated code will be optimized purely for speed.
Definition: config.h:55
uint8_t wasmtime_opt_level_t
Specifier of what optimization level to use for generated JIT code.
Definition: config.h:44
WASM_API_EXTERN void wasmtime_config_profiler_set(wasm_config_t *, wasmtime_profiling_strategy_t)
Configures the profiling strategy used for JIT code.
WASM_API_EXTERN void wasmtime_config_wasm_simd_set(wasm_config_t *, bool)
Configures whether the WebAssembly SIMD proposal is enabled.
WASM_API_EXTERN void wasmtime_config_epoch_interruption_set(wasm_config_t *, bool)
Whether or not epoch-based interruption is enabled for generated code.
WASM_API_EXTERN void wasmtime_config_cranelift_nan_canonicalization_set(wasm_config_t *, bool)
Configures whether Cranelift should perform a NaN-canonicalization pass.
WASM_API_EXTERN void wasmtime_config_memory_reservation_for_growth_set(wasm_config_t *, uint64_t)
Configures the size, in bytes, of the extra virtual memory space reserved for memories to grow into a...
WASM_API_EXTERN void wasmtime_pooling_allocation_config_total_core_instances_set(wasmtime_pooling_allocation_config_t *, uint32_t)
The maximum number of concurrent core instances supported (default is 1000).
WASM_API_EXTERN void wasmtime_config_host_memory_creator_set(wasm_config_t *, wasmtime_memory_creator_t *)
WASM_API_EXTERN void wasmtime_pooling_allocation_config_total_tables_set(wasmtime_pooling_allocation_config_t *, uint32_t)
The maximum number of concurrent tables supported (default is 1000).
WASM_API_EXTERN void wasmtime_config_wasm_function_references_set(wasm_config_t *, bool)
Configures whether the WebAssembly typed function reference types proposal is enabled.
WASM_API_EXTERN void wasmtime_pooling_allocation_config_decommit_batch_size_set(wasmtime_pooling_allocation_config_t *, size_t)
The target number of decommits to do per batch.
WASM_API_EXTERN void wasmtime_config_wasm_reference_types_set(wasm_config_t *, bool)
Configures whether the WebAssembly reference types proposal is enabled.
WASM_API_EXTERN void wasmtime_config_memory_init_cow_set(wasm_config_t *, bool)
Configures whether copy-on-write memory-mapped data is used to initialize a linear memory.
WASM_API_EXTERN void wasmtime_config_wasm_multi_value_set(wasm_config_t *, bool)
Configures whether the WebAssembly multi value proposal is enabled.
WASM_API_EXTERN void wasmtime_pooling_allocation_config_max_memory_size_set(wasmtime_pooling_allocation_config_t *, size_t)
The maximum byte size that any WebAssembly linear memory may grow to.
WASM_API_EXTERN void wasmtime_config_memory_may_move_set(wasm_config_t *, bool)
Configures whether memory_reservation is the maximal size of linear memory.
WASM_API_EXTERN void wasmtime_pooling_allocation_config_max_component_instance_size_set(wasmtime_pooling_allocation_config_t *, size_t)
The maximum size, in bytes, allocated for a component instance’s VMComponentContext metadata.
WASM_API_EXTERN void wasmtime_pooling_allocation_config_async_stack_keep_resident_set(wasmtime_pooling_allocation_config_t *, size_t)
How much memory, in bytes, to keep resident for async stacks allocated with the pooling allocator.
Strategy
Strategies passed to Config::strategy
Definition: config.hh:17
@ Auto
Automatically selects the compilation strategy.
@ Cranelift
Requires Cranelift to be used for compilation.
OptLevel
Values passed to Config::cranelift_opt_level
Definition: config.hh:25
@ Speed
Optimize for speed.
@ None
No extra optimizations performed.
@ SpeedAndSize
Optimize for speed and generated code size.
ProfilingStrategy
Values passed to Config::profiler
Definition: config.hh:35
@ Perfmap
Profiling hooks via perfmap.
@ Vtune
Profiling hooks via VTune.
@ Jitdump
Profiling hooks via perf's jitdump.
An opaque object representing the type of a memory.
Errors generated by Wasmtime.
wasmtime_memory_get_callback_t get_memory
Callback to get the memory and size of this LinearMemory.
Definition: config.h:506
void * env
User provided value to be passed to get_memory and grow_memory.
Definition: config.h:504
void(* finalizer)(void *)
An optional finalizer for env.
Definition: config.h:510
wasmtime_memory_grow_callback_t grow_memory
Callback to request growing the memory.
Definition: config.h:508
void(* finalizer)(void *)
An optional finalizer for env.
Definition: config.h:542
wasmtime_new_memory_callback_t new_memory
The callback to create new memory, must be thread safe.
Definition: config.h:540
void * env
User provided value to be passed to new_memory.
Definition: config.h:538
wasm_config_t * wasm_config_new(void)
Creates a new empty configuration object.