aot_runtime.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _AOT_RUNTIME_H_
  6. #define _AOT_RUNTIME_H_
  7. #include "bh_platform.h"
  8. #include "../common/wasm_runtime_common.h"
  9. #include "../interpreter/wasm_runtime.h"
  10. #include "../compilation/aot.h"
  11. #if WASM_ENABLE_JIT != 0
  12. #include "../compilation/aot_llvm.h"
  13. #endif
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. typedef enum AOTExceptionID {
  18. EXCE_UNREACHABLE = 0,
  19. EXCE_OUT_OF_MEMORY,
  20. EXCE_OUT_OF_BOUNDS_MEMORY_ACCESS,
  21. EXCE_INTEGER_OVERFLOW,
  22. EXCE_INTEGER_DIVIDE_BY_ZERO,
  23. EXCE_INVALID_CONVERSION_TO_INTEGER,
  24. EXCE_INVALID_FUNCTION_TYPE_INDEX,
  25. EXCE_INVALID_FUNCTION_INDEX,
  26. EXCE_UNDEFINED_ELEMENT,
  27. EXCE_UNINITIALIZED_ELEMENT,
  28. EXCE_CALL_UNLINKED_IMPORT_FUNC,
  29. EXCE_NATIVE_STACK_OVERFLOW,
  30. EXCE_UNALIGNED_ATOMIC,
  31. EXCE_AUX_STACK_OVERFLOW,
  32. EXCE_AUX_STACK_UNDERFLOW,
  33. EXCE_OUT_OF_BOUNDS_TABLE_ACCESS,
  34. EXCE_NUM,
  35. } AOTExceptionID;
  36. typedef enum AOTSectionType {
  37. AOT_SECTION_TYPE_TARGET_INFO = 0,
  38. AOT_SECTION_TYPE_INIT_DATA = 1,
  39. AOT_SECTION_TYPE_TEXT = 2,
  40. AOT_SECTION_TYPE_FUNCTION = 3,
  41. AOT_SECTION_TYPE_EXPORT = 4,
  42. AOT_SECTION_TYPE_RELOCATION = 5,
  43. AOT_SECTION_TYPE_SIGANATURE = 6,
  44. AOT_SECTION_TYPE_CUSTOM = 100,
  45. } AOTSectionType;
  46. typedef enum AOTCustomSectionType {
  47. AOT_CUSTOM_SECTION_RAW = 0,
  48. AOT_CUSTOM_SECTION_NATIVE_SYMBOL = 1,
  49. AOT_CUSTOM_SECTION_ACCESS_CONTROL = 2,
  50. AOT_CUSTOM_SECTION_NAME = 3,
  51. } AOTCustomSectionType;
  52. typedef struct AOTObjectDataSection {
  53. char *name;
  54. uint8 *data;
  55. uint32 size;
  56. } AOTObjectDataSection;
  57. /* Relocation info */
  58. typedef struct AOTRelocation {
  59. uint64 relocation_offset;
  60. int64 relocation_addend;
  61. uint32 relocation_type;
  62. char *symbol_name;
  63. /* index in the symbol offset field */
  64. uint32 symbol_index;
  65. } AOTRelocation;
  66. /* Relocation Group */
  67. typedef struct AOTRelocationGroup {
  68. char *section_name;
  69. /* index in the symbol offset field */
  70. uint32 name_index;
  71. uint32 relocation_count;
  72. AOTRelocation *relocations;
  73. } AOTRelocationGroup;
  74. /* AOT function instance */
  75. typedef struct AOTFunctionInstance {
  76. char *func_name;
  77. uint32 func_index;
  78. bool is_import_func;
  79. union {
  80. struct {
  81. AOTFuncType *func_type;
  82. /* function pointer linked */
  83. void *func_ptr;
  84. } func;
  85. AOTImportFunc *func_import;
  86. } u;
  87. } AOTFunctionInstance;
  88. #if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
  89. /* clang-format off */
  90. typedef struct AOTUnwindInfo {
  91. uint8 Version : 3;
  92. uint8 Flags : 5;
  93. uint8 SizeOfProlog;
  94. uint8 CountOfCodes;
  95. uint8 FrameRegister : 4;
  96. uint8 FrameOffset : 4;
  97. struct {
  98. struct {
  99. uint8 CodeOffset;
  100. uint8 UnwindOp : 4;
  101. uint8 OpInfo : 4;
  102. };
  103. uint16 FrameOffset;
  104. } UnwindCode[1];
  105. } AOTUnwindInfo;
  106. /* clang-format on */
  107. /* size of mov instruction and jmp instruction */
  108. #define PLT_ITEM_SIZE 12
  109. #endif
  110. typedef struct AOTModule {
  111. uint32 module_type;
  112. /* import memories */
  113. uint32 import_memory_count;
  114. AOTImportMemory *import_memories;
  115. /* memory info */
  116. uint32 memory_count;
  117. AOTMemory *memories;
  118. /* init data */
  119. uint32 mem_init_data_count;
  120. AOTMemInitData **mem_init_data_list;
  121. /* native symbol */
  122. void **native_symbol_list;
  123. /* import tables */
  124. uint32 import_table_count;
  125. AOTImportTable *import_tables;
  126. /* tables */
  127. uint32 table_count;
  128. AOTTable *tables;
  129. /* table init data info */
  130. uint32 table_init_data_count;
  131. AOTTableInitData **table_init_data_list;
  132. /* function type info */
  133. uint32 func_type_count;
  134. AOTFuncType **func_types;
  135. /* import global variable info */
  136. uint32 import_global_count;
  137. AOTImportGlobal *import_globals;
  138. /* global variable info */
  139. uint32 global_count;
  140. AOTGlobal *globals;
  141. /* total global variable size */
  142. uint32 global_data_size;
  143. /* import function info */
  144. uint32 import_func_count;
  145. AOTImportFunc *import_funcs;
  146. /* function info */
  147. uint32 func_count;
  148. /* point to AOTed/JITed functions */
  149. void **func_ptrs;
  150. /* function type indexes */
  151. uint32 *func_type_indexes;
  152. /* export info */
  153. uint32 export_count;
  154. AOTExport *exports;
  155. /* start function index, -1 denotes no start function */
  156. uint32 start_func_index;
  157. /* start function, point to AOTed/JITed function */
  158. void *start_function;
  159. uint32 malloc_func_index;
  160. uint32 free_func_index;
  161. uint32 retain_func_index;
  162. /* AOTed code, NULL for JIT mode */
  163. void *code;
  164. uint32 code_size;
  165. /* literal for AOTed code, NULL for JIT mode */
  166. uint8 *literal;
  167. uint32 literal_size;
  168. #if defined(BH_PLATFORM_WINDOWS)
  169. /* extra plt data area for __ymm, __xmm and __real constants
  170. in Windows platform, NULL for JIT mode */
  171. uint8 *extra_plt_data;
  172. uint32 extra_plt_data_size;
  173. uint32 ymm_plt_count;
  174. uint32 xmm_plt_count;
  175. uint32 real_plt_count;
  176. uint32 float_plt_count;
  177. #endif
  178. #if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
  179. /* dynamic function table to be added by RtlAddFunctionTable(),
  180. used to unwind the call stack and register exception handler
  181. for AOT functions */
  182. RUNTIME_FUNCTION *rtl_func_table;
  183. bool rtl_func_table_registered;
  184. #endif
  185. /* data sections in AOT object file, including .data, .rodata
  186. * and .rodata.cstN. NULL for JIT mode. */
  187. AOTObjectDataSection *data_sections;
  188. uint32 data_section_count;
  189. /* constant string set */
  190. HashMap *const_str_set;
  191. /* the index of auxiliary __data_end global,
  192. -1 means unexported */
  193. uint32 aux_data_end_global_index;
  194. /* auxiliary __data_end exported by wasm app */
  195. uint32 aux_data_end;
  196. /* the index of auxiliary __heap_base global,
  197. -1 means unexported */
  198. uint32 aux_heap_base_global_index;
  199. /* auxiliary __heap_base exported by wasm app */
  200. uint32 aux_heap_base;
  201. /* the index of auxiliary stack top global,
  202. -1 means unexported */
  203. uint32 aux_stack_top_global_index;
  204. /* auxiliary stack bottom resolved */
  205. uint32 aux_stack_bottom;
  206. /* auxiliary stack size resolved */
  207. uint32 aux_stack_size;
  208. /* is jit mode or not */
  209. bool is_jit_mode;
  210. /* is indirect mode or not */
  211. bool is_indirect_mode;
  212. #if WASM_ENABLE_JIT != 0
  213. WASMModule *wasm_module;
  214. AOTCompContext *comp_ctx;
  215. AOTCompData *comp_data;
  216. #endif
  217. #if WASM_ENABLE_LIBC_WASI != 0
  218. WASIArguments wasi_args;
  219. bool import_wasi_api;
  220. #endif
  221. #if WASM_ENABLE_DEBUG_AOT != 0
  222. void *elf_hdr;
  223. uint32 elf_size;
  224. #endif
  225. #if WASM_ENABLE_CUSTOM_NAME_SECTION != 0
  226. const char **aux_func_names;
  227. uint32 *aux_func_indexes;
  228. uint32 aux_func_name_count;
  229. #endif
  230. #if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
  231. WASMCustomSection *custom_section_list;
  232. #endif
  233. } AOTModule;
  234. typedef union {
  235. uint64 _make_it_8_bytes_;
  236. void *ptr;
  237. } AOTPointer;
  238. typedef union {
  239. uint64 u64;
  240. uint32 u32[2];
  241. } MemBound;
  242. typedef struct AOTMemoryInstance {
  243. uint32 module_type;
  244. /* shared memory flag */
  245. bool is_shared;
  246. /* memory space info */
  247. uint32 num_bytes_per_page;
  248. uint32 cur_page_count;
  249. uint32 max_page_count;
  250. uint32 memory_data_size;
  251. AOTPointer memory_data;
  252. AOTPointer memory_data_end;
  253. /* heap space info */
  254. AOTPointer heap_data;
  255. AOTPointer heap_data_end;
  256. AOTPointer heap_handle;
  257. /* boundary check constants for aot code */
  258. MemBound mem_bound_check_1byte;
  259. MemBound mem_bound_check_2bytes;
  260. MemBound mem_bound_check_4bytes;
  261. MemBound mem_bound_check_8bytes;
  262. MemBound mem_bound_check_16bytes;
  263. } AOTMemoryInstance;
  264. typedef struct AOTTableInstance {
  265. uint32 cur_size;
  266. /*
  267. * only grow in the range of [:max_size)
  268. * if the table is growable, max_size equals to its declared maximum size
  269. * otherwise, max_size equals to its declared minimum size
  270. */
  271. uint32 max_size;
  272. /*
  273. * +------------------------------+ <--- data
  274. * | ref.func[] or ref.extern[]
  275. * +------------------------------+
  276. */
  277. uint32 data[1];
  278. } AOTTableInstance;
  279. typedef struct AOTModuleInstance {
  280. uint32 module_type;
  281. /* memories */
  282. uint32 memory_count;
  283. AOTPointer memories;
  284. /* global and table info */
  285. uint32 global_data_size;
  286. /*
  287. * the count of AOTTableInstance.
  288. * it includes imported tables and local tables.
  289. *
  290. * TODO: for now we treate imported table like a local table
  291. */
  292. uint32 table_count;
  293. /* points to global_data */
  294. AOTPointer global_data;
  295. /* points to AOTTableInstance[] */
  296. AOTPointer tables;
  297. /* function pointer array */
  298. AOTPointer func_ptrs;
  299. /* function type indexes */
  300. AOTPointer func_type_indexes;
  301. /* export info */
  302. uint32 export_func_count;
  303. uint32 export_global_count;
  304. uint32 export_mem_count;
  305. uint32 export_tab_count;
  306. AOTPointer export_funcs;
  307. AOTPointer export_globals;
  308. AOTPointer export_memories;
  309. AOTPointer export_tables;
  310. /* The exception buffer for current thread. */
  311. char cur_exception[128];
  312. /* The custom data that can be set/get by
  313. * wasm_runtime_set_custom_data/wasm_runtime_get_custom_data */
  314. AOTPointer custom_data;
  315. /* The AOT module */
  316. AOTPointer aot_module;
  317. /* WASI context */
  318. AOTPointer wasi_ctx;
  319. /* function performance profiling info list */
  320. AOTPointer func_perf_profilings;
  321. /* stack frames, used in call stack dump and perf profiling */
  322. AOTPointer frames;
  323. AOTPointer exec_env_singleton;
  324. uint32 default_wasm_stack_size;
  325. /* reserved */
  326. uint32 reserved[9];
  327. /*
  328. * +------------------------------+ <-- memories.ptr
  329. * | #0 AOTMemoryInstance
  330. * +------------------------------+ <-- global_data.ptr
  331. * | global data
  332. * +------------------------------+ <-- tables.ptr
  333. * | AOTTableInstance[table_count]
  334. * +------------------------------+
  335. */
  336. union {
  337. uint64 _make_it_8_byte_aligned_;
  338. AOTMemoryInstance memory_instances[1];
  339. uint8 bytes[1];
  340. } global_table_data;
  341. } AOTModuleInstance;
  342. /* Target info, read from ELF header of object file */
  343. typedef struct AOTTargetInfo {
  344. /* Binary type, elf32l/elf32b/elf64l/elf64b */
  345. uint16 bin_type;
  346. /* ABI type */
  347. uint16 abi_type;
  348. /* Object file type */
  349. uint16 e_type;
  350. /* Architecture */
  351. uint16 e_machine;
  352. /* Object file version */
  353. uint32 e_version;
  354. /* Processor-specific flags */
  355. uint32 e_flags;
  356. /* Reserved */
  357. uint32 reserved;
  358. /* Arch name */
  359. char arch[16];
  360. } AOTTargetInfo;
  361. typedef struct AOTFuncPerfProfInfo {
  362. /* total execution time */
  363. uint64 total_exec_time;
  364. /* total execution count */
  365. uint32 total_exec_cnt;
  366. } AOTFuncPerfProfInfo;
  367. /* AOT auxiliary call stack */
  368. typedef struct AOTFrame {
  369. struct AOTFrame *prev_frame;
  370. uint32 func_index;
  371. #if WASM_ENABLE_PERF_PROFILING != 0
  372. uint64 time_started;
  373. AOTFuncPerfProfInfo *func_perf_prof_info;
  374. #endif
  375. } AOTFrame;
  376. /**
  377. * Load a AOT module from aot file buffer
  378. * @param buf the byte buffer which contains the AOT file data
  379. * @param size the size of the buffer
  380. * @param error_buf output of the error info
  381. * @param error_buf_size the size of the error string
  382. *
  383. * @return return AOT module loaded, NULL if failed
  384. */
  385. AOTModule *
  386. aot_load_from_aot_file(const uint8 *buf, uint32 size, char *error_buf,
  387. uint32 error_buf_size);
  388. /**
  389. * Load a AOT module from a specified AOT section list.
  390. *
  391. * @param section_list the section list which contains each section data
  392. * @param error_buf output of the error info
  393. * @param error_buf_size the size of the error string
  394. *
  395. * @return return AOT module loaded, NULL if failed
  396. */
  397. AOTModule *
  398. aot_load_from_sections(AOTSection *section_list, char *error_buf,
  399. uint32 error_buf_size);
  400. #if WASM_ENABLE_JIT != 0
  401. /**
  402. * Convert WASM module to AOT module
  403. *
  404. * @param wasm_module the WASM module to convert
  405. * @param error_buf output of the error info
  406. * @param error_buf_size the size of the error string
  407. *
  408. * @return return AOT module loaded, NULL if failed
  409. */
  410. AOTModule *
  411. aot_convert_wasm_module(WASMModule *wasm_module, char *error_buf,
  412. uint32 error_buf_size);
  413. #endif
  414. /**
  415. * Unload a AOT module.
  416. *
  417. * @param module the module to be unloaded
  418. */
  419. void
  420. aot_unload(AOTModule *module);
  421. /**
  422. * Instantiate a AOT module.
  423. *
  424. * @param module the AOT module to instantiate
  425. * @param is_sub_inst the flag of sub instance
  426. * @param heap_size the default heap size of the module instance, a heap will
  427. * be created besides the app memory space. Both wasm app and native
  428. * function can allocate memory from the heap. If heap_size is 0, the
  429. * default heap size will be used.
  430. * @param error_buf buffer to output the error info if failed
  431. * @param error_buf_size the size of the error buffer
  432. *
  433. * @return return the instantiated AOT module instance, NULL if failed
  434. */
  435. AOTModuleInstance *
  436. aot_instantiate(AOTModule *module, bool is_sub_inst, uint32 stack_size,
  437. uint32 heap_size, char *error_buf, uint32 error_buf_size);
  438. /**
  439. * Deinstantiate a AOT module instance, destroy the resources.
  440. *
  441. * @param module_inst the AOT module instance to destroy
  442. * @param is_sub_inst the flag of sub instance
  443. */
  444. void
  445. aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst);
  446. /**
  447. * Lookup an exported function in the AOT module instance.
  448. *
  449. * @param module_inst the module instance
  450. * @param name the name of the function
  451. * @param signature the signature of the function, use "i32"/"i64"/"f32"/"f64"
  452. * to represent the type of i32/i64/f32/f64, e.g. "(i32i64)" "(i32)f32"
  453. *
  454. * @return the function instance found
  455. */
  456. AOTFunctionInstance *
  457. aot_lookup_function(const AOTModuleInstance *module_inst, const char *name,
  458. const char *signature);
  459. /**
  460. * Call the given AOT function of a AOT module instance with
  461. * arguments.
  462. *
  463. * @param exec_env the execution environment
  464. * @param function the function to be called
  465. * @param argc the number of arguments
  466. * @param argv the arguments. If the function method has return value,
  467. * the first (or first two in case 64-bit return value) element of
  468. * argv stores the return value of the called AOT function after this
  469. * function returns.
  470. *
  471. * @return true if success, false otherwise and exception will be thrown,
  472. * the caller can call aot_get_exception to get exception info.
  473. */
  474. bool
  475. aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
  476. unsigned argc, uint32 argv[]);
  477. bool
  478. aot_create_exec_env_and_call_function(AOTModuleInstance *module_inst,
  479. AOTFunctionInstance *function,
  480. unsigned argc, uint32 argv[]);
  481. bool
  482. aot_create_exec_env_singleton(AOTModuleInstance *module_inst);
  483. /**
  484. * Set AOT module instance exception with exception string
  485. *
  486. * @param module the AOT module instance
  487. *
  488. * @param exception current exception string
  489. */
  490. void
  491. aot_set_exception(AOTModuleInstance *module_inst, const char *exception);
  492. void
  493. aot_set_exception_with_id(AOTModuleInstance *module_inst, uint32 id);
  494. /**
  495. * Get exception info of the AOT module instance.
  496. *
  497. * @param module_inst the AOT module instance
  498. *
  499. * @return the exception string
  500. */
  501. const char *
  502. aot_get_exception(AOTModuleInstance *module_inst);
  503. /**
  504. * Clear exception info of the AOT module instance.
  505. *
  506. * @param module_inst the AOT module instance
  507. */
  508. void
  509. aot_clear_exception(AOTModuleInstance *module_inst);
  510. uint32
  511. aot_module_malloc(AOTModuleInstance *module_inst, uint32 size,
  512. void **p_native_addr);
  513. uint32
  514. aot_module_realloc(AOTModuleInstance *module_inst, uint32 ptr, uint32 size,
  515. void **p_native_addr);
  516. void
  517. aot_module_free(AOTModuleInstance *module_inst, uint32 ptr);
  518. uint32
  519. aot_module_dup_data(AOTModuleInstance *module_inst, const char *src,
  520. uint32 size);
  521. bool
  522. aot_validate_app_addr(AOTModuleInstance *module_inst, uint32 app_offset,
  523. uint32 size);
  524. bool
  525. aot_validate_native_addr(AOTModuleInstance *module_inst, void *native_ptr,
  526. uint32 size);
  527. void *
  528. aot_addr_app_to_native(AOTModuleInstance *module_inst, uint32 app_offset);
  529. uint32
  530. aot_addr_native_to_app(AOTModuleInstance *module_inst, void *native_ptr);
  531. bool
  532. aot_get_app_addr_range(AOTModuleInstance *module_inst, uint32 app_offset,
  533. uint32 *p_app_start_offset, uint32 *p_app_end_offset);
  534. bool
  535. aot_get_native_addr_range(AOTModuleInstance *module_inst, uint8 *native_ptr,
  536. uint8 **p_native_start_addr,
  537. uint8 **p_native_end_addr);
  538. bool
  539. aot_enlarge_memory(AOTModuleInstance *module_inst, uint32 inc_page_count);
  540. /**
  541. * Invoke native function from aot code
  542. */
  543. bool
  544. aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
  545. uint32 *argv);
  546. bool
  547. aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
  548. uint32 argc, uint32 *argv);
  549. bool
  550. aot_check_app_addr_and_convert(AOTModuleInstance *module_inst, bool is_str,
  551. uint32 app_buf_addr, uint32 app_buf_size,
  552. void **p_native_addr);
  553. uint32
  554. aot_get_plt_table_size();
  555. void *
  556. aot_memmove(void *dest, const void *src, size_t n);
  557. void *
  558. aot_memset(void *s, int c, size_t n);
  559. #if WASM_ENABLE_BULK_MEMORY != 0
  560. bool
  561. aot_memory_init(AOTModuleInstance *module_inst, uint32 seg_index, uint32 offset,
  562. uint32 len, uint32 dst);
  563. bool
  564. aot_data_drop(AOTModuleInstance *module_inst, uint32 seg_index);
  565. #endif
  566. #if WASM_ENABLE_THREAD_MGR != 0
  567. bool
  568. aot_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset, uint32 size);
  569. bool
  570. aot_get_aux_stack(WASMExecEnv *exec_env, uint32 *start_offset, uint32 *size);
  571. #endif
  572. #ifdef OS_ENABLE_HW_BOUND_CHECK
  573. #ifndef BH_PLATFORM_WINDOWS
  574. void
  575. aot_signal_handler(WASMSignalInfo *sig_info);
  576. #else
  577. LONG
  578. aot_exception_handler(WASMSignalInfo *sig_info);
  579. #endif
  580. #endif
  581. void
  582. aot_get_module_mem_consumption(const AOTModule *module,
  583. WASMModuleMemConsumption *mem_conspn);
  584. void
  585. aot_get_module_inst_mem_consumption(const AOTModuleInstance *module_inst,
  586. WASMModuleInstMemConsumption *mem_conspn);
  587. #if WASM_ENABLE_REF_TYPES != 0
  588. void
  589. aot_drop_table_seg(AOTModuleInstance *module_inst, uint32 tbl_seg_idx);
  590. void
  591. aot_table_init(AOTModuleInstance *module_inst, uint32 tbl_idx,
  592. uint32 tbl_seg_idx, uint32 length, uint32 src_offset,
  593. uint32 dst_offset);
  594. void
  595. aot_table_copy(AOTModuleInstance *module_inst, uint32 src_tbl_idx,
  596. uint32 dst_tbl_idx, uint32 length, uint32 src_offset,
  597. uint32 dst_offset);
  598. void
  599. aot_table_fill(AOTModuleInstance *module_inst, uint32 tbl_idx, uint32 length,
  600. uint32 val, uint32 data_offset);
  601. uint32
  602. aot_table_grow(AOTModuleInstance *module_inst, uint32 tbl_idx,
  603. uint32 inc_entries, uint32 init_val);
  604. #endif
  605. AOTTableInstance *
  606. aot_next_tbl_inst(const AOTTableInstance *tbl_inst);
  607. bool
  608. aot_alloc_frame(WASMExecEnv *exec_env, uint32 func_index);
  609. void
  610. aot_free_frame(WASMExecEnv *exec_env);
  611. bool
  612. aot_create_call_stack(struct WASMExecEnv *exec_env);
  613. /**
  614. * @brief Dump wasm call stack or get the size
  615. *
  616. * @param exec_env the execution environment
  617. * @param print whether to print to stdout or not
  618. * @param buf buffer to store the dumped content
  619. * @param len length of the buffer
  620. *
  621. * @return when print is true, return the bytes printed out to stdout; when
  622. * print is false and buf is NULL, return the size required to store the
  623. * callstack content; when print is false and buf is not NULL, return the size
  624. * dumped to the buffer, 0 means error and data in buf may be invalid
  625. */
  626. uint32
  627. aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len);
  628. void
  629. aot_dump_perf_profiling(const AOTModuleInstance *module_inst);
  630. const uint8 *
  631. aot_get_custom_section(const AOTModule *module, const char *name, uint32 *len);
  632. #ifdef __cplusplus
  633. } /* end of extern "C" */
  634. #endif
  635. #endif /* end of _AOT_RUNTIME_H_ */