wasm_runtime.h 21 KB

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