aot_runtime.h 23 KB

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