1 /// \file wasmtime/component/func.h 2 3 #ifndef WASMTIME_COMPONENT_FUNC_H 4 #define WASMTIME_COMPONENT_FUNC_H 5 6 #include <wasmtime/component/val.h> 7 #include <wasmtime/conf.h> 8 #include <wasmtime/error.h> 9 #include <wasmtime/store.h> 10 11 #ifdef WASMTIME_FEATURE_COMPONENT_MODEL 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 /// \brief Representation of a function in Wasmtime. 18 /// 19 /// Functions in Wasmtime are represented as an index into a store and don't 20 /// have any data or destructor associated with the value. Functions cannot 21 /// interoperate between #wasmtime_store_t instances and if the wrong function 22 /// is passed to the wrong store then it may trigger an assertion to abort the 23 /// process. 24 typedef struct wasmtime_component_func { 25 /// Internal identifier of what store this belongs to, never zero. 26 uint64_t store_id; 27 /// Internal index within the store. 28 size_t index; 29 } wasmtime_component_func_t; 30 31 /** 32 * \brief Invokes \p func with the \p args given and returns the result. 33 * 34 * The \p args provided must match the parameters that this function takes in 35 * terms of their types and the number of parameters. Results will be written to 36 * the \p results provided if the call completes successfully. The initial types 37 * of the values in \p results are ignored and values are overwritten to write 38 * the result. It's required that the \p results_size exactly matches the number 39 * of results that this function produces. 40 */ 41 WASM_API_EXTERN wasmtime_error_t *wasmtime_component_func_call( 42 const wasmtime_component_func_t *func, wasmtime_context_t *context, 43 const wasmtime_component_val_t *args, size_t args_size, 44 wasmtime_component_val_t *results, size_t results_size); 45 46 /** 47 * \brief Invokes the `post-return` canonical ABI option, if specified, after a 48 * #wasmtime_component_func_call has finished. 49 * 50 * This function is a required method call after a #wasmtime_component_func_call 51 * completes successfully. After the embedder has finished processing the return 52 * value then this function must be invoked. 53 */ 54 WASM_API_EXTERN wasmtime_error_t * 55 wasmtime_component_func_post_return(const wasmtime_component_func_t *func, 56 wasmtime_context_t *context); 57 58 #ifdef __cplusplus 59 } // extern "C" 60 #endif 61 62 #endif // WASMTIME_FEATURE_COMPONENT_MODEL 63 64 #endif // WASMTIME_COMPONENT_FUNC_H 65