From 47a218f908e6bdeb7a0fb65ed74e58a0b608080d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 2 Jul 2020 09:26:10 -0500 Subject: [PATCH] Document the rest of the C API (#1959) This commit fills out documentation for all remaining functions in the C API, and additionally enables "warn if undocumented" which will fail CI since warnings are also treated as errors. --- crates/c-api/doxygen.conf | 4 +- crates/c-api/include/doc-wasm.h | 1993 +++++++++++++++++++++++++++++-- crates/c-api/include/wasi.h | 154 ++- crates/c-api/include/wasmtime.h | 690 +++++++++-- 4 files changed, 2659 insertions(+), 182 deletions(-) diff --git a/crates/c-api/doxygen.conf b/crates/c-api/doxygen.conf index f7c6c12951..b8c1b5273c 100644 --- a/crates/c-api/doxygen.conf +++ b/crates/c-api/doxygen.conf @@ -778,7 +778,7 @@ WARNINGS = YES # will automatically be disabled. # The default value is: YES. -WARN_IF_UNDOCUMENTED = NO +WARN_IF_UNDOCUMENTED = YES # If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for # potential errors in the documentation, such as not documenting some parameters @@ -901,7 +901,9 @@ EXCLUDE_PATTERNS = EXCLUDE_SYMBOLS = assertions \ WASM_DECLARE_* \ WASM_API_EXTERN \ + WASI_API_EXTERN \ WASMTIME_DECLARE_OWN \ + WASI_DECLARE_OWN \ WASMTIME_CONFIG_PROP \ own diff --git a/crates/c-api/include/doc-wasm.h b/crates/c-api/include/doc-wasm.h index cf87c821cf..bd3703c7ab 100644 --- a/crates/c-api/include/doc-wasm.h +++ b/crates/c-api/include/doc-wasm.h @@ -35,6 +35,16 @@ * object. You'll need to still call #wasm_memory_delete (or the corresponding * `*_delete` function) for each copy of an object you acquire. * + * ### Vectors + * + * This API provides a number of `wasm_*_vec_t` type definitions and functions + * to work with them. Each vector is defined by a pointer and a length. + * "Ownership" of a vector refers to the data pointer, not the memory holding + * the data pointer and the length. It is safe, for example to create a + * #wasm_name_t on the stack and pass it to #wasm_importtype_new. The memory + * pointed to by #wasm_name_t must be properly initialized, however, and cannot + * reside on the stack. + * * ### Thread Safety * * All objects are not thread safe unless otherwise noted. This means that all @@ -48,47 +58,61 @@ * Note that if you move a #wasm_store_t between threads this is ok so long as * you move *all* references within that store to the new thread. If any * reference lingers on the previous thread then that is unsafe. + * + * ### Stores + * + * A foundational construct in this API is the #wasm_store_t. A store is a + * collection of host-provided objects and instantiated wasm modules. Stores are + * often treated as a "single unit" and items within a store are all allowed to + * reference one another. References across stores cannot currently be created. + * For example you cannot instantiate a module in one store with an instance + * from another store. + * + * Stores are entirely single-threaded. All objects referencing a #wasm_store_t + * are pinned to a single thread and must reside in the same thread as all other + * objects referencing the same store. + * + * A store is not intended to be a global long-lived object. Memory associated + * with a #wasm_instance_t is not deallocated until the entire #wasm_store_t has + * been deallocated. This means that if you instantiate a module and then delete + * the instance, the instance's backing memory isn't actually deleted (it's + * still referenced by the #wasm_store_t). This aspect makes a #wasm_store_t + * unsuitable for repeatedly instantiating modules over a long period of time + * because memory usage will continue to grow. + * + * If you're working with a web server, for example, then it's recommended to + * think of a store as a "one per request" sort of construct. Globally you'd + * have one #wasm_engine_t and a cache of #wasm_module_t instances compiled into + * that engine. Each request would create a new #wasm_store_t and then + * instantiate a #wasm_module_t into the store. This process of creating a store + * and instantiating a module is expected to be quite fast. When the request is + * finished you'd delete the #wasm_store_t and #wasm_instance_t (along with any + * other references), keeping memory usage reasonable for the lifetime of the + * server. */ /** * \typedef byte_t - * \headerfile wasm.h * \brief A type definition for a number that occupies a single byte of data. - */ - -/** + * * \typedef wasm_byte_t - * \headerfile wasm.h * \brief A type definition for a number that occupies a single byte of data. - */ - -/** + * * \typedef float32_t - * \headerfile wasm.h * \brief A type definition for a 32-bit float. - */ - -/** + * * \typedef float64_t - * \headerfile wasm.h * \brief A type definition for a 64-bit float. - */ - -/** + * * \typedef wasm_name_t - * \headerfile wasm.h * \brief Convenience for hinting that an argument only accepts utf-8 input. */ /** * \typedef wasm_config_t - * \headerfile wasm.h * \brief Convenience alias for #wasm_config_t - */ - -/** + * * \struct wasm_config_t - * \headerfile wasm.h * \brief Global engine configuration * * This structure represents global configuration used when constructing a @@ -101,31 +125,27 @@ * Configuration is safe to share between threads. Typically you'll create a * config object and immediately pass it into #wasm_engine_new_with_config, * however. - */ - -/** + * + * For more information about configuration see the Rust documentation as well + * at + * https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Config.html. + * * \fn own wasm_config_t *wasm_config_new(void); * \brief Creates a new empty configuration object. * * The object returned is owned by the caller and will need to be deleted with * #wasm_config_delete. May return `NULL` if a configuration object could not be * allocated. - */ - -/** + * * \fn void wasm_config_delete(own wasm_config_t*); * \brief Deletes a configuration object. */ /** * \typedef wasm_engine_t - * \headerfile wasm.h * \brief Convenience alias for #wasm_engine_t - */ - -/** + * * \struct wasm_engine_t - * \headerfile wasm.h * \brief Typically global object to create #wasm_store_t from. * * An engine is typically global in a program and contains all the configuration @@ -136,18 +156,14 @@ * An engine is safe to share between threads. Multiple stores can be created * within the same engine with each store living on a separate thread. Typically * you'll create one #wasm_engine_t for the lifetime of your program. - */ - -/** + * * \fn own wasm_engine_t *wasm_engine_new(void); * \brief Creates a new engine with the default configuration. * * The object returned is owned by the caller and will need to be deleted with * #wasm_engine_delete. This may return `NULL` if the engine could not be * allocated. - */ - -/** + * * \fn own wasm_engine_t *wasm_engine_new_with_config(wasm_config_t *); * \brief Creates a new engine with the specified configuration. * @@ -156,64 +172,73 @@ * on the argument. The object returned is owned by the caller and will need to * be deleted with #wasm_engine_delete. This may return `NULL` if the engine * could not be allocated. - */ - -/** + * * \fn void wasm_engine_delete(own wasm_engine_t*); * \brief Deletes an engine. */ /** * \typedef wasm_store_t - * \headerfile wasm.h * \brief Convenience alias for #wasm_store_t - */ - -/** + * * \struct wasm_store_t - * \headerfile wasm.h * \brief A collection of instances and wasm global items. * * A #wasm_store_t corresponds to the concept of an [embedding * store](https://webassembly.github.io/spec/core/exec/runtime.html#store) - */ - -/** + * * \fn own wasm_store_t *wasm_store_new(wasm_engine_t *); * \brief Creates a new store within the specified engine. * * The object returned is owned by the caller and will need to be deleted with * #wasm_store_delete. This may return `NULL` if the store could not be * allocated. - */ - -/** + * * \fn void wasm_store_delete(own wasm_store_t *); * \brief Deletes the specified store. */ /** * \struct wasm_byte_vec_t - * \headerfile wasm.h * \brief A list of bytes * * Used to pass data in or pass data out of various functions. The meaning and * ownership of the bytes is defined by each API that operates on this * datatype. - */ - -/** + * + * \var wasm_byte_vec_t::size + * \brief Length of this vector. + * + * \var wasm_byte_vec_t::data + * \brief Pointer to the base of this vector + * * \typedef wasm_byte_vec_t - * \headerfile wasm.h * \brief Convenience alias for #wasm_byte_vec_t - */ - -/** + * + * \typedef wasm_message_t + * \brief Alias of #wasm_byte_vec_t which always has a trailing 0-byte. + * + * \fn wasm_name + * \brief Unused by Wasmtime + * + * \fn wasm_name_new + * \brief Convenience alias + * + * \fn wasm_name_new_empty + * \brief Convenience alias + * + * \fn wasm_name_new_new_uninitialized + * \brief Convenience alias + * + * \fn wasm_name_copy + * \brief Convenience alias + * + * \fn wasm_name_delete + * \brief Convenience alias + * * \fn void wasm_byte_vec_new_empty(own wasm_byte_vec_t *out); * \brief Initializes an empty byte vector. - */ - -/** + * * \fn void wasm_byte_vec_new_uninitialized(own wasm_byte_vec_t *out, size_t); * \brief Initializes an byte vector with the specified capacity. * @@ -221,27 +246,25 @@ * specified number of bytes. The `out` parameter must previously not already be * initialized and after this function is called you are then responsible for * ensuring #wasm_byte_vec_delete is called. - */ - -/** + * * \fn void wasm_byte_vec_new(own wasm_byte_vec_t *out, size_t, own wasm_byte_t const[]); * \brief Copies the specified data into a new byte vector. * * This function will copy the provided data into this byte vector. The byte * vector should not be previously initialized and the caller is responsible for * calling #wasm_byte_vec_delete after this function returns. - */ - -/** + * + * Note that memory of the the initialization vector provided to this function + * must be managed externally. This function will copy the contents to the + * output vector, but it's up to the caller to properly deallocate the memory. + * * \fn void wasm_byte_vec_copy(own wasm_byte_vec_t *out, const wasm_byte_vec_t *); * \brief Copies one vector into a new vector. * * Copies the second argument's data into the first argument. The `out` vector * should not be previously initialized and after this function returns you're * responsible for calling #wasm_byte_vec_delete. - */ - -/** + * * \fn void wasm_byte_vec_delete(own wasm_byte_vec_t *); * \brief Deletes a byte vector. * @@ -251,15 +274,1825 @@ */ /** - * \fn own wasm_memory_t *wasm_memory_copy(const wasm_memory_t *); - * \brief Creates a new reference to the same memory. + * \struct wasm_valtype_t + * \brief An object representing the type of a value. * - * The object returned is owned by the caller and will need to be deleted with - * #wasm_memory_delete. This may return `NULL` if the new object could not be - * allocated. + * \typedef wasm_valtype_t + * \brief Convenience alias for #wasm_valtype_t + * + * \struct wasm_valtype_vec_t + * \brief A list of #wasm_valtype_t values. + * + * \var wasm_valtype_vec_t::size + * \brief Length of this vector. + * + * \var wasm_valtype_vec_t::data + * \brief Pointer to the base of this vector + * + * \typedef wasm_valtype_vec_t + * \brief Convenience alias for #wasm_valtype_vec_t + * + * \fn void wasm_valtype_delete(own wasm_valtype_t *); + * \brief Deletes a type. + * + * \fn void wasm_valtype_vec_new_empty(own wasm_valtype_vec_t *out); + * \brief Creates an empty vector. + * + * See #wasm_byte_vec_new_empty for more information. + * + * \fn void wasm_valtype_vec_new_uninitialized(own wasm_valtype_vec_t *out, size_t); + * \brief Creates a vector with the given capacity. + * + * See #wasm_byte_vec_new_uninitialized for more information. + * + * \fn void wasm_valtype_vec_new(own wasm_valtype_vec_t *out, size_t, own wasm_valtype_t *const[]); + * \brief Creates a vector with the provided contents. + * + * See #wasm_byte_vec_new for more information. + * + * \fn void wasm_valtype_vec_copy(own wasm_valtype_vec_t *out, const wasm_valtype_vec_t *) + * \brief Copies one vector to another + * + * See #wasm_byte_vec_copy for more information. + * + * \fn void wasm_valtype_vec_delete(own wasm_valtype_vec_t *out) + * \brief Deallocates memory for a vector. + * + * See #wasm_byte_vec_delete for more information. + * + * \fn own wasm_valtype_t* wasm_valtype_copy(wasm_valtype_t *) + * \brief Creates a new value which matches the provided one. + * + * The caller is responsible for deleting the returned value. + * + * \fn own wasm_valtype_t* wasm_valtype_new(wasm_valkind_t); + * \brief Creates a new value type from the specified kind. + * + * The caller is responsible for deleting the returned value. + * + * \fn wasm_valkind_t wasm_valtype_kind(const wasm_valtype_t *); + * \brief Returns the associated kind for this value type. */ /** - * \fn void wasm_memory_delete(own wasm_memory_t*); - * \brief Deletes a memory object. + * \typedef wasm_valkind_t + * \brief Indicator for the kind of a type, with values defined by + * #wasm_valkind_enum + * + * \enum wasm_valkind_enum + * \brief Different kinds of types supported in wasm. + */ + +/** + * \struct wasm_functype_t + * \brief An opaque object representing the type of a function. + * + * \typedef wasm_functype_t + * \brief Convenience alias for #wasm_functype_t + * + * \struct wasm_functype_vec_t + * \brief A list of #wasm_functype_t values. + * + * \var wasm_functype_vec_t::size + * \brief Length of this vector. + * + * \var wasm_functype_vec_t::data + * \brief Pointer to the base of this vector + * + * \typedef wasm_functype_vec_t + * \brief Convenience alias for #wasm_functype_vec_t + * + * \fn void wasm_functype_delete(own wasm_functype_t *); + * \brief Deletes a type. + * + * \fn void wasm_functype_vec_new_empty(own wasm_functype_vec_t *out); + * \brief Creates an empty vector. + * + * See #wasm_byte_vec_new_empty for more information. + * + * \fn void wasm_functype_vec_new_uninitialized(own wasm_functype_vec_t *out, size_t); + * \brief Creates a vector with the given capacity. + * + * See #wasm_byte_vec_new_uninitialized for more information. + * + * \fn void wasm_functype_vec_new(own wasm_functype_vec_t *out, size_t, own wasm_functype_t *const[]); + * \brief Creates a vector with the provided contents. + * + * See #wasm_byte_vec_new for more information. + * + * \fn void wasm_functype_vec_copy(own wasm_functype_vec_t *out, const wasm_functype_vec_t *) + * \brief Copies one vector to another + * + * See #wasm_byte_vec_copy for more information. + * + * \fn void wasm_functype_vec_delete(own wasm_functype_vec_t *out) + * \brief Deallocates memory for a vector. + * + * See #wasm_byte_vec_delete for more information. + * + * \fn own wasm_functype_t* wasm_functype_copy(wasm_functype_t *) + * \brief Creates a new value which matches the provided one. + * + * The caller is responsible for deleting the returned value. + * + * \fn own wasm_functype_t* wasm_functype_new(wasm_valtype_vec_t *params, wasm_valtype_vec_t *results); + * \brief Creates a new function type with the provided parameter and result + * types. + * + * The caller is responsible for deleting the returned value. + * + * \fn const wasm_valtype_vec_t* wasm_functype_params(const wasm_functype_t *); + * \brief Returns the list of parameters of this function type. + * + * The returned memory is owned by the #wasm_functype_t argument, the caller + * should not deallocate it. + * + * \fn const wasm_valtype_vec_t* wasm_functype_results(const wasm_functype_t *); + * \brief Returns the list of results of this function type. + * + * The returned memory is owned by the #wasm_functype_t argument, the caller + * should not deallocate it. + */ + +/** + * \struct wasm_globaltype_t + * \brief An opaque object representing the type of a global. + * + * \typedef wasm_globaltype_t + * \brief Convenience alias for #wasm_globaltype_t + * + * \struct wasm_globaltype_vec_t + * \brief A list of #wasm_globaltype_t values. + * + * \var wasm_globaltype_vec_t::size + * \brief Length of this vector. + * + * \var wasm_globaltype_vec_t::data + * \brief Pointer to the base of this vector + * + * \typedef wasm_globaltype_vec_t + * \brief Convenience alias for #wasm_globaltype_vec_t + * + * \fn void wasm_globaltype_delete(own wasm_globaltype_t *); + * \brief Deletes a type. + * + * \fn void wasm_globaltype_vec_new_empty(own wasm_globaltype_vec_t *out); + * \brief Creates an empty vector. + * + * See #wasm_byte_vec_new_empty for more information. + * + * \fn void wasm_globaltype_vec_new_uninitialized(own wasm_globaltype_vec_t *out, size_t); + * \brief Creates a vector with the given capacity. + * + * See #wasm_byte_vec_new_uninitialized for more information. + * + * \fn void wasm_globaltype_vec_new(own wasm_globaltype_vec_t *out, size_t, own wasm_globaltype_t *const[]); + * \brief Creates a vector with the provided contents. + * + * See #wasm_byte_vec_new for more information. + * + * \fn void wasm_globaltype_vec_copy(own wasm_globaltype_vec_t *out, const wasm_globaltype_vec_t *) + * \brief Copies one vector to another + * + * See #wasm_byte_vec_copy for more information. + * + * \fn void wasm_globaltype_vec_delete(own wasm_globaltype_vec_t *out) + * \brief Deallocates memory for a vector. + * + * See #wasm_byte_vec_delete for more information. + * + * \fn own wasm_globaltype_t* wasm_globaltype_copy(wasm_globaltype_t *) + * \brief Creates a new value which matches the provided one. + * + * The caller is responsible for deleting the returned value. + * + * \fn own wasm_globaltype_t* wasm_globaltype_new(wasm_valtype_t *, wasm_mutability_t) + * \brief Creates a new global type. + * + * This function takes ownership of the #wasm_valtype_t argument. + * + * The caller is responsible for deleting the returned value. + * + * \fn const wasm_valtype_t* wasm_globaltype_content(const wasm_globaltype_t *); + * \brief Returns the type of value contained in a global. + * + * The returned memory is owned by the provided #wasm_globaltype_t, the caller + * should not deallocate it. + * + * \fn wasm_mutability_t wasm_globaltype_mutability(const wasm_globaltype_t *); + * \brief Returns whether or not a global is mutable. + */ + +/** + * \typedef wasm_mutability_t + * \brief Typedef for the #wasm_mutability_enum values. + * + * \enum wasm_mutability_enum + * \brief Boolean flag for whether a global is mutable or not. + */ + +/** + * \struct wasm_tabletype_t + * \brief An opaque object representing the type of a table. + * + * \typedef wasm_tabletype_t + * \brief Convenience alias for #wasm_tabletype_t + * + * \struct wasm_tabletype_vec_t + * \brief A list of #wasm_tabletype_t values. + * + * \var wasm_tabletype_vec_t::size + * \brief Length of this vector. + * + * \var wasm_tabletype_vec_t::data + * \brief Pointer to the base of this vector + * + * \typedef wasm_tabletype_vec_t + * \brief Convenience alias for #wasm_tabletype_vec_t + * + * \fn void wasm_tabletype_delete(own wasm_tabletype_t *); + * \brief Deletes a type. + * + * \fn void wasm_tabletype_vec_new_empty(own wasm_tabletype_vec_t *out); + * \brief Creates an empty vector. + * + * See #wasm_byte_vec_new_empty for more information. + * + * \fn void wasm_tabletype_vec_new_uninitialized(own wasm_tabletype_vec_t *out, size_t); + * \brief Creates a vector with the given capacity. + * + * See #wasm_byte_vec_new_uninitialized for more information. + * + * \fn void wasm_tabletype_vec_new(own wasm_tabletype_vec_t *out, size_t, own wasm_tabletype_t *const[]); + * \brief Creates a vector with the provided contents. + * + * See #wasm_byte_vec_new for more information. + * + * \fn void wasm_tabletype_vec_copy(own wasm_tabletype_vec_t *out, const wasm_tabletype_vec_t *) + * \brief Copies one vector to another + * + * See #wasm_byte_vec_copy for more information. + * + * \fn void wasm_tabletype_vec_delete(own wasm_tabletype_vec_t *out) + * \brief Deallocates memory for a vector. + * + * See #wasm_byte_vec_delete for more information. + * + * \fn own wasm_tabletype_t* wasm_tabletype_copy(wasm_tabletype_t *) + * \brief Creates a new value which matches the provided one. + * + * The caller is responsible for deleting the returned value. + * + * \fn own wasm_tabletype_t* wasm_tabletype_new(wasm_valtype_t *, const wasm_limits_t *)h + * \brief Creates a new table type. + * + * This function takes ownership of the #wasm_valtype_t argument, but does not + * take ownership of the #wasm_limits_t. + * + * The caller is responsible for deallocating the returned type. + * + * \fn const wasm_valtype_t* wasm_tabletype_element(const wasm_tabletype_t *); + * \brief Returns the element type of this table. + * + * The returned #wasm_valtype_t is owned by the #wasm_tabletype_t parameter, the + * caller should not deallocate it. + * + * \fn const wasm_limits_t* wasm_tabletype_limits(const wasm_tabletype_t *); + * \brief Returns the limits of this table. + * + * The returned #wasm_limits_t is owned by the #wasm_tabletype_t parameter, the + * caller should not deallocate it. + */ + +/** + * \struct wasm_limits_t + * \brief Limits for tables/memories in wasm modules + * \var wasm_limits_t::min + * The minimum value required. + * \var wasm_limits_t::max + * The maximum value required, or `wasm_limits_max_default` if no maximum is + * specified. + * + * \typedef wasm_limits_t + * \brief A convenience typedef to #wasm_limits_t + */ + +/** + * \struct wasm_memorytype_t + * \brief An opaque object representing the type of a memory. + * + * \typedef wasm_memorytype_t + * \brief Convenience alias for #wasm_memorytype_t + * + * \struct wasm_memorytype_vec_t + * \brief A list of #wasm_memorytype_t values. + * + * \var wasm_memorytype_vec_t::size + * \brief Length of this vector. + * + * \var wasm_memorytype_vec_t::data + * \brief Pointer to the base of this vector + * + * \typedef wasm_memorytype_vec_t + * \brief Convenience alias for #wasm_memorytype_vec_t + * + * \fn void wasm_memorytype_delete(own wasm_memorytype_t *); + * \brief Deletes a type. + * + * \fn void wasm_memorytype_vec_new_empty(own wasm_memorytype_vec_t *out); + * \brief Creates an empty vector. + * + * See #wasm_byte_vec_new_empty for more information. + * + * \fn void wasm_memorytype_vec_new_uninitialized(own wasm_memorytype_vec_t *out, size_t); + * \brief Creates a vector with the given capacity. + * + * See #wasm_byte_vec_new_uninitialized for more information. + * + * \fn void wasm_memorytype_vec_new(own wasm_memorytype_vec_t *out, size_t, own wasm_memorytype_t *const[]); + * \brief Creates a vector with the provided contents. + * + * See #wasm_byte_vec_new for more information. + * + * \fn void wasm_memorytype_vec_copy(own wasm_memorytype_vec_t *out, const wasm_memorytype_vec_t *) + * \brief Copies one vector to another + * + * See #wasm_byte_vec_copy for more information. + * + * \fn void wasm_memorytype_vec_delete(own wasm_memorytype_vec_t *out) + * \brief Deallocates memory for a vector. + * + * See #wasm_byte_vec_delete for more information. + * + * \fn own wasm_memorytype_t* wasm_memorytype_copy(wasm_memorytype_t *) + * \brief Creates a new value which matches the provided one. + * + * The caller is responsible for deleting the returned value. + * + * \fn own wasm_memorytype_t* wasm_memorytype_new(const wasm_limits_t *)h + * \brief Creates a new memory type. + * + * This function takes ownership of the #wasm_valtype_t argument, but does not + * take ownership of the #wasm_limits_t. + * + * The caller is responsible for deallocating the returned type. + * + * \fn const wasm_limits_t* wasm_memorytype_limits(const wasm_memorytype_t *); + * \brief Returns the limits of this memory. + * + * The returned #wasm_limits_t is owned by the #wasm_memorytype_t parameter, the + * caller should not deallocate it. + */ + +/** + * \struct wasm_externtype_t + * \brief An opaque object representing the type of a external value. Can be + * seen as a superclass of #wasm_functype_t, #wasm_tabletype_t, + * #wasm_globaltype_t, and #wasm_memorytype_t. + * + * \typedef wasm_externtype_t + * \brief Convenience alias for #wasm_externtype_t + * + * \struct wasm_externtype_vec_t + * \brief A list of #wasm_externtype_t values. + * + * \var wasm_externtype_vec_t::size + * \brief Length of this vector. + * + * \var wasm_externtype_vec_t::data + * \brief Pointer to the base of this vector + * + * \typedef wasm_externtype_vec_t + * \brief Convenience alias for #wasm_externtype_vec_t + * + * \fn void wasm_externtype_delete(own wasm_externtype_t *); + * \brief Deletes a type. + * + * \fn void wasm_externtype_vec_new_empty(own wasm_externtype_vec_t *out); + * \brief Creates an empty vector. + * + * See #wasm_byte_vec_new_empty for more information. + * + * \fn void wasm_externtype_vec_new_uninitialized(own wasm_externtype_vec_t *out, size_t); + * \brief Creates a vector with the given capacity. + * + * See #wasm_byte_vec_new_uninitialized for more information. + * + * \fn void wasm_externtype_vec_new(own wasm_externtype_vec_t *out, size_t, own wasm_externtype_t *const[]); + * \brief Creates a vector with the provided contents. + * + * See #wasm_byte_vec_new for more information. + * + * \fn void wasm_externtype_vec_copy(own wasm_externtype_vec_t *out, const wasm_externtype_vec_t *) + * \brief Copies one vector to another + * + * See #wasm_byte_vec_copy for more information. + * + * \fn void wasm_externtype_vec_delete(own wasm_externtype_vec_t *out) + * \brief Deallocates extern for a vector. + * + * See #wasm_byte_vec_delete for more information. + * + * \fn own wasm_externtype_t* wasm_externtype_copy(wasm_externtype_t *) + * \brief Creates a new value which matches the provided one. + * + * The caller is responsible for deleting the returned value. + * + * \fn wasm_externkind_t wasm_externtype_kind(const wasm_externtype_t *) + * \brief Returns the kind of external item this type represents. + */ + +/** + * \typedef wasm_externkind_t + * \brief Classifier for #wasm_externtype_t, defined by #wasm_externkind_enum + * + * \enum wasm_externkind_enum + * \brief Kinds of external items for a wasm module. + */ + +/** + * \fn wasm_externtype_t* wasm_functype_as_externtype(wasm_functype_t *) + * \brief Converts a #wasm_functype_t to a #wasm_externtype_t + * + * The returned value is owned by the #wasm_functype_t argument and should not + * be deleted. + * + * \fn wasm_externtype_t* wasm_tabletype_as_externtype(wasm_tabletype_t *) + * \brief Converts a #wasm_tabletype_t to a #wasm_externtype_t + * + * The returned value is owned by the #wasm_tabletype_t argument and should not + * be deleted. + * + * \fn wasm_externtype_t* wasm_globaltype_as_externtype(wasm_globaltype_t *) + * \brief Converts a #wasm_globaltype_t to a #wasm_externtype_t + * + * The returned value is owned by the #wasm_globaltype_t argument and should not + * be deleted. + * + * \fn wasm_externtype_t* wasm_memorytype_as_externtype(wasm_memorytype_t *) + * \brief Converts a #wasm_memorytype_t to a #wasm_externtype_t + * + * The returned value is owned by the #wasm_memorytype_t argument and should not + * be deleted. + * + * \fn const wasm_externtype_t* wasm_functype_as_externtype_const(const wasm_functype_t *) + * \brief Converts a #wasm_functype_t to a #wasm_externtype_t + * + * The returned value is owned by the #wasm_functype_t argument and should not + * be deleted. + * + * \fn const wasm_externtype_t* wasm_tabletype_as_externtype_const(const wasm_tabletype_t *) + * \brief Converts a #wasm_tabletype_t to a #wasm_externtype_t + * + * The returned value is owned by the #wasm_tabletype_t argument and should not + * be deleted. + * + * \fn const wasm_externtype_t* wasm_globaltype_as_externtype_const(const wasm_globaltype_t *) + * \brief Converts a #wasm_globaltype_t to a #wasm_externtype_t + * + * The returned value is owned by the #wasm_globaltype_t argument and should not + * be deleted. + * + * \fn const wasm_externtype_t* wasm_memorytype_as_externtype_const(const wasm_memorytype_t *) + * \brief Converts a #wasm_memorytype_t to a #wasm_externtype_t + * + * The returned value is owned by the #wasm_memorytype_t argument and should not + * be deleted. + * + * \fn wasm_functype_t* wasm_externtype_as_functype(wasm_externtype_t *) + * \brief Attempts to convert a #wasm_externtype_t to a #wasm_functype_t + * + * The returned value is owned by the #wasm_functype_t argument and should not + * be deleted. Returns `NULL` if the provided argument is not a + * #wasm_functype_t. + * + * \fn wasm_tabletype_t* wasm_externtype_as_tabletype(wasm_externtype_t *) + * \brief Attempts to convert a #wasm_externtype_t to a #wasm_tabletype_t + * + * The returned value is owned by the #wasm_tabletype_t argument and should not + * be deleted. Returns `NULL` if the provided argument is not a + * #wasm_tabletype_t. + * + * \fn wasm_memorytype_t* wasm_externtype_as_memorytype(wasm_externtype_t *) + * \brief Attempts to convert a #wasm_externtype_t to a #wasm_memorytype_t + * + * The returned value is owned by the #wasm_memorytype_t argument and should not + * be deleted. Returns `NULL` if the provided argument is not a + * #wasm_memorytype_t. + * + * \fn wasm_globaltype_t* wasm_externtype_as_globaltype(wasm_externtype_t *) + * \brief Attempts to convert a #wasm_externtype_t to a #wasm_globaltype_t + * + * The returned value is owned by the #wasm_globaltype_t argument and should not + * be deleted. Returns `NULL` if the provided argument is not a + * #wasm_globaltype_t. + * + * \fn const wasm_functype_t* wasm_externtype_as_functype_const(const wasm_externtype_t *) + * \brief Attempts to convert a #wasm_externtype_t to a #wasm_functype_t + * + * The returned value is owned by the #wasm_functype_t argument and should not + * be deleted. Returns `NULL` if the provided argument is not a + * #wasm_functype_t. + * + * \fn const wasm_tabletype_t* wasm_externtype_as_tabletype_const(const wasm_externtype_t *) + * \brief Attempts to convert a #wasm_externtype_t to a #wasm_tabletype_t + * + * The returned value is owned by the #wasm_tabletype_t argument and should not + * be deleted. Returns `NULL` if the provided argument is not a + * #wasm_tabletype_t. + * + * \fn const wasm_memorytype_t* wasm_externtype_as_memorytype_const(const wasm_externtype_t *) + * \brief Attempts to convert a #wasm_externtype_t to a #wasm_memorytype_t + * + * The returned value is owned by the #wasm_memorytype_t argument and should not + * be deleted. Returns `NULL` if the provided argument is not a + * #wasm_memorytype_t. + * + * \fn const wasm_globaltype_t* wasm_externtype_as_globaltype_const(const wasm_externtype_t *) + * \brief Attempts to convert a #wasm_externtype_t to a #wasm_globaltype_t + * + * The returned value is owned by the #wasm_globaltype_t argument and should not + * be deleted. Returns `NULL` if the provided argument is not a + * #wasm_globaltype_t. + */ + +/** + * \struct wasm_importtype_t + * \brief An opaque object representing the type of an import. + * + * \typedef wasm_importtype_t + * \brief Convenience alias for #wasm_importtype_t + * + * \struct wasm_importtype_vec_t + * \brief A list of #wasm_importtype_t values. + * + * \var wasm_importtype_vec_t::size + * \brief Length of this vector. + * + * \var wasm_importtype_vec_t::data + * \brief Pointer to the base of this vector + * + * \typedef wasm_importtype_vec_t + * \brief Convenience alias for #wasm_importtype_vec_t + * + * \fn void wasm_importtype_delete(own wasm_importtype_t *); + * \brief Deletes a type. + * + * \fn void wasm_importtype_vec_new_empty(own wasm_importtype_vec_t *out); + * \brief Creates an empty vector. + * + * See #wasm_byte_vec_new_empty for more information. + * + * \fn void wasm_importtype_vec_new_uninitialized(own wasm_importtype_vec_t *out, size_t); + * \brief Creates a vector with the given capacity. + * + * See #wasm_byte_vec_new_uninitialized for more information. + * + * \fn void wasm_importtype_vec_new(own wasm_importtype_vec_t *out, size_t, own wasm_importtype_t *const[]); + * \brief Creates a vector with the provided contents. + * + * See #wasm_byte_vec_new for more information. + * + * \fn void wasm_importtype_vec_copy(own wasm_importtype_vec_t *out, const wasm_importtype_vec_t *) + * \brief Copies one vector to another + * + * See #wasm_byte_vec_copy for more information. + * + * \fn void wasm_importtype_vec_delete(own wasm_importtype_vec_t *out) + * \brief Deallocates import for a vector. + * + * See #wasm_byte_vec_delete for more information. + * + * \fn own wasm_importtype_t* wasm_importtype_copy(wasm_importtype_t *) + * \brief Creates a new value which matches the provided one. + * + * The caller is responsible for deleting the returned value. + * + * \fn own wasm_importtype_t* wasm_importtype_new(wasm_name_t *module, wasm_name_t *name, wasm_externtype_t *) + * \brief Creates a new import type. + * + * This function takes ownership of the `module`, `name`, and + * #wasm_externtype_t arguments. The caller is responsible for deleting the + * returned value. + * + * \fn const wasm_name_t* wasm_importtype_module(const wasm_importtype_t *); + * \brief Returns the module this import is importing from. + * + * The returned memory is owned by the #wasm_importtype_t argument, the caller + * should not deallocate it. + * + * \fn const wasm_name_t* wasm_importtype_name(const wasm_importtype_t *); + * \brief Returns the name this import is importing from. + * + * The returned memory is owned by the #wasm_importtype_t argument, the caller + * should not deallocate it. + * + * \fn const wasm_externtype_t* wasm_importtype_type(const wasm_importtype_t *); + * \brief Returns the type of item this import is importing. + * + * The returned memory is owned by the #wasm_importtype_t argument, the caller + * should not deallocate it. + */ + +/** + * \struct wasm_exporttype_t + * \brief An opaque object representing the type of an export. + * + * \typedef wasm_exporttype_t + * \brief Convenience alias for #wasm_exporttype_t + * + * \struct wasm_exporttype_vec_t + * \brief A list of #wasm_exporttype_t values. + * + * \var wasm_exporttype_vec_t::size + * \brief Length of this vector. + * + * \var wasm_exporttype_vec_t::data + * \brief Pointer to the base of this vector + * + * \typedef wasm_exporttype_vec_t + * \brief Convenience alias for #wasm_exporttype_vec_t + * + * \fn void wasm_exporttype_delete(own wasm_exporttype_t *); + * \brief Deletes a type. + * + * \fn void wasm_exporttype_vec_new_empty(own wasm_exporttype_vec_t *out); + * \brief Creates an empty vector. + * + * See #wasm_byte_vec_new_empty for more information. + * + * \fn void wasm_exporttype_vec_new_uninitialized(own wasm_exporttype_vec_t *out, size_t); + * \brief Creates a vector with the given capacity. + * + * See #wasm_byte_vec_new_uninitialized for more information. + * + * \fn void wasm_exporttype_vec_new(own wasm_exporttype_vec_t *out, size_t, own wasm_exporttype_t *const[]); + * \brief Creates a vector with the provided contents. + * + * See #wasm_byte_vec_new for more information. + * + * \fn void wasm_exporttype_vec_copy(own wasm_exporttype_vec_t *out, const wasm_exporttype_vec_t *) + * \brief Copies one vector to another + * + * See #wasm_byte_vec_copy for more information. + * + * \fn void wasm_exporttype_vec_delete(own wasm_exporttype_vec_t *out) + * \brief Deallocates export for a vector. + * + * See #wasm_byte_vec_delete for more information. + * + * \fn own wasm_exporttype_t* wasm_exporttype_copy(wasm_exporttype_t *) + * \brief Creates a new value which matches the provided one. + * + * The caller is responsible for deleting the returned value. + * + * \fn own wasm_exporttype_t* wasm_exporttype_new(wasm_name_t *name, wasm_externtype_t *) + * \brief Creates a new export type. + * + * This function takes ownership of the `name` and + * #wasm_externtype_t arguments. The caller is responsible for deleting the + * returned value. + * + * \fn const wasm_name_t* wasm_exporttype_name(const wasm_exporttype_t *); + * \brief Returns the name of this export. + * + * The returned memory is owned by the #wasm_exporttype_t argument, the caller + * should not deallocate it. + * + * \fn const wasm_externtype_t* wasm_exporttype_type(const wasm_exporttype_t *); + * \brief Returns the type of this export. + * + * The returned memory is owned by the #wasm_exporttype_t argument, the caller + * should not deallocate it. + */ + +/** + * \struct wasm_val_t + * \brief Representation of a WebAssembly value. + * + * Note that this structure is intended to represent the way to communicate + * values from the embedder to the engine. This type is not actually the + * internal representation in JIT code, for example. + * + * Also note that this is an owned value, notably the `ref` field. The + * #wasm_val_delete function does not delete the memory holding the #wasm_val_t + * itself, but only the memory pointed to by #wasm_val_t. + * + * \var wasm_val_t::kind + * \brief The kind of this value, or which of the fields in the `of` payload + * contains the actual value. + * + * \var wasm_val_t::of + * \brief The actual value of this #wasm_val_t. Only one field of this + * anonymous union is valid, and which field is valid is defined by the `kind` + * field. + * + * \var wasm_val_t::@0::i32 + * \brief value for the `WASM_I32` type + * + * \var wasm_val_t::@0::i64 + * \brief value for the `WASM_I64` type + * + * \var wasm_val_t::@0::f32 + * \brief value for the `WASM_F32` type + * + * \var wasm_val_t::@0::f64 + * \brief value for the `WASM_F64` type + * + * \var wasm_val_t::@0::ref + * \brief Unused by Wasmtime. + * + * \typedef wasm_val_t + * \brief Convenience alias for #wasm_val_t + * + * \struct wasm_val_vec_t + * \brief A list of #wasm_val_t values. + * + * \var wasm_val_vec_t::size + * \brief Length of this vector. + * + * \var wasm_val_vec_t::data + * \brief Pointer to the base of this vector + * + * \typedef wasm_val_vec_t + * \brief Convenience alias for #wasm_val_vec_t + * + * \fn void wasm_val_delete(wasm_val_t *v); + * \brief Deletes a type. + * + * This does not delete the memory pointed to by `v`, so it's safe for `v` to + * reside on the stack. Instead this only deletes the memory referenced by `v`, + * such as the `ref` variant of #wasm_val_t. + * + * \fn void wasm_val_vec_new_empty(own wasm_val_vec_t *out); + * \brief Creates an empty vector. + * + * See #wasm_byte_vec_new_empty for more information. + * + * \fn void wasm_val_vec_new_uninitialized(own wasm_val_vec_t *out, size_t); + * \brief Creates a vector with the given capacity. + * + * See #wasm_byte_vec_new_uninitialized for more information. + * + * \fn void wasm_val_vec_new(own wasm_val_vec_t *out, size_t, own wasm_val_t const[]); + * \brief Creates a vector with the provided contents. + * + * See #wasm_byte_vec_new for more information. + * + * \fn void wasm_val_vec_copy(own wasm_val_vec_t *out, const wasm_val_vec_t *) + * \brief Copies one vector to another + * + * See #wasm_byte_vec_copy for more information. + * + * \fn void wasm_val_vec_delete(own wasm_val_vec_t *out) + * \brief Deallocates export for a vector. + * + * See #wasm_byte_vec_delete for more information. + * + * \fn void wasm_val_copy(wasm_val_t *out, const wasm_val_t *) + * \brief Copies a #wasm_val_t to a new one. + * + * The second argument to this function is copied to the first. The caller is + * responsible for calling #wasm_val_delete on the first argument after this + * function. The `out` parameter is assumed uninitialized by this function and + * the previous contents will not be deallocated. + */ + +/** + * \struct wasm_ref_t + * \brief Unimplemented and used in Wasmtime right now. + * + * \typedef wasm_ref_t + * \brief Convenience alias for #wasm_ref_t + * + * \fn void wasm_ref_delete(own wasm_ref_t *v); + * \brief Deletes a reference. + * + * \fn own wasm_ref_t *wasm_ref_copy(const wasm_ref_t *) + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn bool wasm_ref_same(const wasm_ref_t *, const wasm_ref_t *) + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void* wasm_ref_get_host_info(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, always returns `NULL`. + * + * \fn void wasm_ref_set_host_info(wasm_ref_t *, void *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void wasm_ref_set_host_info_with_finalizer(wasm_ref_t *, void *, void(*)(void*)); + * \brief Unimplemented in Wasmtime, aborts the process if called. + */ + +/** + * \struct wasm_frame_t + * \brief Opaque struct representing a frame of a wasm stack trace. + * + * \typedef wasm_frame_t + * \brief Convenience alias for #wasm_frame_t + * + * \struct wasm_frame_vec_t + * \brief A list of #wasm_frame_t frameues. + * + * \var wasm_frame_vec_t::size + * \brief Length of this vector. + * + * \var wasm_frame_vec_t::data + * \brief Pointer to the base of this vector + * + * \typedef wasm_frame_vec_t + * \brief Convenience alias for #wasm_frame_vec_t + * + * \fn void wasm_frame_delete(own wasm_frame_t *v); + * \brief Deletes a frame. + * + * \fn void wasm_frame_vec_new_empty(own wasm_frame_vec_t *out); + * \brief Creates an empty vector. + * + * See #wasm_byte_vec_new_empty for more information. + * + * \fn void wasm_frame_vec_new_uninitialized(own wasm_frame_vec_t *out, size_t); + * \brief Creates a vector with the given capacity. + * + * See #wasm_byte_vec_new_uninitialized for more information. + * + * \fn void wasm_frame_vec_new(own wasm_frame_vec_t *out, size_t, own wasm_frame_t *const[]); + * \brief Creates a vector with the provided contents. + * + * See #wasm_byte_vec_new for more information. + * + * \fn void wasm_frame_vec_copy(own wasm_frame_vec_t *out, const wasm_frame_vec_t *) + * \brief Copies one vector to another + * + * See #wasm_byte_vec_copy for more information. + * + * \fn void wasm_frame_vec_delete(own wasm_frame_vec_t *out) + * \brief Deallocates export for a vector. + * + * See #wasm_byte_vec_delete for more information. + * + * \fn own wasm_frame_t *wasm_frame_copy(const wasm_frame_t *) + * \brief Copies a #wasm_frame_t to a new one. + * + * The caller is responsible for deleting the returned #wasm_frame_t. + * + * \fn wasm_instance_t *wasm_frame_instance(const wasm_frame_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn uint32_t wasm_frame_func_index(const wasm_frame_t *); + * \brief Returns the function index in the original wasm module that this frame + * corresponds to. + * + * \fn uint32_t wasm_frame_func_offset(const wasm_frame_t *); + * \brief Returns the byte offset from the beginning of the function in the + * original wasm file to the instruction this frame points to. + * + * \fn uint32_t wasm_frame_module_offset(const wasm_frame_t *); + * \brief Returns the byte offset from the beginning of the original wasm file + * to the instruction this frame points to. + */ + +/** + * \struct wasm_trap_t + * \brief Opaque struct representing a wasm trap. + * + * \typedef wasm_trap_t + * \brief Convenience alias for #wasm_trap_t + * + * \fn void wasm_trap_delete(own wasm_trap_t *v); + * \brief Deletes a trap. + * + * \fn own wasm_trap_t *wasm_trap_copy(const wasm_trap_t *) + * \brief Copies a #wasm_trap_t to a new one. + * + * The caller is responsible for deleting the returned #wasm_trap_t. + * + * \fn void wasm_trap_same(const wasm_trap_t *, const wasm_trap_t *) + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void* wasm_trap_get_host_info(const wasm_trap_t *); + * \brief Unimplemented in Wasmtime, always returns `NULL`. + * + * \fn void wasm_trap_set_host_info(wasm_trap_t *, void *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void wasm_trap_set_host_info_with_finalizer(wasm_trap_t *, void *, void(*)(void*)); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_ref_t *wasm_trap_as_ref(wasm_trap_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_trap_t *wasm_ref_as_trap(wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_ref_t *wasm_trap_as_ref_const(const wasm_trap_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_trap_t *wasm_ref_as_trap_const(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_trap_t *wasm_trap_new(wasm_store_t *store, const wasm_message_t *); + * \brief Creates a new #wasm_trap_t with the provided message. + * + * This function will create a new trap within the given #wasm_store_t with the + * provided message. This will also capture the backtrace, if any, of wasm + * frames on the stack. + * + * Note that the #wasm_message_t argument is expected to have a 0-byte at the + * end of the message, and the length should include the trailing 0-byte. + * + * This function does not take ownership of either argument. + * + * The caller is responsible for deallocating the trap returned. + * + * \fn void wasm_trap_message(const wasm_trap_t *, wasm_message_t *out); + * \brief Retrieves the message associated with this trap. + * + * The caller takes ownership of the returned `out` value and is responsible for + * calling #wasm_byte_vec_delete on it. + * + * \fn own wasm_frame_t* wasm_trap_origin(const wasm_trap_t *); + * \brief Returns the top frame of the wasm stack responsible for this trap. + * + * The caller is responsible for deallocating the returned frame. This function + * may return `NULL`, for example, for traps created when there wasn't anything + * on the wasm stack. + * + * \fn void wasm_trap_trace(const wasm_trap_t *, wasm_frame_vec_t *out); + * \brief Returns the trace of wasm frames for this trap. + * + * The caller is responsible for deallocating the returned list of frames. + * Frames are listed in order of increasing depth, with the most recently called + * function at the front of the list and the base function on the stack at the + * end. + */ + +/** + * \struct wasm_foreign_t + * \brief Unimplemented in Wasmtime + * + * \typedef wasm_foreign_t + * \brief Convenience alias for #wasm_foreign_t + * + * \fn void wasm_foreign_delete(own wasm_foreign_t *v); + * \brief Unimplemented in Wasmtime, aborts the process if called + * + * \fn own wasm_foreign_t *wasm_foreign_copy(const wasm_foreign_t *) + * \brief Unimplemented in Wasmtime, aborts the process if called + * + * \fn void wasm_foreign_same(const wasm_foreign_t *, const wasm_foreign_t *) + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void* wasm_foreign_get_host_info(const wasm_foreign_t *); + * \brief Unimplemented in Wasmtime, always returns `NULL`. + * + * \fn void wasm_foreign_set_host_info(wasm_foreign_t *, void *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void wasm_foreign_set_host_info_with_finalizer(wasm_foreign_t *, void *, void(*)(void*)); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_ref_t *wasm_foreign_as_ref(wasm_foreign_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_foreign_t *wasm_ref_as_foreign(wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_ref_t *wasm_foreign_as_ref_const(const wasm_foreign_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_foreign_t *wasm_ref_as_foreign_const(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_foreign_t *wasm_foreign_new(wasm_store_t *store); + * \brief Unimplemented in Wasmtime, aborts the process if called. + */ + +/** + * \struct wasm_module_t + * \brief Opaque struct representing a compiled wasm module. + * + * This structure is safe to send across threads in Wasmtime. + * + * \typedef wasm_module_t + * \brief Convenience alias for #wasm_module_t + * + * \struct wasm_shared_module_t + * \brief Opaque struct representing module that can be sent between threads. + * + * This structure is safe to send across threads in Wasmtime. Note that in + * Wasmtime #wasm_module_t is also safe to share across threads. + * + * \typedef wasm_shared_module_t + * \brief Convenience alias for #wasm_shared_module_t + * + * \fn void wasm_module_delete(own wasm_module_t *v); + * \brief Deletes a module. + * + * \fn own wasm_module_t *wasm_module_copy(const wasm_module_t *) + * \brief Copies a #wasm_module_t to a new one. + * + * The caller is responsible for deleting the returned #wasm_module_t. + * + * \fn void wasm_module_same(const wasm_module_t *, const wasm_module_t *) + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void* wasm_module_get_host_info(const wasm_module_t *); + * \brief Unimplemented in Wasmtime, always returns `NULL`. + * + * \fn void wasm_module_set_host_info(wasm_module_t *, void *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void wasm_module_set_host_info_with_finalizer(wasm_module_t *, void *, void(*)(void*)); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_ref_t *wasm_module_as_ref(wasm_module_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_module_t *wasm_ref_as_module(wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_ref_t *wasm_module_as_ref_const(const wasm_module_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_module_t *wasm_ref_as_module_const(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_ref_as_module_const(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void wasm_shared_module_delete(own wasm_shared_module_t *); + * \brief Deletes the provided module. + * + * \fn own wasm_shared_module_t *wasm_module_share(const wasm_module_t *); + * \brief Creates a shareable module from the provided module. + * + * > Note that this API is not necessary in Wasmtime because #wasm_module_t can + * > be shared across threads. This is implemented for compatibility, however. + * + * This function does not take ownership of the argument, but the caller is + * expected to deallocate the returned #wasm_shared_module_t. + * + * \fn own wasm_module_t *wasm_module_obtain(wasm_store_t *, const wasm_shared_module_t *); + * \brief Attempts to create a #wasm_module_t from the shareable module. + * + * > Note that this API is not necessary in Wasmtime because #wasm_module_t can + * > be shared across threads. This is implemented for compatibility, however. + * + * This function does not take ownership of its arguments, but the caller is + * expected to deallocate the returned #wasm_module_t. + * + * This function may fail if the engines associated with the #wasm_store_t or + * #wasm_shared_module_t are different. + * + * \fn own wasm_module_t *wasm_module_new(wasm_store_t *, const wasm_byte_vec_t *binary) + * \brief Compiles a raw WebAssembly binary to a #wasm_module_t. + * + * This function will validate and compile the provided binary. The returned + * #wasm_module_t is ready for instantiation after this call returns. + * + * This function does not take ownership of its arguments, but the caller is + * expected to deallocate the returned #wasm_module_t. + * + * This function may fail if the provided binary is not a WebAssembly binary or + * if it does not pass validation. In these cases this function returns `NULL`. + * + * > Note: for a richer error message it's recommended to use + * > #wasmtime_module_new. + * + * \fn bool wasm_module_validate(wasm_store_t *, const wasm_byte_vec_t *binary); + * \brief Validates whether a provided byte sequence is a valid wasm binary. + * + * This function will perform any internal validation necessary to determine if + * `binary` is a valid WebAssembly binary according to the configuration of the + * #wasm_store_t provided. + * + * > Note: for a richer error message for invalid binaries you can use + * #wasmtime_module_validate. + * + * \fn void wasm_module_imports(const wasm_module_t *, wasm_importtype_vec_t *out); + * \brief Returns the list of imports that this module expects. + * + * The list of imports returned are the types of items expected to be passed to + * #wasm_instance_new (or #wasmtime_instance_new). You can use + * #wasm_importtype_type to learn about the expected type of each import. + * + * This function does not take ownership of the provided module but ownership of + * `out` is passed to the caller. Note that `out` is treated as uninitialized + * when passed to this function. + * + * \fn void wasm_module_exports(const wasm_module_t *, wasm_exporttype_vec_t *out); + * \brief Returns the list of exports that this module provides. + * + * The list of exports returned are in the same order as the items returned by + * #wasm_instance_exports. + * + * This function does not take ownership of the provided module but ownership + * of `out` is passed to the caller. Note that `out` is treated as + * uninitialized when passed to this function. + * + * \fn void wasm_module_serialize(const wasm_module_t *, wasm_byte_vec_t *out); + * \brief Unimplemented in Wasmtime. + * + * \fn wasm_module_t *wasm_module_deserialize(wasm_store_t *, const wasm_byte_vec_t *); + * \brief Unimplemented in Wasmtime. + */ + +/** + * \struct wasm_func_t + * \brief Opaque struct representing a compiled wasm function. + * + * \typedef wasm_func_t + * \brief Convenience alias for #wasm_func_t + * + * \typedef wasm_func_callback_t + * \brief Type definition for functions passed to #wasm_func_new. + * + * This is the type signature of a host function created with #wasm_func_new. + * This function takes two parameters, the first of which is the list of + * parameters to the function and the second of which is where to write the + * results. This function can optionally return a #wasm_trap_t and does not have + * to fill in the results in that case. + * + * It is guaranteed that this function will be called with the appropriate + * number and types of arguments according to the function type passed to + * #wasm_func_new. It is required that this function produces the correct number + * and types of results as the original type signature. It is undefined behavior + * to return other types or different numbers of values. + * + * This function takes ownership of all of the parameters given. It's expected + * that the caller will invoke `wasm_val_delete` for each one provided. + * Ownership of the results and the trap returned, if any, is passed to the + * caller of this function. + * + * \typedef wasm_func_callback_with_env_t + * \brief Type definition for functions passed to #wasm_func_new_with_env + * + * The semantics of this function are the same as those of + * #wasm_func_callback_t, except the first argument is the same `void*` argument + * passed to #wasm_func_new_with_env. + * + * \fn void wasm_func_delete(own wasm_func_t *v); + * \brief Deletes a func. + * + * \fn own wasm_func_t *wasm_func_copy(const wasm_func_t *) + * \brief Copies a #wasm_func_t to a new one. + * + * The caller is responsible for deleting the returned #wasm_func_t. + * + * \fn void wasm_func_same(const wasm_func_t *, const wasm_func_t *) + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void* wasm_func_get_host_info(const wasm_func_t *); + * \brief Unimplemented in Wasmtime, always returns `NULL`. + * + * \fn void wasm_func_set_host_info(wasm_func_t *, void *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void wasm_func_set_host_info_with_finalizer(wasm_func_t *, void *, void(*)(void*)); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_ref_t *wasm_func_as_ref(wasm_func_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_func_t *wasm_ref_as_func(wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_ref_t *wasm_func_as_ref_const(const wasm_func_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_func_t *wasm_ref_as_func_const(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_ref_as_func_const(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_func_t *wasm_func_new(wasm_store_t *, const wasm_functype_t *, wasm_func_callback_t); + * \brief Creates a new WebAssembly function with host functionality. + * + * This function creates a new #wasm_func_t from a host-provided function. The + * host provided function must implement the type signature matching the + * #wasm_functype_t provided here. + * + * The returned #wasm_func_t is expected to be deleted by the caller. This + * function does not take ownership of its arguments. + * + * \fn wasm_func_t *wasm_func_new_with_env( + * wasm_store_t *, + * const wasm_functype_t *type, + * wasm_func_callback_with_env_t, + * void *env, + * void (*finalizer)(void *)); + * \brief Creates a new WebAssembly function with host functionality. + * + * This function is the same as #wasm_func_new except that it the host-provided + * `env` argument is passed to each invocation of the callback provided. This + * provides a means of attaching host information to this #wasm_func_t. + * + * The `finalizer` argument will be invoked to deallocate `env` when the + * #wasm_func_t is deallocated. If this argument is `NULL` then the data + * provided will not be finalized. + * + * This function only takes ownership of the `env` argument (which is later + * deallocated automatically by calling `finalizer`). This function yields + * ownership of the returned #wasm_func_t to the caller. + * + * \fn wasm_functype_t *wasm_func_type(const wasm_func_t *); + * \brief Returns the type of this function. + * + * The returned #wasm_functype_t is expected to be deallocated by the caller. + * + * \fn size_t wasm_func_param_arity(const wasm_func_t *); + * \brief Returns the number of arguments expected by this function. + * + * \fn size_t wasm_func_result_arity(const wasm_func_t *); + * \brief Returns the number of results returned by this function. + * + * \fn own wasm_trap_t *wasm_func_call(const wasm_func_t *, const wasm_val_t args[], const wasm_val_t results[]); + * \brief Calls the provided function with the arguments given. + * + * This function is used to call WebAssembly from the host. The parameter array + * provided must be valid for #wasm_func_param_arity number of arguments, and + * the result array must be valid for #wasm_func_result_arity number of results. + * Providing not enough space is undefined behavior. + * + * If any of the arguments do not have the correct type then a trap is returned. + * Additionally if any of the arguments come from a different store than + * the #wasm_func_t provided a trap is returned. + * + * When no trap happens and no errors are detected then `NULL` is returned. The + * `results` array is guaranteed to be filled in with values appropriate for + * this function's type signature. + * + * If a trap happens during execution or some other error then a non-`NULL` trap + * is returned. In this situation the `results` are is unmodified. + * + * > Note: to avoid the UB associated with passing the wrong number of results + * > or parameters by accident, or to distinguish between traps and other + * > errors, it's recommended to use #wasmtime_func_call. + */ + +/** + * \struct wasm_global_t + * \brief Opaque struct representing a wasm global. + * + * \typedef wasm_global_t + * \brief Convenience alias for #wasm_global_t + * + * \fn void wasm_global_delete(own wasm_global_t *v); + * \brief Deletes a global. + * + * \fn own wasm_global_t *wasm_global_copy(const wasm_global_t *) + * \brief Copies a #wasm_global_t to a new one. + * + * The caller is responsible for deleting the returned #wasm_global_t. + * + * \fn void wasm_global_same(const wasm_global_t *, const wasm_global_t *) + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void* wasm_global_get_host_info(const wasm_global_t *); + * \brief Unimplemented in Wasmtime, always returns `NULL`. + * + * \fn void wasm_global_set_host_info(wasm_global_t *, void *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void wasm_global_set_host_info_with_finalizer(wasm_global_t *, void *, void(*)(void*)); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_ref_t *wasm_global_as_ref(wasm_global_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_global_t *wasm_ref_as_global(wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_ref_t *wasm_global_as_ref_const(const wasm_global_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_global_t *wasm_ref_as_global_const(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_ref_as_global_const(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_global_t *wasm_global_new(wasm_store_t *, const wasm_globaltype_t *, const wasm_val_t *); + * \brief Creates a new WebAssembly global. + * + * This function is used to create a wasm global from the host, typically to + * provide as the import of a module. The type of the global is specified along + * with the initial value. + * + * This function will return `NULL` on errors. Errors include: + * + * * The type of the global doesn't match the type of the value specified. + * * The initialization value does not come from the provided #wasm_store_t. + * + * > Note: to get richer information on errors it's recommended to call + * > #wasmtime_global_new. + * + * This function does not take ownership of any of its arguments. The caller is + * expected to deallocate the returned value. + * + * \fn wasm_globaltype_t *wasm_global_type(const wasm_global_t *); + * \brief Returns the type of this global. + * + * The caller is expected to deallocate the returned #wasm_globaltype_t. + * + * \fn void wasm_global_get(const wasm_global_t *, wasm_val_t *out); + * \brief Gets the value of this global. + * + * The caller is expected to deallocate the returned #wasm_val_t. The provided + * `out` argument is treated as uninitialized on input. + * + * \fn void wasm_global_set(wasm_global_t *, const wasm_val_t *); + * \brief Sets the value of this global. + * + * This function will set the value of a global to a new value. This function + * does nothing if the global is not mutable, if the #wasm_val_t argument has + * the wrong type, or if the provided value comes from a different store as the + * #wasm_global_t. + * + * > Note: to get an error and detect erroneous cases, it's recommended to call + * > #wasmtime_global_set + * + * This function does not take ownership of its arguments. + */ + +/** + * \struct wasm_table_t + * \brief Opaque struct representing a wasm table. + * + * \typedef wasm_table_t + * \brief Convenience alias for #wasm_table_t + * + * \typedef wasm_table_size_t + * \brief Typedef for indices and sizes of wasm tables. + * + * \fn void wasm_table_delete(own wasm_table_t *v); + * \brief Deletes a table. + * + * \fn own wasm_table_t *wasm_table_copy(const wasm_table_t *) + * \brief Copies a #wasm_table_t to a new one. + * + * The caller is responsible for deleting the returned #wasm_table_t. + * + * \fn void wasm_table_same(const wasm_table_t *, const wasm_table_t *) + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void* wasm_table_get_host_info(const wasm_table_t *); + * \brief Unimplemented in Wasmtime, always returns `NULL`. + * + * \fn void wasm_table_set_host_info(wasm_table_t *, void *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void wasm_table_set_host_info_with_finalizer(wasm_table_t *, void *, void(*)(void*)); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_ref_t *wasm_table_as_ref(wasm_table_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_table_t *wasm_ref_as_table(wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_ref_t *wasm_table_as_ref_const(const wasm_table_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_table_t *wasm_ref_as_table_const(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_ref_as_table_const(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_table_t *wasm_table_new(wasm_store_t *, const wasm_tabletype_t *, wasm_ref_t *init); + * \brief Creates a new WebAssembly table. + * + * Creates a new host-defined table of values. This table has the type provided + * and is filled with the provided initial value (which can be `NULL`). + * + * Returns an error if the #wasm_ref_t does not match the element type of the + * table provided or if it comes from a different store than the one provided. + * + * > Note: for funcref tables you can use #wasmtime_funcref_table_new as well. + * > + * > Additionally the #wasm_ref_t does not have much support in Wasmtime, so you + * > may not be able to create an appropriate initial value. + * + * \fn wasm_tabletype_t *wasm_table_type(const wasm_table_t *); + * \brief Returns the type of this table. + * + * The caller is expected to deallocate the returned #wasm_tabletype_t. + * + * \fn wasm_ref_t *wasm_table_get(const wasm_table_t *, wasm_table_size_t index); + * \brief Gets an element from this table. + * + * Attempts to get a value at an index in this table. This function returns + * `NULL` if the index is out of bounds. + * + * > Note: for funcref tables you can use #wasmtime_funcref_table_get to learn + * > about out-of-bounds errors. + * > + * > Additionally the #wasm_ref_t does not have much + * > support in Wasmtime, so you may not be able to do much with the returned + * > value. + * + * \fn void wasm_table_set(wasm_table_t *, wasm_table_size_t index, wasm_ref_t *); + * \brief Sets an element in this table. + * + * Attempts to set a value at an index in this table. This function does nothing + * in erroneous situations such as: + * + * * The index is out of bounds. + * * The #wasm_ref_t comes from a different store than the table provided. + * * The #wasm_ref_t does not have an appropriate type to store in this table. + * + * > Note: for funcref tables you can use #wasmtime_funcref_table_set to learn + * > about errors. + * > + * > Additionally the #wasm_ref_t does not have much support in Wasmtime, so you + * > may not be able to create an appropriate initial value. + * + * \fn wasm_table_size_t wasm_table_size(const wasm_table_t *); + * \brief Gets the current size, in elements, of this table. + * + * \fn bool wasm_table_grow(wasm_table_t *, wasm_table_size_t delta, wasm_ref_t *init); + * \brief Attempts to grow this table by `delta` elements. + * + * This function will grow the table by `delta` elements, initializing all new + * elements to the `init` value provided. + * + * If growth happens successfully, then `true` is returned. Otherwise `false` is + * returned and indicates one possible form of failure: + * + * * The table's limits do not allow growth by `delta`. + * * The #wasm_ref_t comes from a different store than the table provided. + * * The #wasm_ref_t does not have an appropriate type to store in this table. + * + * > Note: for funcref tables you can use #wasmtime_funcref_table_grow as well. + * > + * > Additionally the #wasm_ref_t does not have much support in Wasmtime, so you + * > may not be able to create an appropriate initial value. + */ + +/** + * \struct wasm_memory_t + * \brief Opaque struct representing a wasm memory. + * + * \typedef wasm_memory_t + * \brief Convenience alias for #wasm_memory_t + * + * \typedef wasm_memory_pages_t + * \brief Unsigned integer to hold the number of pages a memory has. + * + * \fn void wasm_memory_delete(own wasm_memory_t *v); + * \brief Deletes a memory. + * + * \fn own wasm_memory_t *wasm_memory_copy(const wasm_memory_t *) + * \brief Copies a #wasm_memory_t to a new one. + * + * The caller is responsible for deleting the returned #wasm_memory_t. + * + * \fn void wasm_memory_same(const wasm_memory_t *, const wasm_memory_t *) + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void* wasm_memory_get_host_info(const wasm_memory_t *); + * \brief Unimplemented in Wasmtime, always returns `NULL`. + * + * \fn void wasm_memory_set_host_info(wasm_memory_t *, void *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void wasm_memory_set_host_info_with_finalizer(wasm_memory_t *, void *, void(*)(void*)); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_ref_t *wasm_memory_as_ref(wasm_memory_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_memory_t *wasm_ref_as_memory(wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_ref_t *wasm_memory_as_ref_const(const wasm_memory_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_memory_t *wasm_ref_as_memory_const(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_ref_as_memory_const(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_memory_t *wasm_memory_new(wasm_store_t *, const wasm_memorytype_t *); + * \brief Creates a new WebAssembly memory. + * + * \fn wasm_memorytype_t *wasm_memory_type(const wasm_memory_t *); + * \brief Returns the type of this memory. + * + * The caller is expected to deallocate the returned #wasm_memorytype_t. + * + * \fn byte_t *wasm_memory_data(wasm_memory_t *); + * \brief Returns the base address, in memory, where this memory is located. + * + * Note that the returned address may change over time when growth happens. The + * returned pointer is only valid until the memory is next grown (which could + * happen in wasm itself). + * + * \fn size_t wasm_memory_data_size(const wasm_memory_t *); + * \brief Returns the size, in bytes, of this memory. + * + * \fn wasm_memory_pages_t wasm_memory_size(const wasm_memory_t *); + * \brief Returns the size, in wasm pages, of this memory. + * + * \fn bool wasm_memory_grow(wasm_memory_t *, wasm_memory_pages_t delta); + * \brief Attempts to grow this memory by `delta` wasm pages. + * + * This function is similar to the `memory.grow` instruction in wasm itself. It + * will attempt to grow the memory by `delta` wasm pages. If growth fails then + * `false` is returned, otherwise `true` is returned. + */ + +/** + * \struct wasm_extern_t + * \brief Opaque struct representing a wasm external value. + * + * \typedef wasm_extern_t + * \brief Convenience alias for #wasm_extern_t + * + * \struct wasm_extern_vec_t + * \brief A list of #wasm_extern_t values. + * + * \var wasm_extern_vec_t::size + * \brief Length of this vector. + * + * \var wasm_extern_vec_t::data + * \brief Pointer to the base of this vector + * + * \typedef wasm_extern_vec_t + * \brief Convenience alias for #wasm_extern_vec_t + * + * \fn void wasm_extern_delete(own wasm_extern_t *v); + * \brief Deletes a extern. + * + * \fn void wasm_extern_vec_new_empty(own wasm_extern_vec_t *out); + * \brief Creates an empty vector. + * + * See #wasm_byte_vec_new_empty for more information. + * + * \fn void wasm_extern_vec_new_uninitialized(own wasm_extern_vec_t *out, size_t); + * \brief Creates a vector with the given capacity. + * + * See #wasm_byte_vec_new_uninitialized for more information. + * + * \fn void wasm_extern_vec_new(own wasm_extern_vec_t *out, size_t, own wasm_extern_t *const[]); + * \brief Creates a vector with the provided contents. + * + * See #wasm_byte_vec_new for more information. + * + * \fn void wasm_extern_vec_copy(own wasm_extern_vec_t *out, const wasm_extern_vec_t *) + * \brief Copies one vector to another + * + * See #wasm_byte_vec_copy for more information. + * + * \fn void wasm_extern_vec_delete(own wasm_extern_vec_t *out) + * \brief Deallocates import for a vector. + * + * See #wasm_byte_vec_delete for more information. + * + * \fn own wasm_extern_t *wasm_extern_copy(const wasm_extern_t *) + * \brief Copies a #wasm_extern_t to a new one. + * + * The caller is responsible for deleting the returned #wasm_extern_t. + * + * \fn void wasm_extern_same(const wasm_extern_t *, const wasm_extern_t *) + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void* wasm_extern_get_host_info(const wasm_extern_t *); + * \brief Unimplemented in Wasmtime, always returns `NULL`. + * + * \fn void wasm_extern_set_host_info(wasm_extern_t *, void *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void wasm_extern_set_host_info_with_finalizer(wasm_extern_t *, void *, void(*)(void*)); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_ref_t *wasm_extern_as_ref(wasm_extern_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_extern_t *wasm_ref_as_extern(wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_ref_t *wasm_extern_as_ref_const(const wasm_extern_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_extern_t *wasm_ref_as_extern_const(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_ref_as_extern_const(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_externkind_t *wasm_extern_kind(const wasm_extern_t *); + * \brief Returns the kind of this extern, indicating what it will downcast as. + * + * \fn wasm_externtype_t *wasm_extern_type(const wasm_extern_t *); + * \brief Returns the type of this extern. + * + * The caller is expected to deallocate the returned #wasm_externtype_t. + */ + +/** + * \fn wasm_extern_t *wasm_func_as_extern(wasm_func_t *f); + * \brief Converts a #wasm_func_t to #wasm_extern_t. + * + * The returned #wasm_extern_t is owned by the #wasm_func_t argument. Callers + * should not delete the returned value, and it only lives as long as the + * #wasm_func_t argument. + * + * \fn wasm_extern_t *wasm_global_as_extern(wasm_global_t *f); + * \brief Converts a #wasm_global_t to #wasm_extern_t. + * + * The returned #wasm_extern_t is owned by the #wasm_global_t argument. Callers + * should not delete the returned value, and it only lives as long as the + * #wasm_global_t argument. + * + * \fn wasm_extern_t *wasm_memory_as_extern(wasm_memory_t *f); + * \brief Converts a #wasm_memory_t to #wasm_extern_t. + * + * The returned #wasm_extern_t is owned by the #wasm_memory_t argument. Callers + * should not delete the returned value, and it only lives as long as the + * #wasm_memory_t argument. + * + * \fn wasm_extern_t *wasm_table_as_extern(wasm_table_t *f); + * \brief Converts a #wasm_table_t to #wasm_extern_t. + * + * The returned #wasm_extern_t is owned by the #wasm_table_t argument. Callers + * should not delete the returned value, and it only lives as long as the + * #wasm_table_t argument. + * + * \fn const wasm_extern_t *wasm_func_as_extern_const(const wasm_func_t *f); + * \brief Converts a #wasm_func_t to #wasm_extern_t. + * + * The returned #wasm_extern_t is owned by the #wasm_func_t argument. Callers + * should not delete the returned value, and it only lives as long as the + * #wasm_func_t argument. + * + * \fn const wasm_extern_t *wasm_global_as_extern_const(const wasm_global_t *f); + * \brief Converts a #wasm_global_t to #wasm_extern_t. + * + * The returned #wasm_extern_t is owned by the #wasm_global_t argument. Callers + * should not delete the returned value, and it only lives as long as the + * #wasm_global_t argument. + * + * \fn const wasm_extern_t *wasm_memory_as_extern_const(const wasm_memory_t *f); + * \brief Converts a #wasm_memory_t to #wasm_extern_t. + * + * The returned #wasm_extern_t is owned by the #wasm_memory_t argument. Callers + * should not delete the returned value, and it only lives as long as the + * #wasm_memory_t argument. + * + * \fn const wasm_extern_t *wasm_table_as_extern_const(const wasm_table_t *f); + * \brief Converts a #wasm_table_t to #wasm_extern_t. + * + * The returned #wasm_extern_t is owned by the #wasm_table_t argument. Callers + * should not delete the returned value, and it only lives as long as the + * #wasm_table_t argument. + * + * \fn wasm_func_t *wasm_extern_as_func(wasm_extern_t *); + * \brief Converts a #wasm_extern_t to #wasm_func_t. + * + * The returned #wasm_func_t is owned by the #wasm_extern_t argument. Callers + * should not delete the returned value, and it only lives as long as the + * #wasm_extern_t argument. + * + * If the #wasm_extern_t argument isn't a #wasm_func_t then `NULL` is returned. + * + * \fn wasm_table_t *wasm_extern_as_table(wasm_extern_t *); + * \brief Converts a #wasm_extern_t to #wasm_table_t. + * + * The returned #wasm_table_t is owned by the #wasm_extern_t argument. Callers + * should not delete the returned value, and it only lives as long as the + * #wasm_extern_t argument. + * + * If the #wasm_extern_t argument isn't a #wasm_table_t then `NULL` is returned. + * + * \fn wasm_memory_t *wasm_extern_as_memory(wasm_extern_t *); + * \brief Converts a #wasm_extern_t to #wasm_memory_t. + * + * The returned #wasm_memory_t is owned by the #wasm_extern_t argument. Callers + * should not delete the returned value, and it only lives as long as the + * #wasm_extern_t argument. + * + * If the #wasm_extern_t argument isn't a #wasm_memory_t then `NULL` is returned. + * + * \fn wasm_global_t *wasm_extern_as_global(wasm_extern_t *); + * \brief Converts a #wasm_extern_t to #wasm_global_t. + * + * The returned #wasm_global_t is owned by the #wasm_extern_t argument. Callers + * should not delete the returned value, and it only lives as long as the + * #wasm_extern_t argument. + * + * If the #wasm_extern_t argument isn't a #wasm_global_t then `NULL` is returned. + * + * \fn const wasm_func_t *wasm_extern_as_func_const(const wasm_extern_t *); + * \brief Converts a #wasm_extern_t to #wasm_func_t. + * + * The returned #wasm_func_t is owned by the #wasm_extern_t argument. Callers + * should not delete the returned value, and it only lives as long as the + * #wasm_extern_t argument. + * + * If the #wasm_extern_t argument isn't a #wasm_func_t then `NULL` is returned. + * + * \fn const wasm_table_t *wasm_extern_as_table_const(const wasm_extern_t *); + * \brief Converts a #wasm_extern_t to #wasm_table_t. + * + * The returned #wasm_table_t is owned by the #wasm_extern_t argument. Callers + * should not delete the returned value, and it only lives as long as the + * #wasm_extern_t argument. + * + * If the #wasm_extern_t argument isn't a #wasm_table_t then `NULL` is returned. + * + * \fn const wasm_memory_t *wasm_extern_as_memory_const(const wasm_extern_t *); + * \brief Converts a #wasm_extern_t to #wasm_memory_t. + * + * The returned #wasm_memory_t is owned by the #wasm_extern_t argument. Callers + * should not delete the returned value, and it only lives as long as the + * #wasm_extern_t argument. + * + * If the #wasm_extern_t argument isn't a #wasm_memory_t then `NULL` is returned. + * + * \fn const wasm_global_t *wasm_extern_as_global_const(const wasm_extern_t *); + * \brief Converts a #wasm_extern_t to #wasm_global_t. + * + * The returned #wasm_global_t is owned by the #wasm_extern_t argument. Callers + * should not delete the returned value, and it only lives as long as the + * #wasm_extern_t argument. + * + * If the #wasm_extern_t argument isn't a #wasm_global_t then `NULL` is returned. + */ + +/** + * \struct wasm_instance_t + * \brief Opaque struct representing a wasm instance. + * + * \typedef wasm_instance_t + * \brief Convenience alias for #wasm_instance_t + * + * \fn void wasm_instance_delete(own wasm_instance_t *v); + * \brief Deletes a instance. + * + * \fn own wasm_instance_t *wasm_instance_copy(const wasm_instance_t *) + * \brief Copies a #wasm_instance_t to a new one. + * + * The caller is responsible for deleting the returned #wasm_instance_t. + * + * \fn void wasm_instance_same(const wasm_instance_t *, const wasm_instance_t *) + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void* wasm_instance_get_host_info(const wasm_instance_t *); + * \brief Unimplemented in Wasmtime, always returns `NULL`. + * + * \fn void wasm_instance_set_host_info(wasm_instance_t *, void *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn void wasm_instance_set_host_info_with_finalizer(wasm_instance_t *, void *, void(*)(void*)); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_ref_t *wasm_instance_as_ref(wasm_instance_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_instance_t *wasm_ref_as_instance(wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_ref_t *wasm_instance_as_ref_const(const wasm_instance_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn const wasm_instance_t *wasm_ref_as_instance_const(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn wasm_ref_as_instance_const(const wasm_ref_t *); + * \brief Unimplemented in Wasmtime, aborts the process if called. + * + * \fn own wasm_instance_t *wasm_instance_new(wasm_store_t *, const wasm_module_t *, const wasm_extern_t *const[], wasm_trap_t **); + * \brief Instantiates a module with the provided imports. + * + * This function will instantiate the provided #wasm_module_t into the provided + * #wasm_store_t. The `imports` specified are used to satisfy the imports of the + * #wasm_module_t. + * + * This function must provide exactly the same number of imports as returned by + * #wasm_module_imports or this results in undefined behavior. + * + * > Note: to avoid the undefined behavior here related to the number of imports + * > it's recommended to use #wasmtime_instance_new instead. + * + * Imports provided are expected to be 1:1 matches against the list returned by + * #wasm_module_imports. + * + * Instantiation includes invoking the `start` function of a wasm module. If + * that function traps then a trap is returned through the #wasm_trap_t type. + * + * This function does not take ownership of any of its arguments, and the + * returned #wasm_instance_t and #wasm_trap_t are owned by the caller. + * + * \fn void wasm_instance_exports(const wasm_instance_t *, wasm_extern_vec_t *out); + * \brief Returns the exports of an instance. + * + * This function returns a list of #wasm_extern_t values, which will be owned by + * the caller, which are exported from the instance. The `out` list will have + * the same length as #wasm_module_exports called on the original module. Each + * element is 1:1 matched with the elements in the list of #wasm_module_exports. */ diff --git a/crates/c-api/include/wasi.h b/crates/c-api/include/wasi.h index 3a5176925c..92271496c3 100644 --- a/crates/c-api/include/wasi.h +++ b/crates/c-api/include/wasi.h @@ -1,4 +1,8 @@ -// WASI C API +/** + * \file wasi.h + * + * C API for WASI + */ #ifndef WASI_H #define WASI_H @@ -23,33 +27,158 @@ extern "C" { typedef struct wasi_##name##_t wasi_##name##_t; \ WASI_API_EXTERN void wasi_##name##_delete(own wasi_##name##_t*); -// WASI config - +/** + * \typedef wasi_config_t + * \brief Convenience alias for #wasi_config_t + * + * \struct wasi_config_t + * \brief Opaque type used to create a #wasi_instance_t. + * + * \fn void wasi_config_delete(own wasi_config_t *); + * \brief Deletes a configuration object. + */ WASI_DECLARE_OWN(config) +/** + * \brief Creates a new empty configuration object. + * + * The caller is expected to deallocate the returned configuration + */ WASI_API_EXTERN own wasi_config_t* wasi_config_new(); +/** + * \brief Sets the argv list for this configuration object. + * + * By default WASI programs have an empty argv list, but this can be used to + * explicitly specify what the argv list for the program is. + * + * The arguments are copied into the `config` object as part of this function + * call, so the `argv` pointer only needs to stay alive for this function call. + */ WASI_API_EXTERN void wasi_config_set_argv(wasi_config_t* config, int argc, const char* argv[]); + +/** + * \brief Indicates that the argv list should be inherited from this process's + * argv list. + */ WASI_API_EXTERN void wasi_config_inherit_argv(wasi_config_t* config); +/** + * \brief Sets the list of environment variables available to the WASI instance. + * + * By default WASI programs have a blank environment, but this can be used to + * define some environment variables for them. + * + * It is required that the `names` and `values` lists both have `envc` entries. + * + * The env vars are copied into the `config` object as part of this function + * call, so the `names` and `values` pointers only need to stay alive for this + * function call. + */ WASI_API_EXTERN void wasi_config_set_env(wasi_config_t* config, int envc, const char* names[], const char* values[]); + +/** + * \brief Indicates that the entire environment of the calling process should be + * inherited by this WASI configuration. + */ WASI_API_EXTERN void wasi_config_inherit_env(wasi_config_t* config); +/** + * \brief Configures standard input to be taken from the specified file. + * + * By default WASI programs have no stdin, but this configures the specified + * file to be used as stdin for this configuration. + * + * If the stdin location does not exist or it cannot be opened for reading then + * `false` is returned. Otherwise `true` is returned. + */ WASI_API_EXTERN bool wasi_config_set_stdin_file(wasi_config_t* config, const char* path); + +/** + * \brief Configures this process's own stdin stream to be used as stdin for + * this WASI configuration. + */ WASI_API_EXTERN void wasi_config_inherit_stdin(wasi_config_t* config); +/** + * \brief Configures standard output to be written to the specified file. + * + * By default WASI programs have no stdout, but this configures the specified + * file to be used as stdout. + * + * If the stdout location could not be opened for writing then `false` is + * returned. Otherwise `true` is returned. + */ WASI_API_EXTERN bool wasi_config_set_stdout_file(wasi_config_t* config, const char* path); + +/** + * \brief Configures this process's own stdout stream to be used as stdout for + * this WASI configuration. + */ WASI_API_EXTERN void wasi_config_inherit_stdout(wasi_config_t* config); +/** + * \brief Configures standard output to be written to the specified file. + * + * By default WASI programs have no stderr, but this configures the specified + * file to be used as stderr. + * + * If the stderr location could not be opened for writing then `false` is + * returned. Otherwise `true` is returned. + */ WASI_API_EXTERN bool wasi_config_set_stderr_file(wasi_config_t* config, const char* path); + +/** + * \brief Configures this process's own stderr stream to be used as stderr for + * this WASI configuration. + */ WASI_API_EXTERN void wasi_config_inherit_stderr(wasi_config_t* config); +/** + * \brief Configures a "preopened directory" to be available to WASI APIs. + * + * By default WASI programs do not have access to anything on the filesystem. + * This API can be used to grant WASI programs access to a directory on the + * filesystem, but only that directory (its whole contents but nothing above it). + * + * The `path` argument here is a path name on the host filesystem, and + * `guest_path` is the name by which it will be known in wasm. + */ WASI_API_EXTERN bool wasi_config_preopen_dir(wasi_config_t* config, const char* path, const char* guest_path); -// WASI instance - +/** + * \typedef wasi_instance_t + * \brief Convenience alias for #wasi_instance_t + * + * \struct wasi_instance_t + * \brief Opaque type representing a WASI instance. + * + * \fn void wasi_instance_delete(own wasi_instance_t *); + * \brief Deletes an instance object. + */ WASI_DECLARE_OWN(instance) +/** + * \brief Creates a new WASI instance from the specified configuration. + * + * \param store the store which functions will be attached to + * \param name the WASI module name that is being instantiated, currently either + * `wasi_unstable` or `wasi_snapshot_preview`. + * \param config the configuration object which has settings for how WASI APIs + * will behave. + * \param trap a location, if `NULL` is returned, that contains information + * about why instantiation failed. + * + * \return a #wasi_instance_t owned by the caller on success or `NULL` on + * failure. + * + * Note that this function takes ownership of the `config` argument whether this + * function succeeds or not. Ownership of the #wasi_instance_t and #wasm_trap_t + * are transferred to the caller. + * + * With a #wasi_instance_t you'll likely call either + * #wasmtime_linker_define_wasi or #wasi_instance_bind_import afterwards. + */ WASI_API_EXTERN own wasi_instance_t* wasi_instance_new( wasm_store_t* store, const char* name, @@ -57,6 +186,19 @@ WASI_API_EXTERN own wasi_instance_t* wasi_instance_new( own wasm_trap_t** trap ); +/** + * \brief Extracts a matching item for the given import from a #wasi_instance_t. + * + * \param instance the WASI instance an export is extracted from + * \param import the desired import type that is being extracted, typically + * acquired from #wasm_module_imports. + * + * \return a #wasm_extern_t which can be used to satisfy the `import` + * requested, or `NULL` if the provided `instance` cannot satisfy `import`. + * + * This function does not take ownership of its arguments, and the lifetime of + * the #wasm_extern_t is tied to the #wasi_instance_t argument. + */ WASI_API_EXTERN const wasm_extern_t* wasi_instance_bind_import( const wasi_instance_t* instance, const wasm_importtype_t* import @@ -68,4 +210,4 @@ WASI_API_EXTERN const wasm_extern_t* wasi_instance_bind_import( } // extern "C" #endif -#endif // #ifdef WASI_H \ No newline at end of file +#endif // #ifdef WASI_H diff --git a/crates/c-api/include/wasmtime.h b/crates/c-api/include/wasmtime.h index 43a760b7a6..47820938a9 100644 --- a/crates/c-api/include/wasmtime.h +++ b/crates/c-api/include/wasmtime.h @@ -27,11 +27,18 @@ extern "C" { WASM_API_EXTERN void wasmtime_##name##_delete(own wasmtime_##name##_t*); /** + * \typedef wasmtime_error_t + * \brief Convenience alias for #wasmtime_error_t + * + * \struct wasmtime_error_t * \brief Errors generated by Wasmtime. * * This opaque type represents an error that happened as part of one of the * functions below. Errors primarily have an error message associated with them * at this time, which you can acquire by calling #wasmtime_error_message. + * + * \fn void wasmtime_error_delete(own wasmtime_error_t *); + * \brief Deletes an error. */ WASMTIME_DECLARE_OWN(error) @@ -48,74 +55,303 @@ WASM_API_EXTERN void wasmtime_error_message( own wasm_name_t *message ); +/** + * \brief Specifier for how Wasmtime will compile code, values are in + * #wasmtime_strategy_enum + */ typedef uint8_t wasmtime_strategy_t; + +/** + * \brief Different ways that Wasmtime can compile WebAssembly + * + * The default value is #WASMTIME_STRATEGY_AUTO. + */ enum wasmtime_strategy_enum { // Strategy + /// Wasmtime will automatically determine whether to use Cranelift or + /// Lightbeam, and currently it will always pick Cranelift. This default may + /// change over time though. WASMTIME_STRATEGY_AUTO, + + /// Indicates that Cranelift will unconditionally use Cranelift to compile + /// WebAssembly code. WASMTIME_STRATEGY_CRANELIFT, + + /// Indicates that Cranelift will unconditionally use Lightbeam to compile + /// WebAssembly code. Note that Lightbeam isn't always enabled at compile + /// time, and if that's the case an error will be returned. WASMTIME_STRATEGY_LIGHTBEAM, }; +/** + * \brief Specifier of what optimization level to use for generated JIT code. + * + * See #wasmtime_opt_level_enum for possible values. + */ typedef uint8_t wasmtime_opt_level_t; + +/** + * \brief Different ways Wasmtime can optimize generated code. + * + * The default value is #WASMTIME_OPT_LEVEL_SPEED. + */ enum wasmtime_opt_level_enum { // OptLevel + /// Generated code will not be optimized at all. WASMTIME_OPT_LEVEL_NONE, + /// Generated code will be optimized purely for speed. WASMTIME_OPT_LEVEL_SPEED, + /// Generated code will be optimized, but some speed optimizations are + /// disabled if they cause the generated code to be significantly larger. WASMTIME_OPT_LEVEL_SPEED_AND_SIZE, }; +/** + * \brief Different ways wasmtime can enable profiling JIT code. + * + * See #wasmtime_profiling_strategy_enum for possible values. + */ typedef uint8_t wasmtime_profiling_strategy_t; + +/** + * \brief Different ways to profile JIT code. + * + * The default is #WASMTIME_PROFILING_STRATEGY_NONE. + */ enum wasmtime_profiling_strategy_enum { // ProfilingStrategy + /// No profiling is enabled at runtime. WASMTIME_PROFILING_STRATEGY_NONE, + /// Linux's "jitdump" support in `perf` is enabled and when Wasmtime is run + /// under `perf` necessary calls will be made to profile generated JIT code. WASMTIME_PROFILING_STRATEGY_JITDUMP, + /// Support for VTune will be enabled and the VTune runtime will be informed, + /// at runtime, about JIT code. + /// + /// Note that this isn't always enabled at build time. WASMTIME_PROFILING_STRATEGY_VTUNE, }; #define WASMTIME_CONFIG_PROP(ret, name, ty) \ WASM_API_EXTERN ret wasmtime_config_##name##_set(wasm_config_t*, ty); +/** + * \brief Configures whether DWARF debug information is constructed at runtime + * to describe JIT code. + * + * This setting is `false` by default. When enabled it will attempt to inform + * native debuggers about DWARF debugging information for JIT code to more + * easily debug compiled WebAssembly via native debuggers. This can also + * sometimes improve the quality of output when profiling is enabled. + */ WASMTIME_CONFIG_PROP(void, debug_info, bool) + +/** + * \brief Enables WebAssembly code to be interrupted. + * + * This setting is `false` by default. When enabled it will enable getting an + * interrupt handle via #wasmtime_interrupt_handle_new which can be used to + * interrupt currently-executing WebAssembly code. + */ WASMTIME_CONFIG_PROP(void, interruptable, bool) + +/** + * \brief Configures the maximum stack size, in bytes, that JIT code can use. + * + * This setting is 2MB by default. Configuring this setting will limit the + * amount of native stack space that JIT code can use while it is executing. If + * you're hitting stack overflow you can try making this setting larger, or if + * you'd like to limit wasm programs to less stack you can also configure this. + * + * Note that this setting is not interpreted with 100% precision. Additionally + * the amount of stack space that wasm takes is always relative to the first + * invocation of wasm on the stack, so recursive calls with host frames in the + * middle will all need to fit within this setting. + */ WASMTIME_CONFIG_PROP(void, max_wasm_stack, size_t) + +/** + * \brief Configures whether the WebAssembly threading proposal is enabled. + * + * This setting is `false` by default. + * + * Note that threads are largely unimplemented in Wasmtime at this time. + */ WASMTIME_CONFIG_PROP(void, wasm_threads, bool) + +/** + * \brief Configures whether the WebAssembly reference types proposal is + * enabled. + * + * This setting is `false` by default. + */ WASMTIME_CONFIG_PROP(void, wasm_reference_types, bool) + +/** + * \brief Configures whether the WebAssembly SIMD proposal is + * enabled. + * + * This setting is `false` by default. + */ WASMTIME_CONFIG_PROP(void, wasm_simd, bool) + +/** + * \brief Configures whether the WebAssembly bulk memory proposal is + * enabled. + * + * This setting is `false` by default. + */ WASMTIME_CONFIG_PROP(void, wasm_bulk_memory, bool) + +/** + * \brief Configures whether the WebAssembly multi value proposal is + * enabled. + * + * This setting is `true` by default. + */ WASMTIME_CONFIG_PROP(void, wasm_multi_value, bool) + +/** + * \brief Configures how JIT code will be compiled. + * + * This setting is #WASMTIME_STRATEGY_AUTO by default. + * + * If the compilation strategy selected could not be enabled then an error is + * returned. + */ WASMTIME_CONFIG_PROP(wasmtime_error_t*, strategy, wasmtime_strategy_t) + +/** + * \brief Configures whether Cranelift's debug verifier is enabled. + * + * This setting in `false` by default. + * + * When cranelift is used for compilation this enables expensive debug checks + * within Cranelift itself to verify it's correct. + */ WASMTIME_CONFIG_PROP(void, cranelift_debug_verifier, bool) + +/** + * \brief Configures Cranelift's optimization level for JIT code. + * + * This setting in #WASMTIME_OPT_LEVEL_SPEED by default. + */ WASMTIME_CONFIG_PROP(void, cranelift_opt_level, wasmtime_opt_level_t) + +/** + * \brief Configures the profiling strategy used for JIT code. + * + * This setting in #WASMTIME_PROFILING_STRATEGY_NONE by default. + */ WASMTIME_CONFIG_PROP(wasmtime_error_t*, profiler, wasmtime_profiling_strategy_t) + +/** + * \brief Configures the maximum size for memory to be considered "static" + * + * For more information see the Rust documentation at + * https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Config.html#method.static_memory_maximum_size. + */ WASMTIME_CONFIG_PROP(void, static_memory_maximum_size, uint64_t) + +/** + * \brief Configures the guard region size for "static" memory. + * + * For more information see the Rust documentation at + * https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Config.html#method.static_memory_guard_size. + */ WASMTIME_CONFIG_PROP(void, static_memory_guard_size, uint64_t) + +/** + * \brief Configures the guard region size for "dynamic" memory. + * + * For more information see the Rust documentation at + * https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Config.html#method.dynamic_memory_guard_size. + */ WASMTIME_CONFIG_PROP(void, dynamic_memory_guard_size, uint64_t) +/** + * \brief Enables Wasmtime's cache and loads configuration from the specified + * path. + * + * By default the Wasmtime compilation cache is disabled. The configuration path + * here can be `NULL` to use the default settings, and otherwise the argument + * here must be a file on the filesystem with TOML configuration - + * https://bytecodealliance.github.io/wasmtime/cli-cache.html. + * + * An error is returned if the cache configuration could not be loaded or if the + * cache could not be enabled. + */ WASM_API_EXTERN wasmtime_error_t* wasmtime_config_cache_config_load(wasm_config_t*, const char*); -/////////////////////////////////////////////////////////////////////////////// - -// Converts from the text format of WebAssembly to to the binary format. -// -// * `wat` - this it the input buffer with the WebAssembly Text Format inside of -// it. This will be parsed and converted to the binary format. -// * `ret` - if the conversion is successful, this byte vector is filled in with -// the WebAssembly binary format. -// -// Returns a non-null error if parsing fails, or returns `NULL`. If parsing -// fails then `ret` isn't touched. +/** + * \brief Converts from the text format of WebAssembly to to the binary format. + * + * \param wat this it the input buffer with the WebAssembly Text Format inside of + * it. This will be parsed and converted to the binary format. + * \param ret if the conversion is successful, this byte vector is filled in with + * the WebAssembly binary format. + * + * \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 `wat`, and the caller is expected to + * deallocate the returned #wasmtime_error_t and #wasm_byte_vec_t. + */ WASM_API_EXTERN own wasmtime_error_t* wasmtime_wat2wasm( const wasm_byte_vec_t *wat, own wasm_byte_vec_t *ret ); -/////////////////////////////////////////////////////////////////////////////// -// -// wasmtime_linker_t extension type, binding the `Linker` type in the Rust API - +/** + * \typedef wasmtime_linker_t + * \brief Convenience alias for #wasmtime_linker_t + * + * \struct wasmtime_linker_t + * \brief Object used to conveniently link together and instantiate wasm + * modules. + * + * This type corresponds to the `wasmtime::Linker` type in Rust. This + * Wasmtime-specific extension 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. + * + * \fn void wasmtime_linker_delete(own wasmtime_linker_t *); + * \brief Deletes a linker. + */ WASMTIME_DECLARE_OWN(linker) +/** + * \brief Creates a new linker which will link together objects in the specified + * store. + * + * This function does not take ownership of the store argument, and the caller + * is expected to delete the returned linker. + */ WASM_API_EXTERN own wasmtime_linker_t* wasmtime_linker_new(wasm_store_t* store); +/** + * \brief Configures whether this linker allows later definitions to shadow + * previous definitions. + * + * By default this setting is `false`. + */ WASM_API_EXTERN void wasmtime_linker_allow_shadowing(wasmtime_linker_t* linker, bool allow_shadowing); +/** + * \brief Defines 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 name the field name the item is defined under + * \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). + */ WASM_API_EXTERN own wasmtime_error_t* wasmtime_linker_define( wasmtime_linker_t *linker, const wasm_name_t *module, @@ -123,17 +359,67 @@ WASM_API_EXTERN own wasmtime_error_t* wasmtime_linker_define( const wasm_extern_t *item ); +/** + * \brief Defines a WASI instance in this linker. + * + * \param linker the linker the name is being defined in. + * \param instance a previously-created WASI instance. + * + * \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). + */ WASM_API_EXTERN own wasmtime_error_t* wasmtime_linker_define_wasi( wasmtime_linker_t *linker, const wasi_instance_t *instance ); +/** + * \brief Defines an instance under the specified name in this linker. + * + * \param linker the linker the name is being defined in. + * \param name the module name to define `instance` under. + * \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). + */ WASM_API_EXTERN own wasmtime_error_t* wasmtime_linker_define_instance( wasmtime_linker_t *linker, const wasm_name_t *name, const wasm_instance_t *instance ); +/** + * \brief Instantiates a #wasm_module_t with the items defined in this linker. + * + * \param linker the linker used to instantiate the provided module. + * \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). + */ WASM_API_EXTERN own wasmtime_error_t* wasmtime_linker_instantiate( const wasmtime_linker_t *linker, const wasm_module_t *module, @@ -141,18 +427,59 @@ WASM_API_EXTERN own wasmtime_error_t* wasmtime_linker_instantiate( own wasm_trap_t **trap ); +/** + * \brief Defines automatic instantiations of a #wasm_module_t in this linker. + * + * \param linker the linker the module is being added to + * \param name the name of the module within the linker + * \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). + */ WASM_API_EXTERN own wasmtime_error_t* wasmtime_linker_module( const wasmtime_linker_t *linker, const wasm_name_t *name, const wasm_module_t *module ); +/** + * \brief Acquires the "default export" of the named module in this linker. + * + * \param linker the linker to load from + * \param name the name of the module to get the default export for + * \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). + */ WASM_API_EXTERN own wasmtime_error_t* wasmtime_linker_get_default( const wasmtime_linker_t *linker, const wasm_name_t *name, own wasm_func_t **func ); +/** + * \brief Loads an item by name from this linker. + * + * \param linker the linker to load from + * \param module the name of the module to get + * \param name the name of the field to get + * \param item where to store the extracted item + * + * \return An error is returned if the item isn't defined or has more than one + * definition, or `NULL` is returned and `item` is filled in otherwise. + */ WASM_API_EXTERN own wasmtime_error_t* wasmtime_linker_get_one_by_name( const wasmtime_linker_t *linker, const wasm_name_t *module, @@ -160,17 +487,55 @@ WASM_API_EXTERN own wasmtime_error_t* wasmtime_linker_get_one_by_name( own wasm_extern_t **item ); -/////////////////////////////////////////////////////////////////////////////// -// -// wasmtime_caller_t extension, binding the `Caller` type in the Rust API - +/** + * \brief Structure used to learn about the caller of a host-defined function. + * + * This structure is the first argument of #wasmtime_func_callback_t and + * wasmtime_func_callback_with_env_t. The main purpose of this structure is for + * building a WASI-like API which can inspect the memory of the caller, + * regardless of the caller. + * + * This is intended to be a temporary API extension until interface types have + * become more prevalent. This is not intended to be supported until the end of + * time, but it will be supported so long as WASI requires it. + */ typedef struct wasmtime_caller_t wasmtime_caller_t; +/** + * \brief Callback signature for #wasmtime_func_new. + * + * This function is the same as #wasm_func_callback_t except that its first + * argument is a #wasmtime_caller_t which allows learning information about the + * caller. + */ typedef own wasm_trap_t* (*wasmtime_func_callback_t)(const wasmtime_caller_t* caller, const wasm_val_t args[], wasm_val_t results[]); + +/** + * \brief Callback signature for #wasmtime_func_new_with_env. + * + * This function is the same as #wasm_func_callback_with_env_t except that its + * first argument is a #wasmtime_caller_t which allows learning information + * about the + * caller. + */ typedef own wasm_trap_t* (*wasmtime_func_callback_with_env_t)(const wasmtime_caller_t* caller, void* env, const wasm_val_t args[], wasm_val_t results[]); +/** + * \brief Creates a new host-defined function. + * + * This function is the same as #wasm_func_new, except the callback has the type + * signature #wasmtime_func_callback_t which gives a #wasmtime_caller_t as its + * first argument. + */ WASM_API_EXTERN own wasm_func_t* wasmtime_func_new(wasm_store_t*, const wasm_functype_t*, wasmtime_func_callback_t callback); +/** + * \brief Creates a new host-defined function. + * + * This function is the same as #wasm_func_new_with_env, except the callback + * has the type signature #wasmtime_func_callback_with_env_t which gives a + * #wasmtime_caller_t as its first argument. + */ WASM_API_EXTERN own wasm_func_t* wasmtime_func_new_with_env( wasm_store_t* store, const wasm_functype_t* type, @@ -179,68 +544,114 @@ WASM_API_EXTERN own wasm_func_t* wasmtime_func_new_with_env( void (*finalizer)(void*) ); +/** + * \brief Loads a #wasm_extern_t from the caller's context + * + * This function will attempt to look up the export named `name` on the caller + * instance provided. If it is found then the #wasm_extern_t for that is + * returned, otherwise `NULL` is returned. + * + * Note that this only works for exported memories right now for WASI + * compatibility. + */ WASM_API_EXTERN own wasm_extern_t* wasmtime_caller_export_get(const wasmtime_caller_t* caller, const wasm_name_t* name); -/////////////////////////////////////////////////////////////////////////////// -// -// wasmtime_interrupt_handle_t extension, allowing interruption of running wasm -// modules. -// -// Note that `wasmtime_interrupt_handle_t` is safe to send to other threads and -// interrupt/delete. -// -// Also note that `wasmtime_interrupt_handle_new` may return NULL if interrupts -// are not enabled in `wasm_config_t`. - +/** + * \typedef wasmtime_interrupt_handle_t + * \brief Convenience alias for #wasmtime_interrupt_handle_t + * + * \struct wasmtime_interrupt_handle_t + * \brief A handle used to interrupt executing WebAssembly code. + * + * This structure is an opaque handle that represents a handle to a store. This + * handle can be used to remotely (from another thread) interrupt currently + * executing WebAssembly code. + * + * This structure is safe to share from multiple threads. + * + * \fn void wasmtime_interrupt_handle_delete(own wasmtime_interrupt_handle_t *); + * \brief Deletes an interrupt handle. + */ WASMTIME_DECLARE_OWN(interrupt_handle) +/** + * \brief Creates a new interrupt handle to interrupt executing WebAssembly from + * the provided store. + * + * There are a number of caveats about how interrupt is handled in Wasmtime. For + * more information see the [Rust + * documentation](https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Store.html#method.interrupt_handle). + * + * This function returns `NULL` if the store's configuration does not have + * interrupts enabled. See #wasmtime_config_interruptable_set. + */ WASM_API_EXTERN own wasmtime_interrupt_handle_t *wasmtime_interrupt_handle_new(wasm_store_t *store); +/** + * \brief Requests that WebAssembly code running in the store attached to this + * interrupt handle is interrupted. + * + * For more information about interrupts see #wasmtime_interrupt_handle_new. + * + * Note that this is safe to call from any thread. + */ WASM_API_EXTERN void wasmtime_interrupt_handle_interrupt(wasmtime_interrupt_handle_t *handle); -/////////////////////////////////////////////////////////////////////////////// -// -// Extensions to `wasm_trap_t` - -// Returns `true` if the trap is a WASI "exit" trap and has a return status. If -// `true` is returned then the exit status is returned through the `status` -// pointer. If `false` is returned then this is not a wasi exit trap. +/** + * \brief Attempts to extract a WASI-specific exit status from this trap. + * + * Returns `true` if the trap is a WASI "exit" trap and has a return status. If + * `true` is returned then the exit status is returned through the `status` + * pointer. If `false` is returned then this is not a wasi exit trap. + */ WASM_API_EXTERN bool wasmtime_trap_exit_status(const wasm_trap_t*, int *status); -/////////////////////////////////////////////////////////////////////////////// -// -// Extensions to `wasm_frame_t` - +/** + * \brief Returns a human-readable name for this frame's function. + * + * This function will attempt to load a human-readable name for function this + * frame points to. This function may return `NULL`. + * + * The lifetime of the returned name is the same as the #wasm_frame_t itself. + */ WASM_API_EXTERN const wasm_name_t *wasmtime_frame_func_name(const wasm_frame_t*); + +/** + * \brief Returns a human-readable name for this frame's module. + * + * This function will attempt to load a human-readable name for module this + * frame points to. This function may return `NULL`. + * + * The lifetime of the returned name is the same as the #wasm_frame_t itself. + */ WASM_API_EXTERN const wasm_name_t *wasmtime_frame_module_name(const wasm_frame_t*); -/////////////////////////////////////////////////////////////////////////////// -// -// Extensions to the C API which augment existing functionality with extra -// error reporting, safety, etc. - -// Similar to `wasm_func_call`, but with a few tweaks: -// -// * `args` and `results` have a size parameter saying how big the arrays are -// * An error *and* a trap can be returned -// * Errors are returned if `args` have the wrong types, if the args/results -// arrays have the wrong lengths, or if values come from the wrong store. -// -// The 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 (e.g. the -// size of the args/results were wrong) -// 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 worked 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. +/** + * \brief Call a WebAssembly function. + * + * This function is similar to #wasm_func_call, but with a few tweaks: + * + * * `args` and `results` have a size parameter saying how big the arrays are + * * An error *and* a trap can be returned + * * Errors are returned if `args` have the wrong types, if the args/results + * arrays have the wrong lengths, or if values come from the wrong store. + * + * The 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 (e.g. the + * size of the args/results were wrong) + * 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 worked 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. + */ WASM_API_EXTERN own wasmtime_error_t *wasmtime_func_call( wasm_func_t *func, const wasm_val_t *args, @@ -250,12 +661,19 @@ WASM_API_EXTERN own wasmtime_error_t *wasmtime_func_call( own wasm_trap_t **trap ); -// Similar to `wasm_global_new`, but with a few tweaks: -// -// * An error is returned instead of `wasm_global_t`, which is taken as an -// out-parameter -// * An error happens when the `type` specified does not match the type of the -// value `val`, or if it comes from a different store than `store`. +/** + * \brief Creates a new global value. + * + * Similar to #wasm_global_new, but with a few tweaks: + * + * * An error is returned instead of #wasm_global_t, which is taken as an + * out-parameter + * * An error happens when the `type` specified does not match the type of the + * value `val`, or if it comes from a different store than `store`. + * + * This function does not take ownership of any of its arguments but returned + * values are owned by the caller. + */ WASM_API_EXTERN own wasmtime_error_t *wasmtime_global_new( wasm_store_t *store, const wasm_globaltype_t *type, @@ -263,26 +681,38 @@ WASM_API_EXTERN own wasmtime_error_t *wasmtime_global_new( own wasm_global_t **ret ); -// Similar to `wasm_global_set`, but with an error that can be returned if the -// specified value does not come from the same store as this global, if the -// global is immutable, or if the specified value has the wrong type. +/** + * \brief Sets a global to a new value. + * + * This function is the same as #wasm_global_set, except in the case of an error + * a #wasmtime_error_t is returned. + */ WASM_API_EXTERN own wasmtime_error_t *wasmtime_global_set( wasm_global_t *global, const wasm_val_t *val ); -// Similar to `wasm_instance_new`, but with tweaks: -// -// * An error message can be returned from this function. -// * The number of imports specified is passed as an argument -// * The `trap` pointer is required to not be NULL. -// * No `wasm_store_t` argument is required. -// -// 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). +/** + * \brief Wasmtime-specific function to instantiate a module. + * + * This function is similar to #wasm_instance_new, but with a few tweaks: + * + * * An error message can be returned from this function. + * * The number of imports specified is passed as an argument + * * The `trap` pointer is required to not be NULL. + * + * 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). + * + * This function does not take ownership of any of its arguments, but all return + * values are owned by the caller. + * + * See #wasm_instance_new for information about how to fill in the `imports` + * array. + */ WASM_API_EXTERN own wasmtime_error_t *wasmtime_instance_new( wasm_store_t *store, const wasm_module_t *module, @@ -292,40 +722,110 @@ WASM_API_EXTERN own wasmtime_error_t *wasmtime_instance_new( own wasm_trap_t **trap ); -// Similar to `wasm_module_new`, but an error is returned to return a -// descriptive error message in case compilation fails. +/** + * \brief Wasmtime-specific function to compile a module. + * + * 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 any of its arguments, but the + * returned error and module are owned by the caller. + */ WASM_API_EXTERN own wasmtime_error_t *wasmtime_module_new( wasm_store_t *store, const wasm_byte_vec_t *binary, own wasm_module_t **ret ); -// Similar to `wasm_module_validate`, but an error is returned to return a -// descriptive error message in case compilation fails. +/** + * \brief Wasmtime-specific function to validate a module. + * + * This function will validate the provided byte sequence to determine if it is + * a valid WebAssembly binary. This function performs the same as + * #wasm_module_validate except that it returns a #wasmtime_error_t which + * contains an error message if validation fails. + * + * 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. + */ WASM_API_EXTERN own wasmtime_error_t *wasmtime_module_validate( wasm_store_t *store, const wasm_byte_vec_t *binary ); -// Similar to `wasm_table_*`, except these explicitly operate on funcref tables -// and work with `wasm_func_t` values instead of `wasm_ref_t`. +/** + * \brief Creates a new host-defined wasm table. + * + * This function is the same as #wasm_table_new except that it's specialized for + * funcref tables by taking a `wasm_func_t` initialization value. Additionally + * it returns errors via #wasmtime_error_t. + * + * This function does not take ownership of any of its parameters, but yields + * ownership of returned values (the table and error). + */ WASM_API_EXTERN own wasmtime_error_t *wasmtime_funcref_table_new( wasm_store_t *store, const wasm_tabletype_t *element_ty, wasm_func_t *init, own wasm_table_t **table ); + +/** + * \brief Gets a value in a table. + * + * This function is the same as #wasm_table_get except that it's specialized for + * funcref tables by returning a `wasm_func_t` value. Additionally a `bool` + * return value indicates whether the `index` provided was in bounds. + * + * This function does not take ownership of any of its parameters, but yields + * ownership of returned #wasm_func_t. + */ WASM_API_EXTERN bool wasmtime_funcref_table_get( const wasm_table_t *table, wasm_table_size_t index, own wasm_func_t **func ); + +/** + * \brief Sets a value in a table. + * + * This function is similar to #wasm_table_set, but has a few differences: + * + * * An error is returned through #wasmtime_error_t describing erroneous + * situations. + * * The value being set is specialized to #wasm_func_t. + * + * This function does not take ownership of any of its parameters, but yields + * ownership of returned #wasmtime_error_t. + */ WASM_API_EXTERN own wasmtime_error_t *wasmtime_funcref_table_set( wasm_table_t *table, wasm_table_size_t index, const wasm_func_t *value ); + +/** + * \brief Grows a table. + * + * This function is similar to #wasm_table_grow, but has a few differences: + * + * * An error is returned through #wasmtime_error_t describing erroneous + * situations. + * * The initialization value is specialized to #wasm_func_t. + * * The previous size of the table is returned through `prev_size`. + * + * This function does not take ownership of any of its parameters, but yields + * ownership of returned #wasmtime_error_t. + */ WASM_API_EXTERN wasmtime_error_t *wasmtime_funcref_table_grow( wasm_table_t *table, wasm_table_size_t delta,