aot_runtime.h 23 KB

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