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 struct { 26 /// Internal identifier of what store this belongs to, never zero. 27 uint64_t store_id; 28 /// Private internal wasmtime information. 29 uint32_t __private1; 30 }; 31 32 /// Private internal wasmtime information. 33 uint32_t __private2; 34 } wasmtime_component_func_t; 35 36 /** 37 * \brief Invokes \p func with the \p args given and returns the result. 38 * 39 * The \p args provided must match the parameters that this function takes in 40 * terms of their types and the number of parameters. Results will be written to 41 * the \p results provided if the call completes successfully. The initial types 42 * of the values in \p results are ignored and values are overwritten to write 43 * the result. It's required that the \p results_size exactly matches the number 44 * of results that this function produces. 45 */ 46 WASM_API_EXTERN wasmtime_error_t *wasmtime_component_func_call( 47 const wasmtime_component_func_t *func, wasmtime_context_t *context, 48 const wasmtime_component_val_t *args, size_t args_size, 49 wasmtime_component_val_t *results, size_t results_size); 50 51 /** 52 * \brief Invokes the `post-return` canonical ABI option, if specified, after a 53 * #wasmtime_component_func_call has finished. 54 * 55 * This function is a required method call after a #wasmtime_component_func_call 56 * completes successfully. After the embedder has finished processing the return 57 * value then this function must be invoked. 58 */ 59 WASM_API_EXTERN wasmtime_error_t * 60 wasmtime_component_func_post_return(const wasmtime_component_func_t *func, 61 wasmtime_context_t *context); 62 63 #ifdef __cplusplus 64 } // extern "C" 65 #endif 66 67 #endif // WASMTIME_FEATURE_COMPONENT_MODEL 68 69 #endif // WASMTIME_COMPONENT_FUNC_H 70