wasm_runtime.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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. /* children execution time */
  171. uint64 children_exec_time;
  172. #endif
  173. };
  174. typedef struct WASMExportFuncInstance {
  175. char *name;
  176. WASMFunctionInstance *function;
  177. } WASMExportFuncInstance;
  178. typedef struct WASMExportGlobInstance {
  179. char *name;
  180. WASMGlobalInstance *global;
  181. } WASMExportGlobInstance;
  182. typedef struct WASMExportTabInstance {
  183. char *name;
  184. WASMTableInstance *table;
  185. } WASMExportTabInstance;
  186. typedef struct WASMExportMemInstance {
  187. char *name;
  188. WASMMemoryInstance *memory;
  189. } WASMExportMemInstance;
  190. /* wasm-c-api import function info */
  191. typedef struct CApiFuncImport {
  192. /* host func pointer after linked */
  193. void *func_ptr_linked;
  194. /* whether the host func has env argument */
  195. bool with_env_arg;
  196. /* the env argument of the host func */
  197. void *env_arg;
  198. } CApiFuncImport;
  199. /* The common part of WASMModuleInstanceExtra and AOTModuleInstanceExtra */
  200. typedef struct WASMModuleInstanceExtraCommon {
  201. CApiFuncImport *c_api_func_imports;
  202. void *contexts[WASM_MAX_INSTANCE_CONTEXTS];
  203. /* pointer to the exec env currently used */
  204. WASMExecEnv *cur_exec_env;
  205. #if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
  206. /* Disable bounds checks or not */
  207. bool disable_bounds_checks;
  208. #endif
  209. #if WASM_ENABLE_BULK_MEMORY != 0
  210. bh_bitmap *data_dropped;
  211. #endif
  212. #if WASM_ENABLE_REF_TYPES != 0
  213. bh_bitmap *elem_dropped;
  214. #endif
  215. } WASMModuleInstanceExtraCommon;
  216. /* Extra info of WASM module instance for interpreter/jit mode */
  217. typedef struct WASMModuleInstanceExtra {
  218. WASMModuleInstanceExtraCommon common;
  219. WASMGlobalInstance *globals;
  220. WASMFunctionInstance *functions;
  221. uint32 global_count;
  222. uint32 function_count;
  223. WASMFunctionInstance *start_function;
  224. WASMFunctionInstance *malloc_function;
  225. WASMFunctionInstance *free_function;
  226. WASMFunctionInstance *retain_function;
  227. RunningMode running_mode;
  228. #if WASM_ENABLE_MULTI_MODULE != 0
  229. bh_list sub_module_inst_list_head;
  230. bh_list *sub_module_inst_list;
  231. /* linked table instances of import table instances */
  232. WASMTableInstance **table_insts_linked;
  233. #endif
  234. #if WASM_ENABLE_MEMORY_PROFILING != 0
  235. uint32 max_aux_stack_used;
  236. #endif
  237. #if WASM_ENABLE_DEBUG_INTERP != 0 \
  238. || (WASM_ENABLE_FAST_JIT != 0 && WASM_ENABLE_JIT != 0 \
  239. && WASM_ENABLE_LAZY_JIT != 0)
  240. WASMModuleInstance *next;
  241. #endif
  242. } WASMModuleInstanceExtra;
  243. struct AOTFuncPerfProfInfo;
  244. struct WASMModuleInstance {
  245. /* Module instance type, for module instance loaded from
  246. WASM bytecode binary, this field is Wasm_Module_Bytecode;
  247. for module instance loaded from AOT file, this field is
  248. Wasm_Module_AoT, and this structure should be treated as
  249. AOTModuleInstance structure. */
  250. uint32 module_type;
  251. uint32 memory_count;
  252. DefPointer(WASMMemoryInstance **, memories);
  253. /* global and table info */
  254. uint32 global_data_size;
  255. uint32 table_count;
  256. DefPointer(uint8 *, global_data);
  257. /* For AOTModuleInstance, it denotes `AOTTableInstance *` */
  258. DefPointer(WASMTableInstance **, tables);
  259. /* import func ptrs + llvm jit func ptrs */
  260. DefPointer(void **, func_ptrs);
  261. /* function type indexes */
  262. DefPointer(uint32 *, func_type_indexes);
  263. uint32 export_func_count;
  264. uint32 export_global_count;
  265. uint32 export_memory_count;
  266. uint32 export_table_count;
  267. /* For AOTModuleInstance, it denotes `AOTFunctionInstance *` */
  268. DefPointer(WASMExportFuncInstance *, export_functions);
  269. DefPointer(WASMExportGlobInstance *, export_globals);
  270. DefPointer(WASMExportMemInstance *, export_memories);
  271. DefPointer(WASMExportTabInstance *, export_tables);
  272. /* The exception buffer of wasm interpreter for current thread. */
  273. char cur_exception[EXCEPTION_BUF_LEN];
  274. /* The WASM module or AOT module, for AOTModuleInstance,
  275. it denotes `AOTModule *` */
  276. DefPointer(WASMModule *, module);
  277. DefPointer(void *, used_to_be_wasi_ctx); /* unused */
  278. DefPointer(WASMExecEnv *, exec_env_singleton);
  279. /* Array of function pointers to import functions,
  280. not available in AOTModuleInstance */
  281. DefPointer(void **, import_func_ptrs);
  282. /* Array of function pointers to fast jit functions,
  283. not available in AOTModuleInstance:
  284. Only when the multi-tier JIT macros are all enabled and the running
  285. mode of current module instance is set to Mode_Fast_JIT, runtime
  286. will allocate new memory for it, otherwise it always points to the
  287. module->fast_jit_func_ptrs */
  288. DefPointer(void **, fast_jit_func_ptrs);
  289. /* The custom data that can be set/get by wasm_{get|set}_custom_data */
  290. DefPointer(void *, custom_data);
  291. /* Stack frames, used in call stack dump and perf profiling */
  292. DefPointer(Vector *, frames);
  293. /* Function performance profiling info list, only available
  294. in AOTModuleInstance */
  295. DefPointer(struct AOTFuncPerfProfInfo *, func_perf_profilings);
  296. /* WASM/AOT module extra info, for AOTModuleInstance,
  297. it denotes `AOTModuleInstanceExtra *` */
  298. DefPointer(WASMModuleInstanceExtra *, e);
  299. /* Default WASM operand stack size */
  300. uint32 default_wasm_stack_size;
  301. uint32 reserved[3];
  302. /*
  303. * +------------------------------+ <-- memories
  304. * | WASMMemoryInstance[mem_count], mem_count is always 1 for LLVM JIT/AOT
  305. * +------------------------------+ <-- global_data
  306. * | global data
  307. * +------------------------------+ <-- tables
  308. * | WASMTableInstance[table_count]
  309. * +------------------------------+ <-- e
  310. * | WASMModuleInstanceExtra
  311. * +------------------------------+
  312. */
  313. union {
  314. uint64 _make_it_8_byte_aligned_;
  315. WASMMemoryInstance memory_instances[1];
  316. uint8 bytes[1];
  317. } global_table_data;
  318. };
  319. struct WASMInterpFrame;
  320. typedef struct WASMInterpFrame WASMRuntimeFrame;
  321. #if WASM_ENABLE_MULTI_MODULE != 0
  322. typedef struct WASMSubModInstNode {
  323. bh_list_link l;
  324. /* point to a string pool */
  325. const char *module_name;
  326. WASMModuleInstance *module_inst;
  327. } WASMSubModInstNode;
  328. #endif
  329. /**
  330. * Return the code block of a function.
  331. *
  332. * @param func the WASM function instance
  333. *
  334. * @return the code block of the function
  335. */
  336. static inline uint8 *
  337. wasm_get_func_code(WASMFunctionInstance *func)
  338. {
  339. #if WASM_ENABLE_FAST_INTERP == 0
  340. return func->is_import_func ? NULL : func->u.func->code;
  341. #else
  342. return func->is_import_func ? NULL : func->u.func->code_compiled;
  343. #endif
  344. }
  345. /**
  346. * Return the code block end of a function.
  347. *
  348. * @param func the WASM function instance
  349. *
  350. * @return the code block end of the function
  351. */
  352. static inline uint8 *
  353. wasm_get_func_code_end(WASMFunctionInstance *func)
  354. {
  355. #if WASM_ENABLE_FAST_INTERP == 0
  356. return func->is_import_func ? NULL
  357. : func->u.func->code + func->u.func->code_size;
  358. #else
  359. return func->is_import_func
  360. ? NULL
  361. : func->u.func->code_compiled + func->u.func->code_compiled_size;
  362. #endif
  363. }
  364. WASMModule *
  365. wasm_load(uint8 *buf, uint32 size,
  366. #if WASM_ENABLE_MULTI_MODULE != 0
  367. bool main_module,
  368. #endif
  369. char *error_buf, uint32 error_buf_size);
  370. WASMModule *
  371. wasm_load_from_sections(WASMSection *section_list, char *error_buf,
  372. uint32 error_buf_size);
  373. void
  374. wasm_unload(WASMModule *module);
  375. WASMModuleInstance *
  376. wasm_instantiate(WASMModule *module, WASMModuleInstance *parent,
  377. WASMExecEnv *exec_env_main, uint32 stack_size,
  378. uint32 heap_size, char *error_buf, uint32 error_buf_size);
  379. void
  380. wasm_dump_perf_profiling(const WASMModuleInstance *module_inst);
  381. double
  382. wasm_summarize_wasm_execute_time(const WASMModuleInstance *inst);
  383. double
  384. wasm_get_wasm_func_exec_time(const WASMModuleInstance *inst,
  385. const char *func_name);
  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
  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, uint32 init_val);
  487. #endif /* WASM_ENABLE_REF_TYPES != 0 */
  488. static inline WASMTableInstance *
  489. wasm_get_table_inst(const WASMModuleInstance *module_inst, uint32 tbl_idx)
  490. {
  491. /* careful, it might be a table in another module */
  492. WASMTableInstance *tbl_inst = module_inst->tables[tbl_idx];
  493. #if WASM_ENABLE_MULTI_MODULE != 0
  494. if (tbl_idx < module_inst->module->import_table_count
  495. && module_inst->e->table_insts_linked[tbl_idx]) {
  496. tbl_inst = module_inst->e->table_insts_linked[tbl_idx];
  497. }
  498. #endif
  499. bh_assert(tbl_inst);
  500. return tbl_inst;
  501. }
  502. #if WASM_ENABLE_DUMP_CALL_STACK != 0
  503. bool
  504. wasm_interp_create_call_stack(struct WASMExecEnv *exec_env);
  505. /**
  506. * @brief Dump wasm call stack or get the size
  507. *
  508. * @param exec_env the execution environment
  509. * @param print whether to print to stdout or not
  510. * @param buf buffer to store the dumped content
  511. * @param len length of the buffer
  512. *
  513. * @return when print is true, return the bytes printed out to stdout; when
  514. * print is false and buf is NULL, return the size required to store the
  515. * callstack content; when print is false and buf is not NULL, return the size
  516. * dumped to the buffer, 0 means error and data in buf may be invalid
  517. */
  518. uint32
  519. wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env, bool print, char *buf,
  520. uint32 len);
  521. #endif
  522. const uint8 *
  523. wasm_loader_get_custom_section(WASMModule *module, const char *name,
  524. uint32 *len);
  525. #if WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 \
  526. || WASM_ENABLE_WAMR_COMPILER != 0
  527. void
  528. jit_set_exception_with_id(WASMModuleInstance *module_inst, uint32 id);
  529. /**
  530. * Check whether the app address and the buf is inside the linear memory,
  531. * and convert the app address into native address
  532. */
  533. bool
  534. jit_check_app_addr_and_convert(WASMModuleInstance *module_inst, bool is_str,
  535. uint32 app_buf_addr, uint32 app_buf_size,
  536. void **p_native_addr);
  537. #endif /* end of WASM_ENABLE_FAST_JIT != 0 || WASM_ENABLE_JIT != 0 \
  538. || WASM_ENABLE_WAMR_COMPILER != 0 */
  539. #if WASM_ENABLE_FAST_JIT != 0
  540. bool
  541. fast_jit_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 elem_idx,
  542. uint32 type_idx, uint32 argc, uint32 *argv);
  543. bool
  544. fast_jit_invoke_native(WASMExecEnv *exec_env, uint32 func_idx,
  545. struct WASMInterpFrame *prev_frame);
  546. #endif
  547. #if WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0
  548. bool
  549. llvm_jit_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 elem_idx,
  550. uint32 argc, uint32 *argv);
  551. bool
  552. llvm_jit_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
  553. uint32 *argv);
  554. #if WASM_ENABLE_BULK_MEMORY != 0
  555. bool
  556. llvm_jit_memory_init(WASMModuleInstance *module_inst, uint32 seg_index,
  557. uint32 offset, uint32 len, uint32 dst);
  558. bool
  559. llvm_jit_data_drop(WASMModuleInstance *module_inst, uint32 seg_index);
  560. #endif
  561. #if WASM_ENABLE_REF_TYPES != 0
  562. void
  563. llvm_jit_drop_table_seg(WASMModuleInstance *module_inst, uint32 tbl_seg_idx);
  564. void
  565. llvm_jit_table_init(WASMModuleInstance *module_inst, uint32 tbl_idx,
  566. uint32 tbl_seg_idx, uint32 length, uint32 src_offset,
  567. uint32 dst_offset);
  568. void
  569. llvm_jit_table_copy(WASMModuleInstance *module_inst, uint32 src_tbl_idx,
  570. uint32 dst_tbl_idx, uint32 length, uint32 src_offset,
  571. uint32 dst_offset);
  572. void
  573. llvm_jit_table_fill(WASMModuleInstance *module_inst, uint32 tbl_idx,
  574. uint32 length, uint32 val, uint32 data_offset);
  575. uint32
  576. llvm_jit_table_grow(WASMModuleInstance *module_inst, uint32 tbl_idx,
  577. uint32 inc_entries, uint32 init_val);
  578. #endif
  579. #if WASM_ENABLE_DUMP_CALL_STACK != 0 || WASM_ENABLE_PERF_PROFILING != 0
  580. bool
  581. llvm_jit_alloc_frame(WASMExecEnv *exec_env, uint32 func_index);
  582. void
  583. llvm_jit_free_frame(WASMExecEnv *exec_env);
  584. #endif
  585. #endif /* end of WASM_ENABLE_JIT != 0 || WASM_ENABLE_WAMR_COMPILER != 0 */
  586. #if WASM_ENABLE_LIBC_WASI != 0 && WASM_ENABLE_MULTI_MODULE != 0
  587. void
  588. wasm_propagate_wasi_args(WASMModule *module);
  589. #endif
  590. #if WASM_ENABLE_THREAD_MGR != 0
  591. void
  592. exception_lock(WASMModuleInstance *module_inst);
  593. void
  594. exception_unlock(WASMModuleInstance *module_inst);
  595. #else
  596. #define exception_lock(module_inst) (void)(module_inst)
  597. #define exception_unlock(module_inst) (void)(module_inst)
  598. #endif
  599. #ifdef __cplusplus
  600. }
  601. #endif
  602. #endif /* end of _WASM_RUNTIME_H */