wasm_runtime.h 20 KB

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