wasm_runtime.h 21 KB

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