Add fuel related functions to c-api (#2643)
Co-authored-by: Shu <me@wadza.fr>
This commit is contained in:
@@ -152,6 +152,15 @@ WASMTIME_CONFIG_PROP(void, debug_info, bool)
|
||||
*/
|
||||
WASMTIME_CONFIG_PROP(void, interruptable, bool)
|
||||
|
||||
/**
|
||||
* \brief Whether or not fuel is enabled for generated code.
|
||||
*
|
||||
* This setting is `false` by default. When enabled it will enable fuel counting
|
||||
* meaning that fuel will be consumed every time a wasm instruction is executed,
|
||||
* and trap when reaching zero.
|
||||
*/
|
||||
WASMTIME_CONFIG_PROP(void, consume_fuel, bool)
|
||||
|
||||
/**
|
||||
* \brief Configures the maximum stack size, in bytes, that JIT code can use.
|
||||
*
|
||||
@@ -635,6 +644,29 @@ WASMTIME_DECLARE_OWN(interrupt_handle)
|
||||
*/
|
||||
WASM_API_EXTERN own wasmtime_interrupt_handle_t *wasmtime_interrupt_handle_new(wasm_store_t *store);
|
||||
|
||||
/**
|
||||
* \brief Adds fuel to this 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.
|
||||
*/
|
||||
WASM_API_EXTERN void wasmtime_add_fuel(wasm_store_t *store, uint64_t fuel);
|
||||
|
||||
/**
|
||||
* \brief Returns the amount of fuel consumed by this store's execution so far.
|
||||
*
|
||||
* If fuel consumption is not enabled via #wasmtime_config_consume_fuel_set
|
||||
* then this function will return 0. Also note that fuel, if enabled, must be
|
||||
* originally configured via #wasmtime_add_fuel.
|
||||
*/
|
||||
WASM_API_EXTERN uint64_t wasmtime_fuel_consumed(wasm_store_t *store);
|
||||
|
||||
/**
|
||||
* \brief Requests that WebAssembly code running in the store attached to this
|
||||
* interrupt handle is interrupted.
|
||||
|
||||
Reference in New Issue
Block a user