aot_runtime.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  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. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /* Wasm feature supported, mainly used by AOTTargetInfo now */
  18. #define WASM_FEATURE_SIMD_128BIT (1 << 0)
  19. #define WASM_FEATURE_BULK_MEMORY (1 << 1)
  20. #define WASM_FEATURE_MULTI_THREAD (1 << 2)
  21. #define WASM_FEATURE_REF_TYPES (1 << 3)
  22. #define WASM_FEATURE_GARBAGE_COLLECTION (1 << 4)
  23. #define WASM_FEATURE_EXCEPTION_HANDLING (1 << 5)
  24. #define WASM_FEATURE_MEMORY64 (1 << 6)
  25. #define WASM_FEATURE_MULTI_MEMORY (1 << 7)
  26. #define WASM_FEATURE_DYNAMIC_LINKING (1 << 8)
  27. #define WASM_FEATURE_COMPONENT_MODEL (1 << 9)
  28. #define WASM_FEATURE_RELAXED_SIMD (1 << 10)
  29. #define WASM_FEATURE_FLEXIBLE_VECTORS (1 << 11)
  30. typedef enum AOTSectionType {
  31. AOT_SECTION_TYPE_TARGET_INFO = 0,
  32. AOT_SECTION_TYPE_INIT_DATA = 1,
  33. AOT_SECTION_TYPE_TEXT = 2,
  34. AOT_SECTION_TYPE_FUNCTION = 3,
  35. AOT_SECTION_TYPE_EXPORT = 4,
  36. AOT_SECTION_TYPE_RELOCATION = 5,
  37. AOT_SECTION_TYPE_SIGNATURE = 6,
  38. AOT_SECTION_TYPE_CUSTOM = 100,
  39. } AOTSectionType;
  40. typedef enum AOTCustomSectionType {
  41. AOT_CUSTOM_SECTION_RAW = 0,
  42. AOT_CUSTOM_SECTION_NATIVE_SYMBOL = 1,
  43. AOT_CUSTOM_SECTION_ACCESS_CONTROL = 2,
  44. AOT_CUSTOM_SECTION_NAME = 3,
  45. AOT_CUSTOM_SECTION_STRING_LITERAL = 4,
  46. } AOTCustomSectionType;
  47. typedef struct AOTObjectDataSection {
  48. char *name;
  49. uint8 *data;
  50. uint32 size;
  51. #if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
  52. bool is_name_allocated;
  53. bool is_data_allocated;
  54. #endif
  55. } AOTObjectDataSection;
  56. /* Relocation info */
  57. typedef struct AOTRelocation {
  58. uint64 relocation_offset;
  59. int64 relocation_addend;
  60. uint32 relocation_type;
  61. char *symbol_name;
  62. /* index in the symbol offset field */
  63. uint32 symbol_index;
  64. #if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
  65. bool is_symbol_name_allocated;
  66. #endif
  67. } AOTRelocation;
  68. /* Relocation Group */
  69. typedef struct AOTRelocationGroup {
  70. char *section_name;
  71. /* index in the symbol offset field */
  72. uint32 name_index;
  73. uint32 relocation_count;
  74. AOTRelocation *relocations;
  75. #if WASM_ENABLE_WAMR_COMPILER != 0 || WASM_ENABLE_JIT != 0
  76. bool is_section_name_allocated;
  77. #endif
  78. } AOTRelocationGroup;
  79. /* AOT function instance */
  80. typedef struct AOTFunctionInstance {
  81. char *func_name;
  82. uint32 func_index;
  83. bool is_import_func;
  84. union {
  85. struct {
  86. AOTFuncType *func_type;
  87. /* function pointer linked */
  88. void *func_ptr;
  89. } func;
  90. AOTImportFunc *func_import;
  91. } u;
  92. } AOTFunctionInstance;
  93. typedef struct AOTModuleInstanceExtra {
  94. DefPointer(const uint32 *, stack_sizes);
  95. WASMModuleInstanceExtraCommon common;
  96. AOTFunctionInstance **functions;
  97. uint32 function_count;
  98. #if WASM_ENABLE_MULTI_MODULE != 0
  99. bh_list sub_module_inst_list_head;
  100. bh_list *sub_module_inst_list;
  101. WASMModuleInstanceCommon **import_func_module_insts;
  102. #endif
  103. } AOTModuleInstanceExtra;
  104. #if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
  105. typedef struct GOTItem {
  106. uint32 func_idx;
  107. struct GOTItem *next;
  108. } GOTItem, *GOTItemList;
  109. #endif
  110. #if WASM_ENABLE_GC != 0
  111. typedef struct LocalRefFlag {
  112. uint32 local_ref_flag_cell_num;
  113. uint8 *local_ref_flags;
  114. } LocalRefFlag;
  115. #endif
  116. typedef struct AOTModule {
  117. uint32 module_type;
  118. /* the package version read from the AOT file */
  119. uint32 package_version;
  120. /* import memories */
  121. uint32 import_memory_count;
  122. AOTImportMemory *import_memories;
  123. /* memory info */
  124. uint32 memory_count;
  125. AOTMemory *memories;
  126. /* init data */
  127. uint32 mem_init_data_count;
  128. AOTMemInitData **mem_init_data_list;
  129. /* native symbol */
  130. void **native_symbol_list;
  131. /* import tables */
  132. uint32 import_table_count;
  133. AOTImportTable *import_tables;
  134. /* tables */
  135. uint32 table_count;
  136. AOTTable *tables;
  137. /* table init data info */
  138. uint32 table_init_data_count;
  139. AOTTableInitData **table_init_data_list;
  140. /* type info */
  141. uint32 type_count;
  142. AOTType **types;
  143. /* import global variable info */
  144. uint32 import_global_count;
  145. AOTImportGlobal *import_globals;
  146. /* global variable info */
  147. uint32 global_count;
  148. AOTGlobal *globals;
  149. /* total global variable size */
  150. uint32 global_data_size;
  151. /* import function info */
  152. uint32 import_func_count;
  153. AOTImportFunc *import_funcs;
  154. /* function info */
  155. uint32 func_count;
  156. /* func pointers of AOTed (un-imported) functions */
  157. void **func_ptrs;
  158. /* func type indexes of AOTed (un-imported) functions */
  159. uint32 *func_type_indexes;
  160. #if WASM_ENABLE_AOT_STACK_FRAME != 0
  161. /* max local cell nums of AOTed (un-imported) functions */
  162. uint32 *max_local_cell_nums;
  163. /* max stack cell nums of AOTed (un-imported) functions */
  164. uint32 *max_stack_cell_nums;
  165. #endif
  166. #if WASM_ENABLE_GC != 0
  167. /* params + locals ref flags of (both import and AOTed) functions */
  168. LocalRefFlag *func_local_ref_flags;
  169. #endif
  170. /* export info */
  171. uint32 export_count;
  172. AOTExport *exports;
  173. /* start function index, -1 denotes no start function */
  174. uint32 start_func_index;
  175. /* start function, point to AOTed function */
  176. void *start_function;
  177. uint32 malloc_func_index;
  178. uint32 free_func_index;
  179. uint32 retain_func_index;
  180. /* AOTed code */
  181. void *code;
  182. uint32 code_size;
  183. /* literal for AOTed code */
  184. uint8 *literal;
  185. uint32 literal_size;
  186. #if defined(BH_PLATFORM_WINDOWS)
  187. /* extra plt data area for __ymm, __xmm and __real constants
  188. in Windows platform */
  189. uint8 *extra_plt_data;
  190. uint32 extra_plt_data_size;
  191. uint32 ymm_plt_count;
  192. uint32 xmm_plt_count;
  193. uint32 real_plt_count;
  194. uint32 float_plt_count;
  195. #endif
  196. #if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64)
  197. uint32 got_item_count;
  198. GOTItemList got_item_list;
  199. GOTItemList got_item_list_end;
  200. void **got_func_ptrs;
  201. #endif
  202. /* data sections in AOT object file, including .data, .rodata
  203. and .rodata.cstN. */
  204. AOTObjectDataSection *data_sections;
  205. uint32 data_section_count;
  206. /* constant string set */
  207. HashMap *const_str_set;
  208. /* the index of auxiliary __data_end global,
  209. -1 means unexported */
  210. uint32 aux_data_end_global_index;
  211. /* auxiliary __data_end exported by wasm app */
  212. uint64 aux_data_end;
  213. /* the index of auxiliary __heap_base global,
  214. -1 means unexported */
  215. uint32 aux_heap_base_global_index;
  216. /* auxiliary __heap_base exported by wasm app */
  217. uint64 aux_heap_base;
  218. /* the index of auxiliary stack top global,
  219. -1 means unexported */
  220. uint32 aux_stack_top_global_index;
  221. /* auxiliary stack bottom resolved */
  222. uint64 aux_stack_bottom;
  223. /* auxiliary stack size resolved */
  224. uint32 aux_stack_size;
  225. /* is indirect mode or not */
  226. bool is_indirect_mode;
  227. #if WASM_ENABLE_LIBC_WASI != 0
  228. WASIArguments wasi_args;
  229. bool import_wasi_api;
  230. #endif
  231. #if WASM_ENABLE_MULTI_MODULE != 0
  232. /* TODO: add mutex for mutli-thread? */
  233. bh_list import_module_list_head;
  234. bh_list *import_module_list;
  235. #endif
  236. #if WASM_ENABLE_GC != 0
  237. /* Ref types hash set */
  238. HashMap *ref_type_set;
  239. struct WASMRttType **rtt_types;
  240. korp_mutex rtt_type_lock;
  241. #if WASM_ENABLE_STRINGREF != 0
  242. /* special rtts for stringref types
  243. - stringref
  244. - stringview_wtf8
  245. - stringview_wtf16
  246. - stringview_iter
  247. */
  248. struct WASMRttType *stringref_rtts[4];
  249. uint32 string_literal_count;
  250. uint32 *string_literal_lengths;
  251. const uint8 **string_literal_ptrs;
  252. #endif
  253. #endif
  254. #if WASM_ENABLE_DEBUG_AOT != 0
  255. void *elf_hdr;
  256. uint32 elf_size;
  257. #endif
  258. #if WASM_ENABLE_CUSTOM_NAME_SECTION != 0
  259. const char **aux_func_names;
  260. uint32 *aux_func_indexes;
  261. uint32 aux_func_name_count;
  262. #endif
  263. #if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
  264. WASMCustomSection *custom_section_list;
  265. #endif
  266. /* user defined name */
  267. char *name;
  268. /* Whether the underlying wasm binary buffer can be freed */
  269. bool is_binary_freeable;
  270. } AOTModule;
  271. #define AOTMemoryInstance WASMMemoryInstance
  272. #define AOTTableInstance WASMTableInstance
  273. #define AOTModuleInstance WASMModuleInstance
  274. #if WASM_ENABLE_MULTI_MODULE != 0
  275. #define AOTSubModInstNode WASMSubModInstNode
  276. #endif
  277. /* Target info, read from ELF header of object file */
  278. typedef struct AOTTargetInfo {
  279. /* Binary type, elf32l/elf32b/elf64l/elf64b */
  280. uint16 bin_type;
  281. /* ABI type */
  282. uint16 abi_type;
  283. /* Object file type */
  284. uint16 e_type;
  285. /* Architecture */
  286. uint16 e_machine;
  287. /* Object file version */
  288. uint32 e_version;
  289. /* Processor-specific flags */
  290. uint32 e_flags;
  291. /* Specify wasm features supported */
  292. uint64 feature_flags;
  293. /* Reserved */
  294. uint64 reserved;
  295. /* Arch name */
  296. char arch[16];
  297. } AOTTargetInfo;
  298. typedef struct AOTFuncPerfProfInfo {
  299. /* total execution time */
  300. uint64 total_exec_time;
  301. /* total execution count */
  302. uint32 total_exec_cnt;
  303. /* children execution time */
  304. uint64 children_exec_time;
  305. } AOTFuncPerfProfInfo;
  306. /* AOT auxiliary call stack */
  307. typedef struct AOTFrame {
  308. /* The frame of the caller which is calling current function */
  309. struct AOTFrame *prev_frame;
  310. /* The non-imported function index of current function */
  311. uintptr_t func_index;
  312. /* Used when performance profiling is enabled */
  313. uintptr_t time_started;
  314. /* Used when performance profiling is enabled */
  315. AOTFuncPerfProfInfo *func_perf_prof_info;
  316. /* Instruction pointer: offset to the bytecode array */
  317. uintptr_t ip_offset;
  318. /* Operand stack top pointer of the current frame */
  319. uint32 *sp;
  320. /* Frame ref flags (GC only) */
  321. uint8 *frame_ref;
  322. /**
  323. * Frame data, the layout is:
  324. * local area: parameters and local variables
  325. * stack area: wasm operand stack
  326. * frame ref flags (GC only):
  327. * whether each cell in local and stack area is a GC obj
  328. * currently local's ref flags are stored in AOTModule,
  329. * here we only reserve the padding bytes
  330. */
  331. uint32 lp[1];
  332. } AOTFrame;
  333. #if WASM_ENABLE_STATIC_PGO != 0
  334. typedef struct LLVMProfileRawHeader {
  335. uint64 magic;
  336. uint64 version;
  337. uint64 binary_ids_size;
  338. uint64 num_prof_data;
  339. uint64 padding_bytes_before_counters;
  340. uint64 num_prof_counters;
  341. uint64 padding_bytes_after_counters;
  342. uint64 names_size;
  343. uint64 counters_delta;
  344. uint64 names_delta;
  345. uint64 value_kind_last;
  346. } LLVMProfileRawHeader;
  347. typedef struct ValueProfNode {
  348. uint64 value;
  349. uint64 count;
  350. struct ValueProfNode *next;
  351. } ValueProfNode;
  352. /* The profiling data of data sections created by aot compiler and
  353. used when profiling, the width of pointer can be 8 bytes (64-bit)
  354. or 4 bytes (32-bit) */
  355. typedef struct LLVMProfileData {
  356. uint64 func_md5;
  357. uint64 func_hash;
  358. uint64 offset_counters;
  359. uintptr_t func_ptr;
  360. ValueProfNode **values;
  361. uint32 num_counters;
  362. uint16 num_value_sites[2];
  363. } LLVMProfileData;
  364. /* The profiling data for writing to the output file, the width of
  365. pointer is 8 bytes suppose we always use wamrc and llvm-profdata
  366. with 64-bit mode */
  367. typedef struct LLVMProfileData_64 {
  368. uint64 func_md5;
  369. uint64 func_hash;
  370. uint64 offset_counters;
  371. uint64 func_ptr;
  372. uint64 values;
  373. uint32 num_counters;
  374. uint16 num_value_sites[2];
  375. } LLVMProfileData_64;
  376. #endif /* end of WASM_ENABLE_STATIC_PGO != 0 */
  377. /**
  378. * Load a AOT module from aot file buffer
  379. * @param buf the byte buffer which contains the AOT file data
  380. * @param size the size of the buffer
  381. * @param error_buf output of the error info
  382. * @param error_buf_size the size of the error string
  383. *
  384. * @return return AOT module loaded, NULL if failed
  385. */
  386. AOTModule *
  387. aot_load_from_aot_file(const uint8 *buf, uint32 size, const LoadArgs *args,
  388. char *error_buf, uint32 error_buf_size);
  389. /**
  390. * Load a AOT module from a specified AOT section list.
  391. *
  392. * @param section_list the section list which contains each section data
  393. * @param error_buf output of the error info
  394. * @param error_buf_size the size of the error string
  395. *
  396. * @return return AOT module loaded, NULL if failed
  397. */
  398. AOTModule *
  399. aot_load_from_sections(AOTSection *section_list, char *error_buf,
  400. uint32 error_buf_size);
  401. /**
  402. * Unload a AOT module.
  403. *
  404. * @param module the module to be unloaded
  405. */
  406. void
  407. aot_unload(AOTModule *module);
  408. /**
  409. * Instantiate a AOT module.
  410. *
  411. * @param module the AOT module to instantiate
  412. * @param parent the parent module instance
  413. * @param heap_size the default heap size of the module instance, a heap will
  414. * be created besides the app memory space. Both wasm app and native
  415. * function can allocate memory from the heap. If heap_size is 0, the
  416. * default heap size will be used.
  417. * @param error_buf buffer to output the error info if failed
  418. * @param error_buf_size the size of the error buffer
  419. *
  420. * @return return the instantiated AOT module instance, NULL if failed
  421. */
  422. AOTModuleInstance *
  423. aot_instantiate(AOTModule *module, AOTModuleInstance *parent,
  424. WASMExecEnv *exec_env_main, uint32 stack_size, uint32 heap_size,
  425. uint32 max_memory_pages, char *error_buf,
  426. uint32 error_buf_size);
  427. /**
  428. * Deinstantiate a AOT module instance, destroy the resources.
  429. *
  430. * @param module_inst the AOT module instance to destroy
  431. * @param is_sub_inst the flag of sub instance
  432. */
  433. void
  434. aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst);
  435. /**
  436. * Lookup an exported function in the AOT module instance.
  437. *
  438. * @param module_inst the module instance
  439. * @param name the name of the function
  440. *
  441. * @return the function instance found
  442. */
  443. AOTFunctionInstance *
  444. aot_lookup_function(const AOTModuleInstance *module_inst, const char *name);
  445. /**
  446. * Get a function in the AOT module instance.
  447. *
  448. * @param module_inst the module instance
  449. * @param func_idx the index of the function
  450. *
  451. * @return the function instance found
  452. */
  453. AOTFunctionInstance *
  454. aot_get_function_instance(AOTModuleInstance *module_inst, uint32_t func_idx);
  455. /**
  456. * Call the given AOT function of a AOT module instance with
  457. * arguments.
  458. *
  459. * @param exec_env the execution environment
  460. * @param function the function to be called
  461. * @param argc the number of arguments
  462. * @param argv the arguments. If the function method has return value,
  463. * the first (or first two in case 64-bit return value) element of
  464. * argv stores the return value of the called AOT function after this
  465. * function returns.
  466. *
  467. * @return true if success, false otherwise and exception will be thrown,
  468. * the caller can call aot_get_exception to get exception info.
  469. */
  470. bool
  471. aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
  472. unsigned argc, uint32 argv[]);
  473. /**
  474. * Set AOT module instance exception with exception string
  475. *
  476. * @param module the AOT module instance
  477. *
  478. * @param exception current exception string
  479. */
  480. void
  481. aot_set_exception(AOTModuleInstance *module_inst, const char *exception);
  482. void
  483. aot_set_exception_with_id(AOTModuleInstance *module_inst, uint32 id);
  484. /**
  485. * Get exception info of the AOT module instance.
  486. *
  487. * @param module_inst the AOT module instance
  488. *
  489. * @return the exception string
  490. */
  491. const char *
  492. aot_get_exception(AOTModuleInstance *module_inst);
  493. /**
  494. * @brief Copy exception in buffer passed as parameter. Thread-safe version of
  495. * `aot_get_exception()`
  496. * @note Buffer size must be no smaller than EXCEPTION_BUF_LEN
  497. * @return true if exception found, false otherwise
  498. */
  499. bool
  500. aot_copy_exception(AOTModuleInstance *module_inst, char *exception_buf);
  501. uint64
  502. aot_module_malloc_internal(AOTModuleInstance *module_inst, WASMExecEnv *env,
  503. uint64 size, void **p_native_addr);
  504. uint64
  505. aot_module_realloc_internal(AOTModuleInstance *module_inst, WASMExecEnv *env,
  506. uint64 ptr, uint64 size, void **p_native_addr);
  507. void
  508. aot_module_free_internal(AOTModuleInstance *module_inst, WASMExecEnv *env,
  509. uint64 ptr);
  510. uint64
  511. aot_module_malloc(AOTModuleInstance *module_inst, uint64 size,
  512. void **p_native_addr);
  513. uint64
  514. aot_module_realloc(AOTModuleInstance *module_inst, uint64 ptr, uint64 size,
  515. void **p_native_addr);
  516. void
  517. aot_module_free(AOTModuleInstance *module_inst, uint64 ptr);
  518. uint64
  519. aot_module_dup_data(AOTModuleInstance *module_inst, const char *src,
  520. uint64 size);
  521. bool
  522. aot_enlarge_memory(AOTModuleInstance *module_inst, uint32 inc_page_count);
  523. /**
  524. * Invoke native function from aot code
  525. */
  526. bool
  527. aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
  528. uint32 *argv);
  529. bool
  530. aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
  531. uint32 argc, uint32 *argv);
  532. /**
  533. * Check whether the app address and the buf is inside the linear memory,
  534. * and convert the app address into native address
  535. */
  536. bool
  537. aot_check_app_addr_and_convert(AOTModuleInstance *module_inst, bool is_str,
  538. uint64 app_buf_addr, uint64 app_buf_size,
  539. void **p_native_addr);
  540. uint32
  541. aot_get_plt_table_size();
  542. void *
  543. aot_memmove(void *dest, const void *src, size_t n);
  544. void *
  545. aot_memset(void *s, int c, size_t n);
  546. double
  547. aot_sqrt(double x);
  548. float
  549. aot_sqrtf(float x);
  550. #if WASM_ENABLE_BULK_MEMORY != 0
  551. bool
  552. aot_memory_init(AOTModuleInstance *module_inst, uint32 seg_index, uint32 offset,
  553. uint32 len, size_t dst);
  554. bool
  555. aot_data_drop(AOTModuleInstance *module_inst, uint32 seg_index);
  556. #endif
  557. #if WASM_ENABLE_THREAD_MGR != 0
  558. bool
  559. aot_set_aux_stack(WASMExecEnv *exec_env, uint64 start_offset, uint32 size);
  560. bool
  561. aot_get_aux_stack(WASMExecEnv *exec_env, uint64 *start_offset, uint32 *size);
  562. #endif
  563. void
  564. aot_get_module_mem_consumption(const AOTModule *module,
  565. WASMModuleMemConsumption *mem_conspn);
  566. void
  567. aot_get_module_inst_mem_consumption(const AOTModuleInstance *module_inst,
  568. WASMModuleInstMemConsumption *mem_conspn);
  569. #if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
  570. void
  571. aot_drop_table_seg(AOTModuleInstance *module_inst, uint32 tbl_seg_idx);
  572. void
  573. aot_table_init(AOTModuleInstance *module_inst, uint32 tbl_idx,
  574. uint32 tbl_seg_idx, uint32 length, uint32 src_offset,
  575. uint32 dst_offset);
  576. void
  577. aot_table_copy(AOTModuleInstance *module_inst, uint32 src_tbl_idx,
  578. uint32 dst_tbl_idx, uint32 length, uint32 src_offset,
  579. uint32 dst_offset);
  580. void
  581. aot_table_fill(AOTModuleInstance *module_inst, uint32 tbl_idx, uint32 length,
  582. table_elem_type_t val, uint32 data_offset);
  583. uint32
  584. aot_table_grow(AOTModuleInstance *module_inst, uint32 tbl_idx,
  585. uint32 inc_entries, table_elem_type_t init_val);
  586. #endif
  587. bool
  588. aot_alloc_frame(WASMExecEnv *exec_env, uint32 func_index);
  589. void
  590. aot_free_frame(WASMExecEnv *exec_env);
  591. void
  592. aot_frame_update_profile_info(WASMExecEnv *exec_env, bool alloc_frame);
  593. bool
  594. aot_create_call_stack(struct WASMExecEnv *exec_env);
  595. /**
  596. * @brief Dump wasm call stack or get the size
  597. *
  598. * @param exec_env the execution environment
  599. * @param print whether to print to stdout or not
  600. * @param buf buffer to store the dumped content
  601. * @param len length of the buffer
  602. *
  603. * @return when print is true, return the bytes printed out to stdout; when
  604. * print is false and buf is NULL, return the size required to store the
  605. * callstack content; when print is false and buf is not NULL, return the size
  606. * dumped to the buffer, 0 means error and data in buf may be invalid
  607. */
  608. uint32
  609. aot_dump_call_stack(WASMExecEnv *exec_env, bool print, char *buf, uint32 len);
  610. void
  611. aot_dump_perf_profiling(const AOTModuleInstance *module_inst);
  612. double
  613. aot_summarize_wasm_execute_time(const AOTModuleInstance *inst);
  614. double
  615. aot_get_wasm_func_exec_time(const AOTModuleInstance *inst,
  616. const char *func_name);
  617. const uint8 *
  618. aot_get_custom_section(const AOTModule *module, const char *name, uint32 *len);
  619. const void *
  620. aot_get_data_section_addr(AOTModule *module, const char *section_name,
  621. uint32 *p_data_size);
  622. #if WASM_ENABLE_STATIC_PGO != 0
  623. void
  624. llvm_profile_instrument_target(uint64 target_value, void *data,
  625. uint32 counter_idx);
  626. void
  627. llvm_profile_instrument_memop(uint64 target_value, void *data,
  628. uint32 counter_idx);
  629. uint32
  630. aot_get_pgo_prof_data_size(AOTModuleInstance *module_inst);
  631. uint32
  632. aot_dump_pgo_prof_data_to_buf(AOTModuleInstance *module_inst, char *buf,
  633. uint32 len);
  634. void
  635. aot_exchange_uint16(uint8 *p_data);
  636. void
  637. aot_exchange_uint32(uint8 *p_data);
  638. void
  639. aot_exchange_uint64(uint8 *p_data);
  640. #endif /* end of WASM_ENABLE_STATIC_PGO != 0 */
  641. #if WASM_ENABLE_GC != 0
  642. void *
  643. aot_create_func_obj(AOTModuleInstance *module_inst, uint32 func_idx,
  644. bool throw_exce, char *error_buf, uint32 error_buf_size);
  645. bool
  646. aot_obj_is_instance_of(AOTModuleInstance *module_inst, WASMObjectRef gc_obj,
  647. uint32 type_index);
  648. /* Whether func type1 is one of super types of func type2 */
  649. bool
  650. aot_func_type_is_super_of(AOTModuleInstance *module_inst, uint32 type_idx1,
  651. uint32 type_idx2);
  652. WASMRttTypeRef
  653. aot_rtt_type_new(AOTModuleInstance *module_inst, uint32 type_index);
  654. bool
  655. aot_array_init_with_data(AOTModuleInstance *module_inst, uint32 seg_index,
  656. uint32 data_seg_offset, WASMArrayObjectRef array_obj,
  657. uint32 elem_size, uint32 array_len);
  658. bool
  659. aot_traverse_gc_rootset(WASMExecEnv *exec_env, void *heap);
  660. #endif /* end of WASM_ENABLE_GC != 0 */
  661. char *
  662. aot_const_str_set_insert(const uint8 *str, int32 len, AOTModule *module,
  663. #if (WASM_ENABLE_WORD_ALIGN_READ != 0)
  664. bool is_vram_word_align,
  665. #endif
  666. char *error_buf, uint32 error_buf_size);
  667. bool
  668. aot_set_module_name(AOTModule *module, const char *name, char *error_buf,
  669. uint32_t error_buf_size);
  670. const char *
  671. aot_get_module_name(AOTModule *module);
  672. #ifdef __cplusplus
  673. } /* end of extern "C" */
  674. #endif
  675. #endif /* end of _AOT_RUNTIME_H_ */