aot_runtime.h 22 KB

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