aot_runtime.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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_GC != 0
  12. #include "gc_export.h"
  13. #endif
  14. #if WASM_ENABLE_WASI_NN != 0
  15. #include "../libraries/wasi-nn/src/wasi_nn_private.h"
  16. #endif
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /* Wasm feature supported, mainly used by AOTTargetInfo now */
  21. #define WASM_FEATURE_SIMD_128BIT (1 << 0)
  22. #define WASM_FEATURE_BULK_MEMORY (1 << 1)
  23. #define WASM_FEATURE_THREADS (1 << 2)
  24. #define WASM_FEATURE_REF_TYPES (1 << 3)
  25. #define WASM_FEATURE_TAIL_CALL (1 << 4)
  26. #define WASM_FEATURE_EXCEPTION_HANDLING (1 << 5)
  27. #define WASM_FEATURE_GARBAGE_COLLECTION (1 << 6)
  28. #define WASM_FEATURE_COMPONENT_MODEL (1 << 7)
  29. #define WASM_FEATURE_MULTIPLE_MEMORY (1 << 8)
  30. #define WASM_FEATURE_RELAXED_SIMD (1 << 9)
  31. #define WASM_FEATURE_FLEXIBLE_VECTORS (1 << 10)
  32. #define WASM_FEATURE_STRING_REF (1 << 11)
  33. typedef enum AOTSectionType {
  34. AOT_SECTION_TYPE_TARGET_INFO = 0,
  35. AOT_SECTION_TYPE_INIT_DATA = 1,
  36. AOT_SECTION_TYPE_TEXT = 2,
  37. AOT_SECTION_TYPE_FUNCTION = 3,
  38. AOT_SECTION_TYPE_EXPORT = 4,
  39. AOT_SECTION_TYPE_RELOCATION = 5,
  40. AOT_SECTION_TYPE_SIGANATURE = 6,
  41. AOT_SECTION_TYPE_CUSTOM = 100,
  42. } AOTSectionType;
  43. typedef enum AOTCustomSectionType {
  44. AOT_CUSTOM_SECTION_RAW = 0,
  45. AOT_CUSTOM_SECTION_NATIVE_SYMBOL = 1,
  46. AOT_CUSTOM_SECTION_ACCESS_CONTROL = 2,
  47. AOT_CUSTOM_SECTION_NAME = 3,
  48. } AOTCustomSectionType;
  49. typedef struct AOTObjectDataSection {
  50. char *name;
  51. uint8 *data;
  52. uint32 size;
  53. #if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
  54. bool is_name_allocated;
  55. bool is_data_allocated;
  56. #endif
  57. } AOTObjectDataSection;
  58. /* Relocation info */
  59. typedef struct AOTRelocation {
  60. uint64 relocation_offset;
  61. int64 relocation_addend;
  62. uint32 relocation_type;
  63. char *symbol_name;
  64. /* index in the symbol offset field */
  65. uint32 symbol_index;
  66. #if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
  67. bool is_symbol_name_allocated;
  68. #endif
  69. } AOTRelocation;
  70. /* Relocation Group */
  71. typedef struct AOTRelocationGroup {
  72. char *section_name;
  73. /* index in the symbol offset field */
  74. uint32 name_index;
  75. uint32 relocation_count;
  76. AOTRelocation *relocations;
  77. #if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
  78. bool is_section_name_allocated;
  79. #endif
  80. } AOTRelocationGroup;
  81. /* AOT function instance */
  82. typedef struct AOTFunctionInstance {
  83. char *func_name;
  84. uint32 func_index;
  85. bool is_import_func;
  86. union {
  87. struct {
  88. AOTFuncType *func_type;
  89. /* function pointer linked */
  90. void *func_ptr;
  91. } func;
  92. AOTImportFunc *func_import;
  93. } u;
  94. } AOTFunctionInstance;
  95. typedef struct AOTModuleInstanceExtra {
  96. DefPointer(const uint32 *, stack_sizes);
  97. CApiFuncImport *c_api_func_imports;
  98. #if WASM_CONFIGUABLE_BOUNDS_CHECKS != 0
  99. /* Disable bounds checks or not */
  100. bool disable_bounds_checks;
  101. #endif
  102. } AOTModuleInstanceExtra;
  103. #if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
  104. /* clang-format off */
  105. typedef struct AOTUnwindInfo {
  106. uint8 Version : 3;
  107. uint8 Flags : 5;
  108. uint8 SizeOfProlog;
  109. uint8 CountOfCodes;
  110. uint8 FrameRegister : 4;
  111. uint8 FrameOffset : 4;
  112. struct {
  113. struct {
  114. uint8 CodeOffset;
  115. uint8 UnwindOp : 4;
  116. uint8 OpInfo : 4;
  117. };
  118. uint16 FrameOffset;
  119. } UnwindCode[1];
  120. } AOTUnwindInfo;
  121. /* clang-format on */
  122. /* size of mov instruction and jmp instruction */
  123. #define PLT_ITEM_SIZE 12
  124. #endif
  125. #if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
  126. typedef struct GOTItem {
  127. uint32 func_idx;
  128. struct GOTItem *next;
  129. } GOTItem, *GOTItemList;
  130. #endif
  131. typedef struct AOTModule {
  132. uint32 module_type;
  133. /* import memories */
  134. uint32 import_memory_count;
  135. AOTImportMemory *import_memories;
  136. /* memory info */
  137. uint32 memory_count;
  138. AOTMemory *memories;
  139. /* init data */
  140. uint32 mem_init_data_count;
  141. AOTMemInitData **mem_init_data_list;
  142. /* native symbol */
  143. void **native_symbol_list;
  144. /* import tables */
  145. uint32 import_table_count;
  146. AOTImportTable *import_tables;
  147. /* tables */
  148. uint32 table_count;
  149. AOTTable *tables;
  150. /* table init data info */
  151. uint32 table_init_data_count;
  152. AOTTableInitData **table_init_data_list;
  153. /* type info */
  154. uint32 type_count;
  155. AOTType **types;
  156. /* import global variable info */
  157. uint32 import_global_count;
  158. AOTImportGlobal *import_globals;
  159. /* global variable info */
  160. uint32 global_count;
  161. AOTGlobal *globals;
  162. /* total global variable size */
  163. uint32 global_data_size;
  164. /* import function info */
  165. uint32 import_func_count;
  166. AOTImportFunc *import_funcs;
  167. /* function info */
  168. uint32 func_count;
  169. /* func pointers of AOTed (un-imported) functions */
  170. void **func_ptrs;
  171. /* func type indexes of AOTed (un-imported) functions */
  172. uint32 *func_type_indexes;
  173. /* export info */
  174. uint32 export_count;
  175. AOTExport *exports;
  176. /* start function index, -1 denotes no start function */
  177. uint32 start_func_index;
  178. /* start function, point to AOTed function */
  179. void *start_function;
  180. uint32 malloc_func_index;
  181. uint32 free_func_index;
  182. uint32 retain_func_index;
  183. /* AOTed code */
  184. void *code;
  185. uint32 code_size;
  186. /* literal for AOTed code */
  187. uint8 *literal;
  188. uint32 literal_size;
  189. #if defined(BH_PLATFORM_WINDOWS)
  190. /* extra plt data area for __ymm, __xmm and __real constants
  191. in Windows platform */
  192. uint8 *extra_plt_data;
  193. uint32 extra_plt_data_size;
  194. uint32 ymm_plt_count;
  195. uint32 xmm_plt_count;
  196. uint32 real_plt_count;
  197. uint32 float_plt_count;
  198. #endif
  199. #if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
  200. /* dynamic function table to be added by RtlAddFunctionTable(),
  201. used to unwind the call stack and register exception handler
  202. for AOT functions */
  203. RUNTIME_FUNCTION *rtl_func_table;
  204. bool rtl_func_table_registered;
  205. #endif
  206. #if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
  207. uint32 got_item_count;
  208. GOTItemList got_item_list;
  209. GOTItemList got_item_list_end;
  210. void **got_func_ptrs;
  211. #endif
  212. /* data sections in AOT object file, including .data, .rodata
  213. and .rodata.cstN. */
  214. AOTObjectDataSection *data_sections;
  215. uint32 data_section_count;
  216. /* constant string set */
  217. HashMap *const_str_set;
  218. /* the index of auxiliary __data_end global,
  219. -1 means unexported */
  220. uint32 aux_data_end_global_index;
  221. /* auxiliary __data_end exported by wasm app */
  222. uint32 aux_data_end;
  223. /* the index of auxiliary __heap_base global,
  224. -1 means unexported */
  225. uint32 aux_heap_base_global_index;
  226. /* auxiliary __heap_base exported by wasm app */
  227. uint32 aux_heap_base;
  228. /* the index of auxiliary stack top global,
  229. -1 means unexported */
  230. uint32 aux_stack_top_global_index;
  231. /* auxiliary stack bottom resolved */
  232. uint32 aux_stack_bottom;
  233. /* auxiliary stack size resolved */
  234. uint32 aux_stack_size;
  235. /* is indirect mode or not */
  236. bool is_indirect_mode;
  237. #if WASM_ENABLE_LIBC_WASI != 0
  238. WASIArguments wasi_args;
  239. bool import_wasi_api;
  240. #endif
  241. #if WASM_ENABLE_DEBUG_AOT != 0
  242. void *elf_hdr;
  243. uint32 elf_size;
  244. #endif
  245. #if WASM_ENABLE_CUSTOM_NAME_SECTION != 0
  246. const char **aux_func_names;
  247. uint32 *aux_func_indexes;
  248. uint32 aux_func_name_count;
  249. #endif
  250. #if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
  251. WASMCustomSection *custom_section_list;
  252. #endif
  253. } AOTModule;
  254. #define AOTMemoryInstance WASMMemoryInstance
  255. #define AOTTableInstance WASMTableInstance
  256. #define AOTModuleInstance WASMModuleInstance
  257. /* Target info, read from ELF header of object file */
  258. typedef struct AOTTargetInfo {
  259. /* Binary type, elf32l/elf32b/elf64l/elf64b */
  260. uint16 bin_type;
  261. /* ABI type */
  262. uint16 abi_type;
  263. /* Object file type */
  264. uint16 e_type;
  265. /* Architecture */
  266. uint16 e_machine;
  267. /* Object file version */
  268. uint32 e_version;
  269. /* Processor-specific flags */
  270. uint32 e_flags;
  271. /* Specify wasm features supported */
  272. uint64 feature_flags;
  273. /* Reserved */
  274. uint64 reserved;
  275. /* Arch name */
  276. char arch[16];
  277. } AOTTargetInfo;
  278. typedef struct AOTFuncPerfProfInfo {
  279. /* total execution time */
  280. uint64 total_exec_time;
  281. /* total execution count */
  282. uint32 total_exec_cnt;
  283. } AOTFuncPerfProfInfo;
  284. /* AOT auxiliary call stack */
  285. typedef struct AOTFrame {
  286. struct AOTFrame *prev_frame;
  287. uint32 func_index;
  288. #if WASM_ENABLE_PERF_PROFILING != 0
  289. uint64 time_started;
  290. AOTFuncPerfProfInfo *func_perf_prof_info;
  291. #endif
  292. } AOTFrame;
  293. #if WASM_ENABLE_STATIC_PGO != 0
  294. typedef struct LLVMProfileRawHeader {
  295. uint64 magic;
  296. uint64 version;
  297. uint64 binary_ids_size;
  298. uint64 num_prof_data;
  299. uint64 padding_bytes_before_counters;
  300. uint64 num_prof_counters;
  301. uint64 padding_bytes_after_counters;
  302. uint64 names_size;
  303. uint64 counters_delta;
  304. uint64 names_delta;
  305. uint64 value_kind_last;
  306. } LLVMProfileRawHeader;
  307. typedef struct ValueProfNode {
  308. uint64 value;
  309. uint64 count;
  310. struct ValueProfNode *next;
  311. } ValueProfNode;
  312. /* The profiling data of data sections created by aot compiler and
  313. used when profiling, the width of pointer can be 8 bytes (64-bit)
  314. or 4 bytes (32-bit) */
  315. typedef struct LLVMProfileData {
  316. uint64 func_md5;
  317. uint64 func_hash;
  318. uint64 offset_counters;
  319. uintptr_t func_ptr;
  320. ValueProfNode **values;
  321. uint32 num_counters;
  322. uint16 num_value_sites[2];
  323. } LLVMProfileData;
  324. /* The profiling data for writting to the output file, the width of
  325. pointer is 8 bytes suppose we always use wamrc and llvm-profdata
  326. with 64-bit mode */
  327. typedef struct LLVMProfileData_64 {
  328. uint64 func_md5;
  329. uint64 func_hash;
  330. uint64 offset_counters;
  331. uint64 func_ptr;
  332. uint64 values;
  333. uint32 num_counters;
  334. uint16 num_value_sites[2];
  335. } LLVMProfileData_64;
  336. #endif /* end of WASM_ENABLE_STATIC_PGO != 0 */
  337. /**
  338. * Load a AOT module from aot file buffer
  339. * @param buf the byte buffer which contains the AOT file data
  340. * @param size the size of the buffer
  341. * @param error_buf output of the error info
  342. * @param error_buf_size the size of the error string
  343. *
  344. * @return return AOT module loaded, NULL if failed
  345. */
  346. AOTModule *
  347. aot_load_from_aot_file(const uint8 *buf, uint32 size, char *error_buf,
  348. uint32 error_buf_size);
  349. /**
  350. * Load a AOT module from a specified AOT section list.
  351. *
  352. * @param section_list the section list which contains each section data
  353. * @param error_buf output of the error info
  354. * @param error_buf_size the size of the error string
  355. *
  356. * @return return AOT module loaded, NULL if failed
  357. */
  358. AOTModule *
  359. aot_load_from_sections(AOTSection *section_list, char *error_buf,
  360. uint32 error_buf_size);
  361. /**
  362. * Unload a AOT module.
  363. *
  364. * @param module the module to be unloaded
  365. */
  366. void
  367. aot_unload(AOTModule *module);
  368. /**
  369. * Instantiate a AOT module.
  370. *
  371. * @param module the AOT module to instantiate
  372. * @param parent the parent module instance
  373. * @param heap_size the default heap size of the module instance, a heap will
  374. * be created besides the app memory space. Both wasm app and native
  375. * function can allocate memory from the heap. If heap_size is 0, the
  376. * default heap size will be used.
  377. * @param error_buf buffer to output the error info if failed
  378. * @param error_buf_size the size of the error buffer
  379. *
  380. * @return return the instantiated AOT module instance, NULL if failed
  381. */
  382. AOTModuleInstance *
  383. aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
  384. WASMExecEnv *exec_env_main, uint32 stack_size, uint32 heap_size,
  385. char *error_buf, uint32 error_buf_size);
  386. /**
  387. * Deinstantiate a AOT module instance, destroy the resources.
  388. *
  389. * @param module_inst the AOT module instance to destroy
  390. * @param is_sub_inst the flag of sub instance
  391. */
  392. void
  393. aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst);
  394. /**
  395. * Lookup an exported function in the AOT module instance.
  396. *
  397. * @param module_inst the module instance
  398. * @param name the name of the function
  399. * @param signature the signature of the function, use "i32"/"i64"/"f32"/"f64"
  400. * to represent the type of i32/i64/f32/f64, e.g. "(i32i64)" "(i32)f32"
  401. *
  402. * @return the function instance found
  403. */
  404. AOTFunctionInstance *
  405. aot_lookup_function(const AOTModuleInstance *module_inst, const char *name,
  406. const char *signature);
  407. /**
  408. * Call the given AOT function of a AOT module instance with
  409. * arguments.
  410. *
  411. * @param exec_env the execution environment
  412. * @param function the function to be called
  413. * @param argc the number of arguments
  414. * @param argv the arguments. If the function method has return value,
  415. * the first (or first two in case 64-bit return value) element of
  416. * argv stores the return value of the called AOT function after this
  417. * function returns.
  418. *
  419. * @return true if success, false otherwise and exception will be thrown,
  420. * the caller can call aot_get_exception to get exception info.
  421. */
  422. bool
  423. aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
  424. unsigned argc, uint32 argv[]);
  425. /**
  426. * Set AOT module instance exception with exception string
  427. *
  428. * @param module the AOT module instance
  429. *
  430. * @param exception current exception string
  431. */
  432. void
  433. aot_set_exception(AOTModuleInstance *module_inst, const char *exception);
  434. void
  435. aot_set_exception_with_id(AOTModuleInstance *module_inst, uint32 id);
  436. /**
  437. * Get exception info of the AOT module instance.
  438. *
  439. * @param module_inst the AOT module instance
  440. *
  441. * @return the exception string
  442. */
  443. const char *
  444. aot_get_exception(AOTModuleInstance *module_inst);
  445. /**
  446. * @brief Copy exception in buffer passed as parameter. Thread-safe version of
  447. * `aot_get_exception()`
  448. * @note Buffer size must be no smaller than EXCEPTION_BUF_LEN
  449. * @return true if exception found, false otherwise
  450. */
  451. bool
  452. aot_copy_exception(AOTModuleInstance *module_inst, char *exception_buf);
  453. uint32
  454. aot_module_malloc_internal(AOTModuleInstance *module_inst, WASMExecEnv *env,
  455. uint32 size, void **p_native_addr);
  456. uint32
  457. aot_module_realloc_internal(AOTModuleInstance *module_inst, WASMExecEnv *env,
  458. uint32 ptr, uint32 size, void **p_native_addr);
  459. void
  460. aot_module_free_internal(AOTModuleInstance *module_inst, WASMExecEnv *env,
  461. uint32 ptr);
  462. uint32
  463. aot_module_malloc(AOTModuleInstance *module_inst, uint32 size,
  464. void **p_native_addr);
  465. uint32
  466. aot_module_realloc(AOTModuleInstance *module_inst, uint32 ptr, uint32 size,
  467. void **p_native_addr);
  468. void
  469. aot_module_free(AOTModuleInstance *module_inst, uint32 ptr);
  470. uint32
  471. aot_module_dup_data(AOTModuleInstance *module_inst, const char *src,
  472. uint32 size);
  473. bool
  474. aot_enlarge_memory(AOTModuleInstance *module_inst, uint32 inc_page_count);
  475. /**
  476. * Invoke native function from aot code
  477. */
  478. bool
  479. aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
  480. uint32 *argv);
  481. bool
  482. aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
  483. uint32 argc, uint32 *argv);
  484. /**
  485. * Check whether the app address and the buf is inside the linear memory,
  486. * and convert the app address into native address
  487. */
  488. bool
  489. aot_check_app_addr_and_convert(AOTModuleInstance *module_inst, bool is_str,
  490. uint32 app_buf_addr, uint32 app_buf_size,
  491. void **p_native_addr);
  492. uint32
  493. aot_get_plt_table_size();
  494. void *
  495. aot_memmove(void *dest, const void *src, size_t n);
  496. void *
  497. aot_memset(void *s, int c, size_t n);
  498. double
  499. aot_sqrt(double x);
  500. float
  501. aot_sqrtf(float x);
  502. #if WASM_ENABLE_BULK_MEMORY != 0
  503. bool
  504. aot_memory_init(AOTModuleInstance *module_inst, uint32 seg_index, uint32 offset,
  505. uint32 len, uint32 dst);
  506. bool
  507. aot_data_drop(AOTModuleInstance *module_inst, uint32 seg_index);
  508. #endif
  509. #if WASM_ENABLE_THREAD_MGR != 0
  510. bool
  511. aot_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset, uint32 size);
  512. bool
  513. aot_get_aux_stack(WASMExecEnv *exec_env, uint32 *start_offset, uint32 *size);
  514. #endif
  515. void
  516. aot_get_module_mem_consumption(const AOTModule *module,
  517. WASMModuleMemConsumption *mem_conspn);
  518. void
  519. aot_get_module_inst_mem_consumption(const AOTModuleInstance *module_inst,
  520. WASMModuleInstMemConsumption *mem_conspn);
  521. #if WASM_ENABLE_REF_TYPES != 0
  522. void
  523. aot_drop_table_seg(AOTModuleInstance *module_inst, uint32 tbl_seg_idx);
  524. void
  525. aot_table_init(AOTModuleInstance *module_inst, uint32 tbl_idx,
  526. uint32 tbl_seg_idx, uint32 length, uint32 src_offset,
  527. uint32 dst_offset);
  528. void
  529. aot_table_copy(AOTModuleInstance *module_inst, uint32 src_tbl_idx,
  530. uint32 dst_tbl_idx, uint32 length, uint32 src_offset,
  531. uint32 dst_offset);
  532. void
  533. aot_table_fill(AOTModuleInstance *module_inst, uint32 tbl_idx, uint32 length,
  534. table_elem_type_t val, uint32 data_offset);
  535. uint32
  536. aot_table_grow(AOTModuleInstance *module_inst, uint32 tbl_idx,
  537. uint32 inc_entries, table_elem_type_t init_val);
  538. #endif
  539. bool
  540. aot_alloc_frame(WASMExecEnv *exec_env, uint32 func_index);
  541. void
  542. aot_free_frame(WASMExecEnv *exec_env);
  543. bool
  544. aot_create_call_stack(struct WASMExecEnv *exec_env);
  545. /**
  546. * @brief Dump wasm call stack or get the size
  547. *
  548. * @param exec_env the execution environment
  549. * @param print whether to print to stdout or not
  550. * @param buf buffer to store the dumped content
  551. * @param len length of the buffer
  552. *
  553. * @return when print is true, return the bytes printed out to stdout; when
  554. * print is false and buf is NULL, return the size required to store the
  555. * callstack content; when print is false and buf is not NULL, return the size
  556. * dumped to the buffer, 0 means error and data in buf may be invalid
  557. */
  558. uint32
  559. aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len);
  560. void
  561. aot_dump_perf_profiling(const AOTModuleInstance *module_inst);
  562. const uint8 *
  563. aot_get_custom_section(const AOTModule *module, const char *name, uint32 *len);
  564. const void *
  565. aot_get_data_section_addr(AOTModule *module, const char *section_name,
  566. uint32 *p_data_size);
  567. #if WASM_ENABLE_STATIC_PGO != 0
  568. void
  569. llvm_profile_instrument_target(uint64 target_value, void *data,
  570. uint32 counter_idx);
  571. void
  572. llvm_profile_instrument_memop(uint64 target_value, void *data,
  573. uint32 counter_idx);
  574. uint32
  575. aot_get_pgo_prof_data_size(AOTModuleInstance *module_inst);
  576. uint32
  577. aot_dump_pgo_prof_data_to_buf(AOTModuleInstance *module_inst, char *buf,
  578. uint32 len);
  579. void
  580. aot_exchange_uint16(uint8 *p_data);
  581. void
  582. aot_exchange_uint32(uint8 *p_data);
  583. void
  584. aot_exchange_uint64(uint8 *p_data);
  585. #endif /* end of WASM_ENABLE_STATIC_PGO != 0 */
  586. #ifdef __cplusplus
  587. } /* end of extern "C" */
  588. #endif
  589. #endif /* end of _AOT_RUNTIME_H_ */