wasm_export.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _WASM_EXPORT_H
  6. #define _WASM_EXPORT_H
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include "lib_export.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #define get_module_inst(exec_env) \
  14. wasm_runtime_get_module_inst(exec_env)
  15. #define validate_app_addr(offset, size) \
  16. wasm_runtime_validate_app_addr(module_inst, offset, size)
  17. #define validate_app_str_addr(offset) \
  18. wasm_runtime_validate_app_str_addr(module_inst, offset)
  19. #define addr_app_to_native(offset) \
  20. wasm_runtime_addr_app_to_native(module_inst, offset)
  21. #define addr_native_to_app(ptr) \
  22. wasm_runtime_addr_native_to_app(module_inst, ptr)
  23. #define module_malloc(size, p_native_addr) \
  24. wasm_runtime_module_malloc(module_inst, size, p_native_addr)
  25. #define module_free(offset) \
  26. wasm_runtime_module_free(module_inst, offset)
  27. #define native_raw_return_type(type, args) type *raw_ret = (type*)(args)
  28. #define native_raw_get_arg(type, name, args) type name = *((type*)(args++))
  29. #define native_raw_set_return(val) *raw_ret = (val)
  30. #ifndef WASM_MODULE_T_DEFINED
  31. #define WASM_MODULE_T_DEFINED
  32. /* Uninstantiated WASM module loaded from WASM binary file
  33. or AoT binary file*/
  34. struct WASMModuleCommon;
  35. typedef struct WASMModuleCommon *wasm_module_t;
  36. #endif
  37. /* Instantiated WASM module */
  38. struct WASMModuleInstanceCommon;
  39. typedef struct WASMModuleInstanceCommon *wasm_module_inst_t;
  40. /* Function instance */
  41. typedef void WASMFunctionInstanceCommon;
  42. typedef WASMFunctionInstanceCommon *wasm_function_inst_t;
  43. /* WASM section */
  44. typedef struct wasm_section_t {
  45. struct wasm_section_t *next;
  46. /* section type */
  47. int section_type;
  48. /* section body, not include type and size */
  49. uint8_t *section_body;
  50. /* section body size */
  51. uint32_t section_body_size;
  52. } wasm_section_t, aot_section_t, *wasm_section_list_t, *aot_section_list_t;
  53. /* Execution environment, e.g. stack info */
  54. struct WASMExecEnv;
  55. typedef struct WASMExecEnv *wasm_exec_env_t;
  56. /* Package Type */
  57. typedef enum {
  58. Wasm_Module_Bytecode = 0,
  59. Wasm_Module_AoT,
  60. Package_Type_Unknown = 0xFFFF
  61. } package_type_t;
  62. /* Memory allocator type */
  63. typedef enum {
  64. /* pool mode, allocate memory from user defined heap buffer */
  65. Alloc_With_Pool = 0,
  66. /* user allocator mode, allocate memory from user defined
  67. malloc function */
  68. Alloc_With_Allocator,
  69. /* system allocator mode, allocate memory from system allocator,
  70. or, platform's os_malloc function */
  71. Alloc_With_System_Allocator,
  72. } mem_alloc_type_t;
  73. /* Memory allocator option */
  74. typedef union MemAllocOption {
  75. struct {
  76. void *heap_buf;
  77. uint32_t heap_size;
  78. } pool;
  79. struct {
  80. void *malloc_func;
  81. void *realloc_func;
  82. void *free_func;
  83. } allocator;
  84. } MemAllocOption;
  85. /* WASM runtime initialize arguments */
  86. typedef struct RuntimeInitArgs {
  87. mem_alloc_type_t mem_alloc_type;
  88. MemAllocOption mem_alloc_option;
  89. const char *native_module_name;
  90. NativeSymbol *native_symbols;
  91. uint32_t n_native_symbols;
  92. } RuntimeInitArgs;
  93. /**
  94. * Initialize the WASM runtime environment, and also initialize
  95. * the memory allocator with system allocator, which calls os_malloc
  96. * to allocate memory
  97. *
  98. * @return true if success, false otherwise
  99. */
  100. bool
  101. wasm_runtime_init();
  102. /**
  103. * Initialize the WASM runtime environment, and also initialize
  104. * the memory allocator and register native symbols, which are specified
  105. * with init arguments
  106. *
  107. * @param init_args specifies the init arguments
  108. *
  109. * @return return true if success, false otherwise
  110. */
  111. bool
  112. wasm_runtime_full_init(RuntimeInitArgs *init_args);
  113. /**
  114. * Destroy the WASM runtime environment.
  115. */
  116. void
  117. wasm_runtime_destroy();
  118. /**
  119. * Allocate memory from runtime memory environment.
  120. *
  121. * @param size bytes need to allocate
  122. *
  123. * @return the pointer to memory allocated
  124. */
  125. void *
  126. wasm_runtime_malloc(unsigned int size);
  127. /**
  128. * Reallocate memory from runtime memory environment
  129. *
  130. * @param ptr the original memory
  131. * @param size bytes need to reallocate
  132. *
  133. * @return the pointer to memory reallocated
  134. */
  135. void *
  136. wasm_runtime_realloc(void *ptr, unsigned int size);
  137. /*
  138. * Free memory to runtime memory environment.
  139. */
  140. void wasm_runtime_free(void *ptr);
  141. /**
  142. * Get the package type of a buffer.
  143. *
  144. * @param buf the package buffer
  145. * @param size the package buffer size
  146. *
  147. * @return the package type, return Package_Type_Unknown if the type is unknown
  148. */
  149. package_type_t
  150. get_package_type(const uint8_t *buf, uint32_t size);
  151. #if WASM_ENABLE_MULTI_MODULE != 0
  152. /**
  153. * It is a callback for WAMR providing by embedding to load a module file
  154. * into a buffer
  155. */
  156. typedef bool (*module_reader)(const char *module_name,
  157. uint8_t **p_buffer, uint32_t *p_size);
  158. /**
  159. * It is a callback for WAMR providing by embedding to release the buffer which
  160. * is used by loading a module file
  161. */
  162. typedef void (*module_destroyer)(uint8_t *buffer, uint32_t size);
  163. /**
  164. * To setup callbacks for reading and releasing a buffer about a module file
  165. *
  166. * @param reader a callback to read a module file into a buffer
  167. * @param destroyer a callback to release above buffer
  168. */
  169. void
  170. wasm_runtime_set_module_reader(const module_reader reader,
  171. const module_destroyer destroyer);
  172. /**
  173. * Give the "module" a name "module_name".
  174. * can not assign a new name to a module if it already has a name
  175. *
  176. * @param module_name indicate a name
  177. * @param module the target module
  178. * @param error_buf output of the exception info
  179. * @param error_buf_size the size of the exception string
  180. *
  181. * @return true means success, false means failed
  182. */
  183. bool
  184. wasm_runtime_register_module(const char *module_name, wasm_module_t module,
  185. char *error_buf, uint32_t error_buf_size);
  186. /**
  187. * To check if there is already a loaded module named module_name in the
  188. * runtime. you will not want to load repeately
  189. *
  190. * @param module_name indicate a name
  191. *
  192. * @return return WASM module loaded, NULL if failed
  193. */
  194. wasm_module_t
  195. wasm_runtime_find_module_registered(const char *module_name);
  196. #endif /* WASM_ENABLE_MULTI_MODULE */
  197. /**
  198. * Load a WASM module from a specified byte buffer. The byte buffer can be
  199. * WASM binary data when interpreter or JIT is enabled, or AOT binary data
  200. * when AOT is enabled. If it is AOT binary data, it must be 4-byte aligned.
  201. *
  202. * @param buf the byte buffer which contains the WASM binary data
  203. * @param size the size of the buffer
  204. * @param error_buf output of the exception info
  205. * @param error_buf_size the size of the exception string
  206. *
  207. * @return return WASM module loaded, NULL if failed
  208. */
  209. wasm_module_t
  210. wasm_runtime_load(const uint8_t *buf, uint32_t size,
  211. char *error_buf, uint32_t error_buf_size);
  212. /**
  213. * Load a WASM module from a specified WASM or AOT section list.
  214. *
  215. * @param section_list the section list which contains each section data
  216. * @param is_aot whether the section list is AOT section list
  217. * @param error_buf output of the exception info
  218. * @param error_buf_size the size of the exception string
  219. *
  220. * @return return WASM module loaded, NULL if failed
  221. */
  222. wasm_module_t
  223. wasm_runtime_load_from_sections(wasm_section_list_t section_list, bool is_aot,
  224. char *error_buf, uint32_t error_buf_size);
  225. /**
  226. * Unload a WASM module.
  227. *
  228. * @param module the module to be unloaded
  229. */
  230. void
  231. wasm_runtime_unload(wasm_module_t module);
  232. void
  233. wasm_runtime_set_wasi_args(wasm_module_t module,
  234. const char *dir_list[], uint32_t dir_count,
  235. const char *map_dir_list[], uint32_t map_dir_count,
  236. const char *env[], uint32_t env_count,
  237. char *argv[], int argc);
  238. /**
  239. * Instantiate a WASM module.
  240. *
  241. * @param module the WASM module to instantiate
  242. * @param stack_size the default stack size of the module instance when the
  243. * exec env's operation stack isn't created by user, e.g. API
  244. * wasm_application_execute_main() and wasm_application_execute_func()
  245. * create the operation stack internally with the stack size specified
  246. * here. And API wasm_runtime_create_exec_env() creates the operation
  247. * stack with stack size specified by its parameter, the stack size
  248. * specified here is ignored.
  249. * @param heap_size the default heap size of the module instance, a heap will
  250. * be created besides the app memory space. Both wasm app and native
  251. * function can allocate memory from the heap. If heap_size is 0, the
  252. * default heap size will be used.
  253. * @param error_buf buffer to output the error info if failed
  254. * @param error_buf_size the size of the error buffer
  255. *
  256. * @return return the instantiated WASM module instance, NULL if failed
  257. */
  258. wasm_module_inst_t
  259. wasm_runtime_instantiate(const wasm_module_t module,
  260. uint32_t stack_size, uint32_t heap_size,
  261. char *error_buf, uint32_t error_buf_size);
  262. /**
  263. * Deinstantiate a WASM module instance, destroy the resources.
  264. *
  265. * @param module_inst the WASM module instance to destroy
  266. */
  267. void
  268. wasm_runtime_deinstantiate(wasm_module_inst_t module_inst);
  269. bool
  270. wasm_runtime_is_wasi_mode(wasm_module_inst_t module_inst);
  271. wasm_function_inst_t
  272. wasm_runtime_lookup_wasi_start_function(wasm_module_inst_t module_inst);
  273. /**
  274. * Lookup an exported function in the WASM module instance.
  275. *
  276. * @param module_inst the module instance
  277. * @param name the name of the function
  278. * @param signature the signature of the function, ignored currently
  279. *
  280. * @return the function instance found, NULL if not found
  281. */
  282. wasm_function_inst_t
  283. wasm_runtime_lookup_function(wasm_module_inst_t const module_inst,
  284. const char *name, const char *signature);
  285. /**
  286. * Create execution environment for a WASM module instance.
  287. *
  288. * @param module_inst the module instance
  289. * @param stack_size the stack size to execute a WASM function
  290. *
  291. * @return the execution environment, NULL if failed, e.g. invalid
  292. * stack size is passed
  293. */
  294. wasm_exec_env_t
  295. wasm_runtime_create_exec_env(wasm_module_inst_t module_inst,
  296. uint32_t stack_size);
  297. /**
  298. * Destroy the execution environment.
  299. *
  300. * @param exec_env the execution environment to destroy
  301. */
  302. void
  303. wasm_runtime_destroy_exec_env(wasm_exec_env_t exec_env);
  304. /**
  305. * Get WASM module instance from execution environment
  306. *
  307. * @param exec_env the execution environment to retrieve
  308. *
  309. * @return the WASM module instance
  310. */
  311. wasm_module_inst_t
  312. wasm_runtime_get_module_inst(wasm_exec_env_t exec_env);
  313. /**
  314. * Call the given WASM function of a WASM module instance with
  315. * arguments (bytecode and AoT).
  316. *
  317. * @param exec_env the execution environment to call the function,
  318. * which must be created from wasm_create_exec_env()
  319. * @param function the function to call
  320. * @param argc the number of arguments
  321. * @param argv the arguments. If the function has return value,
  322. * the first (or first two in case 64-bit return value) element of
  323. * argv stores the return value of the called WASM function after this
  324. * function returns.
  325. *
  326. * @return true if success, false otherwise and exception will be thrown,
  327. * the caller can call wasm_runtime_get_exception to get the exception
  328. * info.
  329. */
  330. bool
  331. wasm_runtime_call_wasm(wasm_exec_env_t exec_env,
  332. wasm_function_inst_t function,
  333. uint32_t argc, uint32_t argv[]);
  334. /**
  335. * Find the unique main function from a WASM module instance
  336. * and execute that function.
  337. *
  338. * @param module_inst the WASM module instance
  339. * @param argc the number of arguments
  340. * @param argv the arguments array
  341. *
  342. * @return true if the main function is called, false otherwise and exception
  343. * will be thrown, the caller can call wasm_runtime_get_exception to get
  344. * the exception info.
  345. */
  346. bool
  347. wasm_application_execute_main(wasm_module_inst_t module_inst,
  348. int32_t argc, char *argv[]);
  349. /**
  350. * Find the specified function in argv[0] from a WASM module instance
  351. * and execute that function.
  352. *
  353. * @param module_inst the WASM module instance
  354. * @param name the name of the function to execute.
  355. * to indicate the module name via: $module_name$function_name
  356. * or just a function name: function_name
  357. * @param argc the number of arguments
  358. * @param argv the arguments array
  359. *
  360. * @return true if the specified function is called, false otherwise and
  361. * exception will be thrown, the caller can call wasm_runtime_get_exception
  362. * to get the exception info.
  363. */
  364. bool
  365. wasm_application_execute_func(wasm_module_inst_t module_inst,
  366. const char *name, int32_t argc, char *argv[]);
  367. /**
  368. * Get exception info of the WASM module instance.
  369. *
  370. * @param module_inst the WASM module instance
  371. *
  372. * @return the exception string
  373. */
  374. const char *
  375. wasm_runtime_get_exception(wasm_module_inst_t module_inst);
  376. /**
  377. * Set exception info of the WASM module instance.
  378. *
  379. * @param module_inst the WASM module instance
  380. *
  381. * @param exception the exception string
  382. */
  383. void
  384. wasm_runtime_set_exception(wasm_module_inst_t module_inst,
  385. const char *exception);
  386. /**
  387. * Clear exception info of the WASM module instance.
  388. *
  389. * @param module_inst the WASM module instance
  390. */
  391. void
  392. wasm_runtime_clear_exception(wasm_module_inst_t module_inst);
  393. /**
  394. * Set custom data to WASM module instance.
  395. *
  396. * @param module_inst the WASM module instance
  397. * @param custom_data the custom data to be set
  398. */
  399. void
  400. wasm_runtime_set_custom_data(wasm_module_inst_t module_inst,
  401. void *custom_data);
  402. /**
  403. * Get the custom data within a WASM module instance.
  404. *
  405. * @param module_inst the WASM module instance
  406. *
  407. * @return the custom data (NULL if not set yet)
  408. */
  409. void *
  410. wasm_runtime_get_custom_data(wasm_module_inst_t module_inst);
  411. /**
  412. * Allocate memory from the heap of WASM module instance
  413. *
  414. * @param module_inst the WASM module instance which contains heap
  415. * @param size the size bytes to allocate
  416. * @param p_native_addr return native address of the allocated memory
  417. * if it is not NULL, and return NULL if memory malloc failed
  418. *
  419. * @return the allocated memory address, which is a relative offset to the
  420. * base address of the module instance's memory space, the value range
  421. * is (-heap_size, 0). Note that it is not an absolute address.
  422. * Return non-zero if success, zero if failed.
  423. */
  424. int32_t
  425. wasm_runtime_module_malloc(wasm_module_inst_t module_inst, uint32_t size,
  426. void **p_native_addr);
  427. /**
  428. * Free memory to the heap of WASM module instance
  429. *
  430. * @param module_inst the WASM module instance which contains heap
  431. * @param ptr the pointer to free
  432. */
  433. void
  434. wasm_runtime_module_free(wasm_module_inst_t module_inst, int32_t ptr);
  435. /**
  436. * Allocate memory from the heap of WASM module instance and initialize
  437. * the memory with src
  438. *
  439. * @param module_inst the WASM module instance which contains heap
  440. * @param src the source data to copy
  441. * @param size the size of the source data
  442. *
  443. * @return the allocated memory address, which is a relative offset to the
  444. * base address of the module instance's memory space, the value range
  445. * is (-heap_size, 0). Note that it is not an absolute address.
  446. * Return non-zero if success, zero if failed.
  447. */
  448. int32_t
  449. wasm_runtime_module_dup_data(wasm_module_inst_t module_inst,
  450. const char *src, uint32_t size);
  451. /**
  452. * Validate the app address, check whether it belongs to WASM module
  453. * instance's address space, or in its heap space or memory space.
  454. *
  455. * @param module_inst the WASM module instance
  456. * @param app_offset the app address to validate, which is a relative address
  457. * @param size the size bytes of the app address
  458. *
  459. * @return true if success, false otherwise. If failed, an exception will
  460. * be thrown.
  461. */
  462. bool
  463. wasm_runtime_validate_app_addr(wasm_module_inst_t module_inst,
  464. int32_t app_offset, uint32_t size);
  465. /**
  466. * Similar to wasm_runtime_validate_app_addr(), except that the size parameter
  467. * is not provided. This function validates the app string address, check whether it
  468. * belongs to WASM module instance's address space, or in its heap space or
  469. * memory space. Moreover, it checks whether it is the offset of a string that
  470. * is end with '\0'.
  471. * @param module_inst the WASM module instance
  472. * @param app_str_offset the app address of the string to validate, which is a
  473. * relative address
  474. *
  475. * @return true if success, false otherwise. If failed, an exception will
  476. * be thrown.
  477. */
  478. bool
  479. wasm_runtime_validate_app_str_addr(wasm_module_inst_t module_inst,
  480. int32_t app_str_offset);
  481. /**
  482. * Validate the native address, check whether it belongs to WASM module
  483. * instance's address space, or in its heap space or memory space.
  484. *
  485. * @param module_inst the WASM module instance
  486. * @param native_ptr the native address to validate, which is an absolute
  487. * address
  488. * @param size the size bytes of the app address
  489. *
  490. * @return true if success, false otherwise. If failed, an exception will
  491. * be thrown.
  492. */
  493. bool
  494. wasm_runtime_validate_native_addr(wasm_module_inst_t module_inst,
  495. void *native_ptr, uint32_t size);
  496. /**
  497. * Convert app address(relative address) to native address(absolute address)
  498. *
  499. * @param module_inst the WASM module instance
  500. * @param app_offset the app adress
  501. *
  502. * @return the native address converted
  503. */
  504. void*
  505. wasm_runtime_addr_app_to_native(wasm_module_inst_t module_inst,
  506. int32_t app_offset);
  507. /**
  508. * Convert native address(absolute address) to app address(relative address)
  509. *
  510. * @param module_inst the WASM module instance
  511. * @param native_ptr the native address
  512. *
  513. * @return the app address converted
  514. */
  515. int32_t
  516. wasm_runtime_addr_native_to_app(wasm_module_inst_t module_inst,
  517. void *native_ptr);
  518. /**
  519. * Get the app address range (relative address) that a app address belongs to
  520. *
  521. * @param module_inst the WASM module instance
  522. * @param app_offset the app address to retrieve
  523. * @param p_app_start_offset buffer to output the app start offset if not NULL
  524. * @param p_app_end_offset buffer to output the app end offset if not NULL
  525. *
  526. * @return true if success, false otherwise.
  527. */
  528. bool
  529. wasm_runtime_get_app_addr_range(wasm_module_inst_t module_inst,
  530. int32_t app_offset,
  531. int32_t *p_app_start_offset,
  532. int32_t *p_app_end_offset);
  533. /**
  534. * Get the native address range (absolute address) that a native address belongs to
  535. *
  536. * @param module_inst the WASM module instance
  537. * @param native_ptr the native address to retrieve
  538. * @param p_native_start_addr buffer to output the native start address if not NULL
  539. * @param p_native_end_addr buffer to output the native end address if not NULL
  540. *
  541. * @return true if success, false otherwise.
  542. */
  543. bool
  544. wasm_runtime_get_native_addr_range(wasm_module_inst_t module_inst,
  545. uint8_t *native_ptr,
  546. uint8_t **p_native_start_addr,
  547. uint8_t **p_native_end_addr);
  548. /**
  549. * Register native functions with same module name
  550. *
  551. * @param module_name the module name of the native functions
  552. * @param native_symbols specifies an array of NativeSymbol structures which
  553. * contain the names, function pointers and signatures
  554. * Note: WASM runtime will not allocate memory to clone the data, so
  555. * user must ensure the array can be used forever
  556. * Meanings of letters in function signature:
  557. * 'i': the parameter is i32 type
  558. * 'I': the parameter is i64 type
  559. * 'f': the parameter is f32 type
  560. * 'F': the parameter is f64 type
  561. * '*': the parameter is a pointer (i32 in WASM), and runtime will
  562. * auto check its boundary before calling the native function.
  563. * If it is followed by '~', the checked length of the pointer
  564. * is gotten from the following parameter, if not, the checked
  565. * length of the pointer is 1.
  566. * '~': the parameter is the pointer's length with i32 type, and must
  567. * follow after '*'
  568. * '$': the parameter is a string (i32 in WASM), and runtime will
  569. * auto check its boundary before calling the native function
  570. * @param n_native_symbols specifies the number of native symbols in the array
  571. *
  572. * @return true if success, false otherwise
  573. */
  574. bool wasm_runtime_register_natives(const char *module_name,
  575. NativeSymbol *native_symbols,
  576. uint32_t n_native_symbols);
  577. /**
  578. * Register native functions with same module name, similar to
  579. * wasm_runtime_register_natives, the difference is that runtime passes raw
  580. * arguments to native API, which means that the native API should be defined as:
  581. * void foo(wasm_exec_env_t exec_env, uint64 *args);
  582. * and native API should extract arguments one by one from args array with macro
  583. * native_raw_get_arg
  584. * and write the return value back to args[0] with macro
  585. * native_raw_return_type and native_raw_set_return
  586. */
  587. bool wasm_runtime_register_natives_raw(const char *module_name,
  588. NativeSymbol *native_symbols,
  589. uint32_t n_native_symbols);
  590. /**
  591. * Get attachment of native function from execution environment
  592. *
  593. * @param exec_env the execution environment to retrieve
  594. *
  595. * @return the attachment of native function
  596. */
  597. void *
  598. wasm_runtime_get_function_attachment(wasm_exec_env_t exec_env);
  599. /**
  600. * Set user data to execution environment.
  601. *
  602. * @param exec_env the execution environment
  603. * @param user_data the user data to be set
  604. */
  605. void
  606. wasm_runtime_set_user_data(wasm_exec_env_t exec_env,
  607. void *user_data);
  608. /**
  609. * Get the user data within execution environment.
  610. *
  611. * @param exec_env the execution environment
  612. *
  613. * @return the user data (NULL if not set yet)
  614. */
  615. void *
  616. wasm_runtime_get_user_data(wasm_exec_env_t exec_env);
  617. #if WASM_ENABLE_THREAD_MGR != 0
  618. /**
  619. * Set the max thread num per cluster.
  620. *
  621. * @param num maximum thread num
  622. */
  623. void
  624. wasm_runtime_set_max_thread_num(uint32_t num);
  625. #endif
  626. #ifdef __cplusplus
  627. }
  628. #endif
  629. #endif /* end of _WASM_EXPORT_H */