wasm_runtime.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _WASM_RUNTIME_H
  6. #define _WASM_RUNTIME_H
  7. #include "wasm.h"
  8. #include "bh_atomic.h"
  9. #include "bh_bitmap.h"
  10. #include "bh_hashmap.h"
  11. #include "../common/wasm_runtime_common.h"
  12. #include "../common/wasm_exec_env.h"
  13. #if WASM_ENABLE_WASI_NN != 0
  14. #include "../libraries/wasi-nn/src/wasi_nn_private.h"
  15. #endif
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #define EXCEPTION_BUF_LEN 128
  20. typedef struct WASMModuleInstance WASMModuleInstance;
  21. typedef struct WASMFunctionInstance WASMFunctionInstance;
  22. typedef struct WASMMemoryInstance WASMMemoryInstance;
  23. typedef struct WASMTableInstance WASMTableInstance;
  24. typedef struct WASMGlobalInstance WASMGlobalInstance;
  25. /**
  26. * When LLVM JIT, WAMR compiler or AOT is enabled, we should ensure that
  27. * some offsets of the same field in the interpreter module instance and
  28. * aot module instance are the same, so that the LLVM JITed/AOTed code
  29. * can smoothly access the interpreter module instance.
  30. * Same for the memory instance and table instance.
  31. * We use the macro DefPointer to define some related pointer fields.
  32. */
  33. #if (WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 \
  34. || WASM_ENABLE_AOT != 0) \
  35. && UINTPTR_MAX == UINT32_MAX
  36. /* Add u32 padding if LLVM JIT, WAMR compiler or AOT is enabled on
  37. 32-bit platform */
  38. #define DefPointer(type, field) \
  39. type field; \
  40. uint32 field##_padding
  41. #else
  42. #define DefPointer(type, field) type field
  43. #endif
  44. typedef enum WASMExceptionID {
  45. EXCE_UNREACHABLE = 0,
  46. EXCE_OUT_OF_MEMORY,
  47. EXCE_OUT_OF_BOUNDS_MEMORY_ACCESS,
  48. EXCE_INTEGER_OVERFLOW,
  49. EXCE_INTEGER_DIVIDE_BY_ZERO,
  50. EXCE_INVALID_CONVERSION_TO_INTEGER,
  51. EXCE_INVALID_FUNCTION_TYPE_INDEX,
  52. EXCE_INVALID_FUNCTION_INDEX,
  53. EXCE_UNDEFINED_ELEMENT,
  54. EXCE_UNINITIALIZED_ELEMENT,
  55. EXCE_CALL_UNLINKED_IMPORT_FUNC,
  56. EXCE_NATIVE_STACK_OVERFLOW,
  57. EXCE_UNALIGNED_ATOMIC,
  58. EXCE_AUX_STACK_OVERFLOW,
  59. EXCE_AUX_STACK_UNDERFLOW,
  60. EXCE_OUT_OF_BOUNDS_TABLE_ACCESS,
  61. EXCE_OPERAND_STACK_OVERFLOW,
  62. EXCE_FAILED_TO_COMPILE_FAST_JIT_FUNC,
  63. EXCE_ALREADY_THROWN,
  64. EXCE_NUM,
  65. } WASMExceptionID;
  66. typedef union {
  67. uint64 u64;
  68. uint32 u32[2];
  69. } MemBound;
  70. struct WASMMemoryInstance {
  71. /* Module type */
  72. uint32 module_type;
  73. /* Whether the memory is shared */
  74. uint8 is_shared_memory;
  75. /* One byte padding */
  76. uint8 __padding__;
  77. /* Reference count of the memory instance:
  78. 0: non-shared memory, > 0: shared memory */
  79. bh_atomic_16_t ref_count;
  80. /* Number bytes per page */
  81. uint32 num_bytes_per_page;
  82. /* Current page count */
  83. uint32 cur_page_count;
  84. /* Maximum page count */
  85. uint32 max_page_count;
  86. /* Memory data size */
  87. uint32 memory_data_size;
  88. /**
  89. * Memory data begin address, Note:
  90. * the app-heap might be inserted in to the linear memory,
  91. * when memory is re-allocated, the heap data and memory data
  92. * must be copied to new memory also
  93. */
  94. DefPointer(uint8 *, memory_data);
  95. /* Memory data end address */
  96. DefPointer(uint8 *, memory_data_end);
  97. /* Heap data base address */
  98. DefPointer(uint8 *, heap_data);
  99. /* Heap data end address */
  100. DefPointer(uint8 *, heap_data_end);
  101. /* The heap created */
  102. DefPointer(void *, heap_handle);
  103. #if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 \
  104. || WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_AOT != 0
  105. MemBound mem_bound_check_1byte;
  106. MemBound mem_bound_check_2bytes;
  107. MemBound mem_bound_check_4bytes;
  108. MemBound mem_bound_check_8bytes;
  109. MemBound mem_bound_check_16bytes;
  110. #endif
  111. };
  112. struct WASMTableInstance {
  113. /* Current size */
  114. uint32 cur_size;
  115. /* Maximum size */
  116. uint32 max_size;
  117. /* Table elements */
  118. uint32 elems[1];
  119. };
  120. struct WASMGlobalInstance {
  121. /* value type, VALUE_TYPE_I32/I64/F32/F64 */
  122. uint8 type;
  123. /* mutable or constant */
  124. bool is_mutable;
  125. /* data offset to base_addr of WASMMemoryInstance */
  126. uint32 data_offset;
  127. /* initial value */
  128. WASMValue initial_value;
  129. #if WASM_ENABLE_MULTI_MODULE != 0
  130. /* just for import, keep the reference here */
  131. WASMModuleInstance *import_module_inst;
  132. WASMGlobalInstance *import_global_inst;
  133. #endif
  134. };
  135. struct WASMFunctionInstance {
  136. /* whether it is import function or WASM function */
  137. bool is_import_func;
  138. /* parameter count */
  139. uint16 param_count;
  140. /* local variable count, 0 for import function */
  141. uint16 local_count;
  142. /* cell num of parameters */
  143. uint16 param_cell_num;
  144. /* cell num of return type */
  145. uint16 ret_cell_num;
  146. /* cell num of local variables, 0 for import function */
  147. uint16 local_cell_num;
  148. #if WASM_ENABLE_FAST_INTERP != 0
  149. /* cell num of consts */
  150. uint16 const_cell_num;
  151. #endif
  152. uint16 *local_offsets;
  153. /* parameter types */
  154. uint8 *param_types;
  155. /* local types, NULL for import function */
  156. uint8 *local_types;
  157. union {
  158. WASMFunctionImport *func_import;
  159. WASMFunction *func;
  160. } u;
  161. #if WASM_ENABLE_MULTI_MODULE != 0
  162. WASMModuleInstance *import_module_inst;
  163. WASMFunctionInstance *import_func_inst;
  164. #endif
  165. #if WASM_ENABLE_PERF_PROFILING != 0
  166. /* total execution time */
  167. uint64 total_exec_time;
  168. /* total execution count */
  169. uint32 total_exec_cnt;
  170. #endif
  171. };
  172. typedef struct WASMExportFuncInstance {
  173. char *name;
  174. WASMFunctionInstance *function;
  175. } WASMExportFuncInstance;
  176. typedef struct WASMExportGlobInstance {
  177. char *name;
  178. WASMGlobalInstance *global;
  179. } WASMExportGlobInstance;
  180. typedef struct WASMExportTabInstance {
  181. char *name;
  182. WASMTableInstance *table;
  183. } WASMExportTabInstance;
  184. typedef struct WASMExportMemInstance {
  185. char *name;
  186. WASMMemoryInstance *memory;
  187. } WASMExportMemInstance;
  188. /* wasm-c-api import function info */
  189. typedef struct CApiFuncImport {
  190. /* host func pointer after linked */
  191. void *func_ptr_linked;
  192. /* whether the host func has env argument */
  193. bool with_env_arg;
  194. /* the env argument of the host func */
  195. void *env_arg;
  196. } CApiFuncImport;
  197. /* The common part of WASMModuleInstanceExtra and AOTModuleInstanceExtra */
  198. typedef struct WASMModuleInstanceExtraCommon {
  199. void *contexts[WASM_MAX_INSTANCE_CONTEXTS];
  200. CApiFuncImport *c_api_func_imports;
  201. /* pointer to the exec env currently used */
  202. WASMExecEnv *cur_exec_env;
  203. #if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
  204. /* Disable bounds checks or not */
  205. bool disable_bounds_checks;
  206. #endif
  207. #if WASM_ENABLE_BULK_MEMORY != 0
  208. bh_bitmap *data_dropped;
  209. #endif
  210. #if WASM_ENABLE_REF_TYPES != 0
  211. bh_bitmap *elem_dropped;
  212. #endif
  213. } WASMModuleInstanceExtraCommon;
  214. /* Extra info of WASM module instance for interpreter/jit mode */
  215. typedef struct WASMModuleInstanceExtra {
  216. WASMModuleInstanceExtraCommon common;
  217. WASMGlobalInstance *globals;
  218. WASMFunctionInstance *functions;
  219. uint32 global_count;
  220. uint32 function_count;
  221. WASMFunctionInstance *start_function;
  222. WASMFunctionInstance *malloc_function;
  223. WASMFunctionInstance *free_function;
  224. WASMFunctionInstance *retain_function;
  225. RunningMode running_mode;
  226. #if WASM_ENABLE_MULTI_MODULE != 0
  227. bh_list sub_module_inst_list_head;
  228. bh_list *sub_module_inst_list;
  229. /* linked table instances of import table instances */
  230. WASMTableInstance **table_insts_linked;
  231. #endif
  232. #if WASM_ENABLE_MEMORY_PROFILING != 0
  233. uint32 max_aux_stack_used;
  234. #endif
  235. #if WASM_ENABLE_DEBUG_INTERP != 0 \
  236. || (WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \
  237. && WASM_ENABLE_LAZY_JIT != 0)
  238. WASMModuleInstance *next;
  239. #endif
  240. } WASMModuleInstanceExtra;
  241. struct AOTFuncPerfProfInfo;
  242. struct WASMModuleInstance {
  243. /* Module instance type, for module instance loaded from
  244. WASM bytecode binary, this field is Wasm_Module_Bytecode;
  245. for module instance loaded from AOT file, this field is
  246. Wasm_Module_AoT, and this structure should be treated as
  247. AOTModuleInstance structure. */
  248. uint32 module_type;
  249. uint32 memory_count;
  250. DefPointer(WASMMemoryInstance **, memories);
  251. /* global and table info */
  252. uint32 global_data_size;
  253. uint32 table_count;
  254. DefPointer(uint8 *, global_data);
  255. /* For AOTModuleInstance, it denotes `AOTTableInstance *` */
  256. DefPointer(WASMTableInstance **, tables);
  257. /* import func ptrs + llvm jit func ptrs */
  258. DefPointer(void **, func_ptrs);
  259. /* function type indexes */
  260. DefPointer(uint32 *, func_type_indexes);
  261. uint32 export_func_count;
  262. uint32 export_global_count;
  263. uint32 export_memory_count;
  264. uint32 export_table_count;
  265. /* For AOTModuleInstance, it denotes `AOTFunctionInstance *` */
  266. DefPointer(WASMExportFuncInstance *, export_functions);
  267. DefPointer(WASMExportGlobInstance *, export_globals);
  268. DefPointer(WASMExportMemInstance *, export_memories);
  269. DefPointer(WASMExportTabInstance *, export_tables);
  270. /* The exception buffer of wasm interpreter for current thread. */
  271. char cur_exception[EXCEPTION_BUF_LEN];
  272. /* The WASM module or AOT module, for AOTModuleInstance,
  273. it denotes `AOTModule *` */
  274. DefPointer(WASMModule *, module);
  275. DefPointer(void *, used_to_be_wasi_ctx); /* unused */
  276. DefPointer(WASMExecEnv *, exec_env_singleton);
  277. /* Array of function pointers to import functions,
  278. not available in AOTModuleInstance */
  279. DefPointer(void **, import_func_ptrs);
  280. /* Array of function pointers to fast jit functions,
  281. not available in AOTModuleInstance:
  282. Only when the multi-tier JIT macros are all enabled and the running
  283. mode of current module instance is set to Mode_Fast_JIT, runtime
  284. will allocate new memory for it, otherwise it always points to the
  285. module->fast_jit_func_ptrs */
  286. DefPointer(void **, fast_jit_func_ptrs);
  287. /* The custom data that can be set/get by wasm_{get|set}_custom_data */
  288. DefPointer(void *, custom_data);
  289. /* Stack frames, used in call stack dump and perf profiling */
  290. DefPointer(Vector *, frames);
  291. /* Function performance profiling info list, only available
  292. in AOTModuleInstance */
  293. DefPointer(struct AOTFuncPerfProfInfo *, func_perf_profilings);
  294. /* WASM/AOT module extra info, for AOTModuleInstance,
  295. it denotes `AOTModuleInstanceExtra *` */
  296. DefPointer(WASMModuleInstanceExtra *, e);
  297. /* Default WASM operand stack size */
  298. uint32 default_wasm_stack_size;
  299. uint32 reserved[3];
  300. /*
  301. * +------------------------------+ <-- memories
  302. * | WASMMemoryInstance[mem_count], mem_count is always 1 for LLVM JIT/AOT
  303. * +------------------------------+ <-- global_data
  304. * | global data
  305. * +------------------------------+ <-- tables
  306. * | WASMTableInstance[table_count]
  307. * +------------------------------+ <-- e
  308. * | WASMModuleInstanceExtra
  309. * +------------------------------+
  310. */
  311. union {
  312. uint64 _make_it_8_byte_aligned_;
  313. WASMMemoryInstance memory_instances[1];
  314. uint8 bytes[1];
  315. } global_table_data;
  316. };
  317. struct WASMInterpFrame;
  318. typedef struct WASMInterpFrame WASMRuntimeFrame;
  319. #if WASM_ENABLE_MULTI_MODULE != 0
  320. typedef struct WASMSubModInstNode {
  321. bh_list_link l;
  322. /* point to a string pool */
  323. const char *module_name;
  324. WASMModuleInstance *module_inst;
  325. } WASMSubModInstNode;
  326. #endif
  327. /**
  328. * Return the code block of a function.
  329. *
  330. * @param func the WASM function instance
  331. *
  332. * @return the code block of the function
  333. */
  334. static inline uint8 *
  335. wasm_get_func_code(WASMFunctionInstance *func)
  336. {
  337. #if WASM_ENABLE_FAST_INTERP == 0
  338. return func->is_import_func ? NULL : func->u.func->code;
  339. #else
  340. return func->is_import_func ? NULL : func->u.func->code_compiled;
  341. #endif
  342. }
  343. /**
  344. * Return the code block end of a function.
  345. *
  346. * @param func the WASM function instance
  347. *
  348. * @return the code block end of the function
  349. */
  350. static inline uint8 *
  351. wasm_get_func_code_end(WASMFunctionInstance *func)
  352. {
  353. #if WASM_ENABLE_FAST_INTERP == 0
  354. return func->is_import_func ? NULL
  355. : func->u.func->code + func->u.func->code_size;
  356. #else
  357. return func->is_import_func
  358. ? NULL
  359. : func->u.func->code_compiled + func->u.func->code_compiled_size;
  360. #endif
  361. }
  362. WASMModule *
  363. wasm_load(uint8 *buf, uint32 size,
  364. #if WASM_ENABLE_MULTI_MODULE != 0
  365. bool main_module,
  366. #endif
  367. char *error_buf, uint32 error_buf_size);
  368. WASMModule *
  369. wasm_load_from_sections(WASMSection *section_list, char *error_buf,
  370. uint32 error_buf_size);
  371. void
  372. wasm_unload(WASMModule *module);
  373. WASMModuleInstance *
  374. wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
  375. WASMExecEnv *exec_env_main, uint32 stack_size,
  376. uint32 heap_size, char *error_buf, uint32 error_buf_size);
  377. void
  378. wasm_dump_perf_profiling(const WASMModuleInstance *module_inst);
  379. void
  380. wasm_deinstantiate(WASMModuleInstance *module_inst, bool is_sub_inst);
  381. bool
  382. wasm_set_running_mode(WASMModuleInstance *module_inst,
  383. RunningMode running_mode);
  384. WASMFunctionInstance *
  385. wasm_lookup_function(const WASMModuleInstance *module_inst, const char *name,
  386. const char *signature);
  387. #if WASM_ENABLE_MULTI_MODULE != 0
  388. WASMGlobalInstance *
  389. wasm_lookup_global(const WASMModuleInstance *module_inst, const char *name);
  390. WASMMemoryInstance *
  391. wasm_lookup_memory(const WASMModuleInstance *module_inst, const char *name);
  392. WASMTableInstance *
  393. wasm_lookup_table(const WASMModuleInstance *module_inst, const char *name);
  394. #endif
  395. bool
  396. wasm_call_function(WASMExecEnv *exec_env, WASMFunctionInstance *function,
  397. unsigned argc, uint32 argv[]);
  398. void
  399. wasm_set_exception(WASMModuleInstance *module, const char *exception);
  400. void
  401. wasm_set_exception_with_id(WASMModuleInstance *module_inst, uint32 id);
  402. const char *
  403. wasm_get_exception(WASMModuleInstance *module);
  404. /**
  405. * @brief Copy exception in buffer passed as parameter. Thread-safe version of
  406. * `wasm_get_exception()`
  407. * @note Buffer size must be no smaller than EXCEPTION_BUF_LEN
  408. * @return true if exception found
  409. */
  410. bool
  411. wasm_copy_exception(WASMModuleInstance *module_inst, char *exception_buf);
  412. uint32
  413. wasm_module_malloc_internal(WASMModuleInstance *module_inst,
  414. WASMExecEnv *exec_env, uint32 size,
  415. void **p_native_addr);
  416. uint32
  417. wasm_module_realloc_internal(WASMModuleInstance *module_inst,
  418. WASMExecEnv *exec_env, uint32 ptr, uint32 size,
  419. void **p_native_addr);
  420. void
  421. wasm_module_free_internal(WASMModuleInstance *module_inst,
  422. WASMExecEnv *exec_env, uint32 ptr);
  423. uint32
  424. wasm_module_malloc(WASMModuleInstance *module_inst, uint32 size,
  425. void **p_native_addr);
  426. uint32
  427. wasm_module_realloc(WASMModuleInstance *module_inst, uint32 ptr, uint32 size,
  428. void **p_native_addr);
  429. void
  430. wasm_module_free(WASMModuleInstance *module_inst, uint32 ptr);
  431. uint32
  432. wasm_module_dup_data(WASMModuleInstance *module_inst, const char *src,
  433. uint32 size);
  434. /**
  435. * Check whether the app address and the buf is inside the linear memory,
  436. * and convert the app address into native address
  437. */
  438. bool
  439. wasm_check_app_addr_and_convert(WASMModuleInstance *module_inst, bool is_str,
  440. uint32 app_buf_addr, uint32 app_buf_size,
  441. void **p_native_addr);
  442. WASMMemoryInstance *
  443. wasm_get_default_memory(WASMModuleInstance *module_inst);
  444. bool
  445. wasm_enlarge_memory(WASMModuleInstance *module_inst, uint32 inc_page_count);
  446. bool
  447. wasm_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 elem_idx,
  448. uint32 argc, uint32 argv[]);
  449. #if WASM_ENABLE_THREAD_MGR != 0
  450. bool
  451. wasm_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset, uint32 size);
  452. bool
  453. wasm_get_aux_stack(WASMExecEnv *exec_env, uint32 *start_offset, uint32 *size);
  454. #endif
  455. void
  456. wasm_get_module_mem_consumption(const WASMModule *module,
  457. WASMModuleMemConsumption *mem_conspn);
  458. void
  459. wasm_get_module_inst_mem_consumption(const WASMModuleInstance *module,
  460. WASMModuleInstMemConsumption *mem_conspn);
  461. #if WASM_ENABLE_REF_TYPES != 0
  462. static inline bool
  463. wasm_elem_is_active(uint32 mode)
  464. {
  465. return (mode & 0x1) == 0x0;
  466. }
  467. static inline bool
  468. wasm_elem_is_passive(uint32 mode)
  469. {
  470. return (mode & 0x1) == 0x1;
  471. }
  472. static inline bool
  473. wasm_elem_is_declarative(uint32 mode)
  474. {
  475. return (mode & 0x3) == 0x3;
  476. }
  477. bool
  478. wasm_enlarge_table(WASMModuleInstance *module_inst, uint32 table_idx,
  479. uint32 inc_entries, uint32 init_val);
  480. #endif /* WASM_ENABLE_REF_TYPES != 0 */
  481. static inline WASMTableInstance *
  482. wasm_get_table_inst(const WASMModuleInstance *module_inst, uint32 tbl_idx)
  483. {
  484. /* careful, it might be a table in another module */
  485. WASMTableInstance *tbl_inst = module_inst->tables[tbl_idx];
  486. #if WASM_ENABLE_MULTI_MODULE != 0
  487. if (tbl_idx < module_inst->module->import_table_count
  488. && module_inst->e->table_insts_linked[tbl_idx]) {
  489. tbl_inst = module_inst->e->table_insts_linked[tbl_idx];
  490. }
  491. #endif
  492. bh_assert(tbl_inst);
  493. return tbl_inst;
  494. }
  495. #if WASM_ENABLE_DUMP_CALL_STACK != 0
  496. bool
  497. wasm_interp_create_call_stack(struct WASMExecEnv *exec_env);
  498. /**
  499. * @brief Dump wasm call stack or get the size
  500. *
  501. * @param exec_env the execution environment
  502. * @param print whether to print to stdout or not
  503. * @param buf buffer to store the dumped content
  504. * @param len length of the buffer
  505. *
  506. * @return when print is true, return the bytes printed out to stdout; when
  507. * print is false and buf is NULL, return the size required to store the
  508. * callstack content; when print is false and buf is not NULL, return the size
  509. * dumped to the buffer, 0 means error and data in buf may be invalid
  510. */
  511. uint32
  512. wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf,
  513. uint32 len);
  514. #endif
  515. const uint8 *
  516. wasm_loader_get_custom_section(WASMModule *module, const char *name,
  517. uint32 *len);
  518. #if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 \
  519. || WASM_ENABLE_WAMR_COMPILER != 0
  520. void
  521. jit_set_exception_with_id(WASMModuleInstance *module_inst, uint32 id);
  522. /**
  523. * Check whether the app address and the buf is inside the linear memory,
  524. * and convert the app address into native address
  525. */
  526. bool
  527. jit_check_app_addr_and_convert(WASMModuleInstance *module_inst, bool is_str,
  528. uint32 app_buf_addr, uint32 app_buf_size,
  529. void **p_native_addr);
  530. #endif /* end of WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 \
  531. || WASM_ENABLE_WAMR_COMPILER != 0 */
  532. #if WASM_ENABLE_FAST_JIT != 0
  533. bool
  534. fast_jit_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 elem_idx,
  535. uint32 type_idx, uint32 argc, uint32 *argv);
  536. bool
  537. fast_jit_invoke_native(WASMExecEnv *exec_env, uint32 func_idx,
  538. struct WASMInterpFrame *prev_frame);
  539. #endif
  540. #if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0
  541. bool
  542. llvm_jit_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 elem_idx,
  543. uint32 argc, uint32 *argv);
  544. bool
  545. llvm_jit_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
  546. uint32 *argv);
  547. #if WASM_ENABLE_BULK_MEMORY != 0
  548. bool
  549. llvm_jit_memory_init(WASMModuleInstance *module_inst, uint32 seg_index,
  550. uint32 offset, uint32 len, uint32 dst);
  551. bool
  552. llvm_jit_data_drop(WASMModuleInstance *module_inst, uint32 seg_index);
  553. #endif
  554. #if WASM_ENABLE_REF_TYPES != 0
  555. void
  556. llvm_jit_drop_table_seg(WASMModuleInstance *module_inst, uint32 tbl_seg_idx);
  557. void
  558. llvm_jit_table_init(WASMModuleInstance *module_inst, uint32 tbl_idx,
  559. uint32 tbl_seg_idx, uint32 length, uint32 src_offset,
  560. uint32 dst_offset);
  561. void
  562. llvm_jit_table_copy(WASMModuleInstance *module_inst, uint32 src_tbl_idx,
  563. uint32 dst_tbl_idx, uint32 length, uint32 src_offset,
  564. uint32 dst_offset);
  565. void
  566. llvm_jit_table_fill(WASMModuleInstance *module_inst, uint32 tbl_idx,
  567. uint32 length, uint32 val, uint32 data_offset);
  568. uint32
  569. llvm_jit_table_grow(WASMModuleInstance *module_inst, uint32 tbl_idx,
  570. uint32 inc_entries, uint32 init_val);
  571. #endif
  572. #if WASM_ENABLE_DUMP_CALL_STACK != 0 || WASM_ENABLE_PERF_PROFILING != 0
  573. bool
  574. llvm_jit_alloc_frame(WASMExecEnv *exec_env, uint32 func_index);
  575. void
  576. llvm_jit_free_frame(WASMExecEnv *exec_env);
  577. #endif
  578. #endif /* end of WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 */
  579. #if WASM_ENABLE_LIBC_WASI != 0 && WASM_ENABLE_MULTI_MODULE != 0
  580. void
  581. wasm_propagate_wasi_args(WASMModule *module);
  582. #endif
  583. #if WASM_ENABLE_THREAD_MGR != 0
  584. void
  585. exception_lock(WASMModuleInstance *module_inst);
  586. void
  587. exception_unlock(WASMModuleInstance *module_inst);
  588. #else
  589. #define exception_lock(module_inst) (void)(module_inst)
  590. #define exception_unlock(module_inst) (void)(module_inst)
  591. #endif
  592. #ifdef __cplusplus
  593. }
  594. #endif
  595. #endif /* end of _WASM_RUNTIME_H */