wasm_export.h 22 KB

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