aot_runtime.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  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_JIT != 0
  12. #include "../compilation/aot_llvm.h"
  13. #endif
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. typedef enum AOTExceptionID {
  18. EXCE_UNREACHABLE = 0,
  19. EXCE_OUT_OF_MEMORY,
  20. EXCE_OUT_OF_BOUNDS_MEMORY_ACCESS,
  21. EXCE_INTEGER_OVERFLOW,
  22. EXCE_INTEGER_DIVIDE_BY_ZERO,
  23. EXCE_INVALID_CONVERSION_TO_INTEGER,
  24. EXCE_INVALID_FUNCTION_TYPE_INDEX,
  25. EXCE_INVALID_FUNCTION_INDEX,
  26. EXCE_UNDEFINED_ELEMENT,
  27. EXCE_UNINITIALIZED_ELEMENT,
  28. EXCE_CALL_UNLINKED_IMPORT_FUNC,
  29. EXEC_CALL_UNLINKED_MODULE,
  30. EXCE_NATIVE_STACK_OVERFLOW,
  31. EXCE_UNALIGNED_ATOMIC,
  32. EXCE_AUX_STACK_OVERFLOW,
  33. EXCE_AUX_STACK_UNDERFLOW,
  34. EXCE_OUT_OF_BOUNDS_TABLE_ACCESS,
  35. EXCE_NUM,
  36. } AOTExceptionID;
  37. typedef enum AOTSectionType {
  38. AOT_SECTION_TYPE_TARGET_INFO = 0,
  39. AOT_SECTION_TYPE_DYLINK = 1,
  40. AOT_SECTION_TYPE_INIT_DATA = 2,
  41. AOT_SECTION_TYPE_TEXT = 3 ,
  42. AOT_SECTION_TYPE_FUNCTION = 4,
  43. AOT_SECTION_TYPE_EXPORT = 5,
  44. AOT_SECTION_TYPE_RELOCATION = 6,
  45. AOT_SECTION_TYPE_SIGANATURE = 7,
  46. AOT_SECTION_TYPE_CUSTOM = 100,
  47. } AOTSectionType;
  48. typedef enum AOTCustomSectionType {
  49. AOT_CUSTOM_SECTION_NATIVE_SYMBOL = 1,
  50. AOT_CUSTOM_SECTION_ACCESS_CONTROL = 2,
  51. AOT_CUSTOM_SECTION_NAME = 3,
  52. } AOTCustomSectionType;
  53. typedef struct AOTObjectDataSection {
  54. char *name;
  55. uint8 *data;
  56. uint32 size;
  57. } AOTObjectDataSection;
  58. /* Relocation info */
  59. typedef struct AOTRelocation {
  60. uint64 relocation_offset;
  61. int64 relocation_addend;
  62. uint32 relocation_type;
  63. char *symbol_name;
  64. /* index in the symbol offset field */
  65. uint32 symbol_index;
  66. } AOTRelocation;
  67. /* Relocation Group */
  68. typedef struct AOTRelocationGroup {
  69. char *section_name;
  70. /* index in the symbol offset field */
  71. uint32 name_index;
  72. uint32 relocation_count;
  73. AOTRelocation *relocations;
  74. } AOTRelocationGroup;
  75. /* AOT function instance */
  76. typedef struct AOTExportFunctionInstance {
  77. const char *func_name;
  78. uint32 func_index;
  79. bool is_import_func;
  80. union {
  81. struct {
  82. AOTFuncType *func_type;
  83. /* function pointer linked */
  84. void *func_ptr;
  85. } func;
  86. AOTImportFunc *func_import;
  87. } u;
  88. } AOTExportFunctionInstance;
  89. #if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
  90. /* clang-format off */
  91. typedef struct AOTUnwindInfo {
  92. uint8 Version : 3;
  93. uint8 Flags : 5;
  94. uint8 SizeOfProlog;
  95. uint8 CountOfCodes;
  96. uint8 FrameRegister : 4;
  97. uint8 FrameOffset : 4;
  98. struct {
  99. struct {
  100. uint8 CodeOffset;
  101. uint8 UnwindOp : 4;
  102. uint8 OpInfo : 4;
  103. };
  104. uint16 FrameOffset;
  105. } UnwindCode[1];
  106. } AOTUnwindInfo;
  107. /* clang-format on */
  108. /* size of mov instruction and jmp instruction */
  109. #define PLT_ITEM_SIZE 12
  110. #endif
  111. typedef struct AOTModule {
  112. uint32 module_type;
  113. WASMDylinkSection * dylink_section;
  114. /* import memories */
  115. uint32 import_memory_count;
  116. AOTImportMemory *import_memories;
  117. /* memory info */
  118. uint32 memory_count;
  119. AOTMemory *memories;
  120. /* init data */
  121. uint32 mem_init_data_count;
  122. AOTMemInitData **mem_init_data_list;
  123. /* native symbol */
  124. uint32 native_symbol_count;
  125. void **native_symbol_list;
  126. /* import tables */
  127. uint32 import_table_count;
  128. AOTImportTable *import_tables;
  129. /* tables */
  130. uint32 table_count;
  131. AOTTable *tables;
  132. /* table init data info */
  133. uint32 table_init_data_count;
  134. AOTTableInitData **table_init_data_list;
  135. /* function type info */
  136. uint32 func_type_count;
  137. AOTFuncType **func_types;
  138. /* import global variable info */
  139. uint32 import_global_count;
  140. AOTImportGlobal *import_globals;
  141. /* global variable info */
  142. uint32 global_count;
  143. AOTGlobal *globals;
  144. /* total global variable size */
  145. uint32 global_data_size;
  146. /* import function info */
  147. uint32 import_func_count;
  148. AOTImportFunc *import_funcs;
  149. /* function info */
  150. uint32 func_count;
  151. /* point to AOTed/JITed functions */
  152. void **func_ptrs;
  153. /* function type indexes */
  154. uint32 *func_type_indexes;
  155. /* export info */
  156. uint32 export_count;
  157. uint32 export_func_count;
  158. uint32 export_global_count;
  159. uint32 export_mem_count;
  160. uint32 export_tab_count;
  161. AOTExport *exports;
  162. /* start function index, -1 denotes no start function */
  163. uint32 start_func_index;
  164. /* start function, point to AOTed/JITed function */
  165. void *start_function;
  166. uint32 malloc_func_index;
  167. uint32 free_func_index;
  168. uint32 retain_func_index;
  169. /* AOTed code, NULL for JIT mode */
  170. void *code;
  171. uint32 code_size;
  172. /* literal for AOTed code, NULL for JIT mode */
  173. uint8 *literal;
  174. uint32 literal_size;
  175. #if defined(BH_PLATFORM_WINDOWS)
  176. /* extra plt data area for __xmm and __real constants
  177. in Windows platform, NULL for JIT mode */
  178. uint8 *extra_plt_data;
  179. uint32 extra_plt_data_size;
  180. uint32 xmm_plt_count;
  181. uint32 real_plt_count;
  182. uint32 float_plt_count;
  183. #endif
  184. #if defined(OS_ENABLE_HW_BOUND_CHECK) && defined(BH_PLATFORM_WINDOWS)
  185. /* dynamic function table to be added by RtlAddFunctionTable(),
  186. used to unwind the call stack and register exception handler
  187. for AOT functions */
  188. RUNTIME_FUNCTION *rtl_func_table;
  189. bool rtl_func_table_registered;
  190. #endif
  191. /* data sections in AOT object file, including .data, .rodata
  192. * and .rodata.cstN. NULL for JIT mode. */
  193. AOTObjectDataSection *data_sections;
  194. uint32 data_section_count;
  195. /* constant string set */
  196. HashMap *const_str_set;
  197. /* the index of auxiliary __data_end global,
  198. -1 means unexported */
  199. uint32 aux_data_end_global_index;
  200. /* auxiliary __data_end exported by wasm app */
  201. uint32 aux_data_end;
  202. /* the index of auxiliary __heap_base global,
  203. -1 means unexported */
  204. uint32 aux_heap_base_global_index;
  205. /* auxiliary __heap_base exported by wasm app */
  206. uint32 aux_heap_base;
  207. /* the index of auxiliary stack top global,
  208. -1 means unexported */
  209. uint32 aux_stack_top_global_index;
  210. /* auxiliary stack bottom resolved */
  211. uint32 aux_stack_bottom;
  212. /* auxiliary stack size resolved */
  213. uint32 aux_stack_size;
  214. /* is jit mode or not */
  215. bool is_jit_mode;
  216. const uint8 * file_buf;
  217. WASMRuntime * runtime;
  218. #if WASM_ENABLE_DYNAMIC_LINKING != 0
  219. /* directly implicit dependency modules of current module, e.g. dylink section */
  220. HashMap *implicit_dependency_modules_hmap;
  221. uint32 ref_cnt;
  222. uint32 export_sp_global_id; // store the export id of stack_pointer after loading, so that no lookup again when linking
  223. #endif
  224. const ConstStrDescription * module_name;
  225. #if WASM_ENABLE_JIT != 0
  226. WASMModule *wasm_module;
  227. AOTCompContext *comp_ctx;
  228. AOTCompData *comp_data;
  229. #endif
  230. #if WASM_ENABLE_LIBC_WASI != 0
  231. WASIArguments wasi_args;
  232. bool is_wasi_module;
  233. #endif
  234. #if WASM_ENABLE_DEBUG_AOT != 0
  235. void *elf_hdr;
  236. uint32 elf_size;
  237. #endif
  238. #if WASM_ENABLE_CUSTOM_NAME_SECTION != 0
  239. const char **aux_func_names;
  240. uint32 *aux_func_indexes;
  241. uint32 aux_func_name_count;
  242. #endif
  243. } AOTModule;
  244. typedef union {
  245. uint64 _make_it_8_bytes_;
  246. void *ptr;
  247. } AOTPointer;
  248. typedef union {
  249. uint64 u64;
  250. uint32 u32[2];
  251. } MemBound;
  252. typedef struct AOTMemoryInstance {
  253. uint32 module_type;
  254. /* shared memory flag */
  255. bool is_shared;
  256. /* memory space info */
  257. uint32 num_bytes_per_page;
  258. uint32 cur_page_count;
  259. uint32 max_page_count;
  260. uint32 memory_data_size;
  261. AOTPointer memory_data;
  262. AOTPointer memory_data_end;
  263. /* heap space info */
  264. AOTPointer heap_data;
  265. AOTPointer heap_data_end;
  266. AOTPointer heap_handle;
  267. /* boundary check constants for aot code */
  268. MemBound mem_bound_check_1byte;
  269. MemBound mem_bound_check_2bytes;
  270. MemBound mem_bound_check_4bytes;
  271. MemBound mem_bound_check_8bytes;
  272. MemBound mem_bound_check_16bytes;
  273. } AOTMemoryInstance;
  274. typedef struct AOTTableInstance {
  275. uint32 cur_size;
  276. /*
  277. * only grow in the range of [:max_size)
  278. * if the table is growable, max_size equals to its declared maximum size
  279. * otherwise, max_size equals to its declared minimum size
  280. */
  281. uint32 max_size;
  282. /*
  283. * +------------------------------+ <--- data
  284. * | ref.func[] or ref.extern[]
  285. * +------------------------------+
  286. */
  287. uint32 data[1];
  288. } AOTTableInstance;
  289. typedef struct AOTModuleInstance {
  290. uint32 module_type;
  291. #if WASM_ENABLE_DYNAMIC_LINKING != 0
  292. //WASMModuleInstanceHead head;
  293. // unique instance id in program scope, used to alloc table space currently.
  294. uint32 inst_id;
  295. WASMRuntime * runtime;
  296. WASMProgramInstance * program;
  297. HashMap * local_implicit_dependency_modules_name_hmap;
  298. DependencyModuleInitGlobals init_globals;
  299. // explicit ref count, updated by dlopen/dlclose
  300. uint32 exp_ref_cnt;
  301. // implicit ref count, updated according to needed library entries
  302. uint32 imp_ref_cnt;
  303. // workround here, for compatiable with aot instance memory layout
  304. #ifdef TARGET_32
  305. uint32 padding_runtime;
  306. uint32 padding_program;
  307. uint32 padding_imp_hmap;
  308. #endif
  309. uint32 padding_memory_count;
  310. #endif
  311. /* memories */
  312. uint32 memory_count;
  313. AOTPointer memories;
  314. /* global and table info */
  315. uint32 global_data_size;
  316. /*
  317. * the count of AOTTableInstance.
  318. * it includes imported tables and local tables.
  319. *
  320. * TODO: for now we treate imported table like a local table
  321. */
  322. uint32 table_count;
  323. /* points to global_data */
  324. AOTPointer global_data;
  325. /* points to AOTTableInstance[] */
  326. AOTPointer tables;
  327. AOTPointer global_table_data_end;
  328. /* function pointer array */
  329. AOTPointer func_ptrs;
  330. /* function type indexes */
  331. AOTPointer func_type_indexes;
  332. /* export info */
  333. //uint32 export_func_count;
  334. //uint32 export_global_count;
  335. //uint32 export_mem_count;
  336. //uint32 export_tab_count;
  337. AOTPointer export_funcs;
  338. AOTPointer export_globals;
  339. AOTPointer export_memories;
  340. AOTPointer export_tables;
  341. AOTPointer malloc_func;
  342. AOTPointer retain_func;
  343. AOTPointer free_func;
  344. /* The exception buffer for current thread. */
  345. char cur_exception[128];
  346. /* The custom data that can be set/get by
  347. * wasm_runtime_set_custom_data/wasm_runtime_get_custom_data */
  348. AOTPointer custom_data;
  349. /* The AOT module */
  350. AOTPointer aot_module;
  351. /* WASI context */
  352. AOTPointer wasi_ctx;
  353. /* function performance profiling info list */
  354. AOTPointer func_perf_profilings;
  355. AOTPointer exec_env_singleton;
  356. /* others */
  357. uint32 temp_ret;
  358. uint32 llvm_stack;
  359. uint32 default_wasm_stack_size;
  360. uint32 _padding;
  361. /* store stacktrace information */
  362. AOTPointer frames;
  363. /* reserved */
  364. uint32 reserved[6];
  365. /*
  366. * +------------------------------+ <-- memories.ptr
  367. * | #0 AOTMemoryInstance
  368. * +------------------------------+ <-- global_data.ptr
  369. * | global data
  370. * +------------------------------+ <-- tables.ptr
  371. * | AOTTableInstance[table_count]
  372. * +------------------------------+
  373. */
  374. union {
  375. uint64 _make_it_8_byte_aligned_;
  376. AOTMemoryInstance memory_instances[1];
  377. uint8 bytes[1];
  378. } global_table_data;
  379. } AOTModuleInstance;
  380. /* Target info, read from ELF header of object file */
  381. typedef struct AOTTargetInfo {
  382. /* Binary type, elf32l/elf32b/elf64l/elf64b */
  383. uint16 bin_type;
  384. /* ABI type */
  385. uint16 abi_type;
  386. /* Object file type */
  387. uint16 e_type;
  388. /* Architecture */
  389. uint16 e_machine;
  390. /* Object file version */
  391. uint32 e_version;
  392. /* Processor-specific flags */
  393. uint32 e_flags;
  394. /* Reserved */
  395. uint32 reserved;
  396. /* Arch name */
  397. char arch[16];
  398. } AOTTargetInfo;
  399. typedef struct AOTFuncPerfProfInfo {
  400. /* total execution time */
  401. uint64 total_exec_time;
  402. /* total execution count */
  403. uint32 total_exec_cnt;
  404. } AOTFuncPerfProfInfo;
  405. /* AOT auxiliary call stack */
  406. typedef struct AOTFrame {
  407. struct AOTFrame *prev_frame;
  408. uint32 func_index;
  409. #if WASM_ENABLE_PERF_PROFILING != 0
  410. uint64 time_started;
  411. AOTFuncPerfProfInfo *func_perf_prof_info;
  412. #endif
  413. } AOTFrame;
  414. /**
  415. * Load a AOT module from aot file buffer
  416. * @param buf the byte buffer which contains the AOT file data
  417. * @param size the size of the buffer
  418. * @param error_buf output of the error info
  419. * @param error_buf_size the size of the error string
  420. *
  421. * @return return AOT module loaded, NULL if failed
  422. */
  423. AOTModule *
  424. aot_load_from_aot_file(const uint8 *buf, uint32 size, char *error_buf,
  425. uint32 error_buf_size);
  426. /**
  427. * Load a AOT module from a specified AOT section list.
  428. *
  429. * @param section_list the section list which contains each section data
  430. * @param error_buf output of the error info
  431. * @param error_buf_size the size of the error string
  432. *
  433. * @return return AOT module loaded, NULL if failed
  434. */
  435. AOTModule *
  436. aot_load_from_sections(AOTSection *section_list, char *error_buf,
  437. uint32 error_buf_size);
  438. #if WASM_ENABLE_JIT != 0
  439. /**
  440. * Convert WASM module to AOT module
  441. *
  442. * @param wasm_module the WASM module to convert
  443. * @param error_buf output of the error info
  444. * @param error_buf_size the size of the error string
  445. *
  446. * @return return AOT module loaded, NULL if failed
  447. */
  448. AOTModule *
  449. aot_convert_wasm_module(WASMModule *wasm_module, char *error_buf,
  450. uint32 error_buf_size);
  451. #endif
  452. /**
  453. * Unload a AOT module.
  454. *
  455. * @param module the module to be unloaded
  456. */
  457. void
  458. aot_unload(AOTModule *module);
  459. /**
  460. * Instantiate a AOT module.
  461. *
  462. * @param module the AOT module to instantiate
  463. * @param is_sub_inst the flag of sub instance
  464. * @param heap_size the default heap size of the module instance, a heap will
  465. * be created besides the app memory space. Both wasm app and native
  466. * function can allocate memory from the heap. If heap_size is 0, the
  467. * default heap size will be used.
  468. * @param error_buf buffer to output the error info if failed
  469. * @param error_buf_size the size of the error buffer
  470. *
  471. * @return return the instantiated AOT module instance, NULL if failed
  472. */
  473. AOTModuleInstance*
  474. aot_instantiate(WASMProgramInstance * program, AOTModule *module, bool is_sub_inst,
  475. uint32 stack_size, uint32 heap_size,
  476. char *error_buf, uint32 error_buf_size);
  477. #if WASM_ENABLE_DYNAMIC_LINKING != 0
  478. AOTModuleInstance*
  479. aot_instantiate_dependency(AOTModule *module, WASMProgramInstance * program,
  480. uint32 stack_size, DependencyModuleInitGlobals * init_globals);
  481. #endif
  482. /**
  483. * Deinstantiate a AOT module instance, destroy the resources.
  484. *
  485. * @param module_inst the AOT module instance to destroy
  486. * @param is_sub_inst the flag of sub instance
  487. */
  488. void
  489. aot_deinstantiate(AOTModuleInstance *module_inst, bool is_sub_inst);
  490. /**
  491. * Lookup an exported function in the AOT module instance.
  492. *
  493. * @param module_inst the module instance
  494. * @param name the name of the function
  495. * @param signature the signature of the function, use "i32"/"i64"/"f32"/"f64"
  496. * to represent the type of i32/i64/f32/f64, e.g. "(i32i64)" "(i32)f32"
  497. *
  498. * @return the function instance found
  499. */
  500. AOTExportFunctionInstance *
  501. aot_lookup_function(const AOTModuleInstance *module_inst, const char *name,
  502. const char *signature);
  503. /**
  504. * Call the given AOT function of a AOT module instance with
  505. * arguments.
  506. *
  507. * @param exec_env the execution environment
  508. * @param function the function to be called
  509. * @param argc the number of arguments
  510. * @param argv the arguments. If the function method has return value,
  511. * the first (or first two in case 64-bit return value) element of
  512. * argv stores the return value of the called AOT function after this
  513. * function returns.
  514. *
  515. * @return true if success, false otherwise and exception will be thrown,
  516. * the caller can call aot_get_exception to get exception info.
  517. */
  518. bool
  519. aot_call_function(WASMExecEnv *exec_env, AOTExportFunctionInstance *function,
  520. unsigned argc, uint32 argv[]);
  521. bool
  522. aot_create_exec_env_and_call_function(AOTModuleInstance *module_inst,
  523. AOTExportFunctionInstance *function,
  524. unsigned argc, uint32 argv[]);
  525. bool
  526. aot_create_exec_env_singleton(AOTModuleInstance *module_inst);
  527. /**
  528. * Set AOT module instance exception with exception string
  529. *
  530. * @param module the AOT module instance
  531. *
  532. * @param exception current exception string
  533. */
  534. void
  535. aot_set_exception(AOTModuleInstance *module_inst, const char *exception);
  536. void
  537. aot_set_exception_with_id(AOTModuleInstance *module_inst, uint32 id);
  538. /**
  539. * Get exception info of the AOT module instance.
  540. *
  541. * @param module_inst the AOT module instance
  542. *
  543. * @return the exception string
  544. */
  545. const char *
  546. aot_get_exception(AOTModuleInstance *module_inst);
  547. /**
  548. * Clear exception info of the AOT module instance.
  549. *
  550. * @param module_inst the AOT module instance
  551. */
  552. void
  553. aot_clear_exception(AOTModuleInstance *module_inst);
  554. uint32
  555. aot_module_malloc(AOTModuleInstance *module_inst, uint32 size,
  556. void **p_native_addr);
  557. uint32
  558. aot_module_realloc(AOTModuleInstance *module_inst, uint32 ptr, uint32 size,
  559. void **p_native_addr);
  560. void
  561. aot_module_free(AOTModuleInstance *module_inst, uint32 ptr);
  562. uint32
  563. aot_module_dup_data(AOTModuleInstance *module_inst, const char *src,
  564. uint32 size);
  565. bool
  566. aot_validate_app_addr(AOTModuleInstance *module_inst, uint32 app_offset,
  567. uint32 size);
  568. bool
  569. aot_validate_native_addr(AOTModuleInstance *module_inst, void *native_ptr,
  570. uint32 size);
  571. void *
  572. aot_addr_app_to_native(AOTModuleInstance *module_inst, uint32 app_offset);
  573. uint32
  574. aot_addr_native_to_app(AOTModuleInstance *module_inst, void *native_ptr);
  575. bool
  576. aot_get_app_addr_range(AOTModuleInstance *module_inst, uint32 app_offset,
  577. uint32 *p_app_start_offset, uint32 *p_app_end_offset);
  578. bool
  579. aot_get_native_addr_range(AOTModuleInstance *module_inst, uint8 *native_ptr,
  580. uint8 **p_native_start_addr,
  581. uint8 **p_native_end_addr);
  582. bool
  583. aot_enlarge_memory(AOTModuleInstance *module_inst, uint32 inc_page_count);
  584. /**
  585. * Compare whether two wasm types are equal according to the indexs
  586. *
  587. * @param module_inst the AOT module instance
  588. * @param type1_idx index of the first wasm type
  589. * @param type2_idx index of the second wasm type
  590. *
  591. * @return true if equal, false otherwise
  592. */
  593. bool
  594. aot_is_wasm_type_equal(AOTModuleInstance *module_inst, uint32 type1_idx,
  595. uint32 type2_idx);
  596. /**
  597. * Invoke native function from aot code
  598. */
  599. bool
  600. aot_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, uint32 argc,
  601. uint32 *argv);
  602. bool
  603. aot_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 table_elem_idx,
  604. uint32 argc, uint32 *argv);
  605. bool
  606. aot_call_indirect_with_type(WASMExecEnv *exec_env,
  607. uint32 tbl_idx, int32 table_elem_idx, uint32 type_idx,
  608. uint32 argc, uint32 *argv);
  609. bool
  610. aot_resolve_function(WASMExecEnv *exec_env, uint32 import_func_id,
  611. uint32 argc, uint32 *argv);
  612. uint32
  613. aot_get_plt_table_size();
  614. void *
  615. aot_memmove(void *dest, const void *src, size_t n);
  616. void *
  617. aot_memset(void *s, int c, size_t n);
  618. #if WASM_ENABLE_BULK_MEMORY != 0
  619. bool
  620. aot_memory_init(AOTModuleInstance *module_inst, uint32 seg_index, uint32 offset,
  621. uint32 len, uint32 dst);
  622. bool
  623. aot_data_drop(AOTModuleInstance *module_inst, uint32 seg_index);
  624. #endif
  625. #if WASM_ENABLE_THREAD_MGR != 0
  626. bool
  627. aot_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset, uint32 size);
  628. bool
  629. aot_get_aux_stack(WASMExecEnv *exec_env, uint32 *start_offset, uint32 *size);
  630. #endif
  631. #ifdef OS_ENABLE_HW_BOUND_CHECK
  632. bool
  633. aot_signal_init();
  634. void
  635. aot_signal_destroy();
  636. #endif
  637. void
  638. aot_get_module_mem_consumption(const AOTModule *module,
  639. WASMModuleMemConsumption *mem_conspn);
  640. void
  641. aot_get_module_inst_mem_consumption(const AOTModuleInstance *module_inst,
  642. WASMModuleInstMemConsumption *mem_conspn);
  643. #if WASM_ENABLE_REF_TYPES != 0
  644. void
  645. aot_drop_table_seg(AOTModuleInstance *module_inst, uint32 tbl_seg_idx);
  646. void
  647. aot_table_init(AOTModuleInstance *module_inst, uint32 tbl_idx,
  648. uint32 tbl_seg_idx, uint32 length, uint32 src_offset,
  649. uint32 dst_offset);
  650. void
  651. aot_table_copy(AOTModuleInstance *module_inst, uint32 src_tbl_idx,
  652. uint32 dst_tbl_idx, uint32 length, uint32 src_offset,
  653. uint32 dst_offset);
  654. void
  655. aot_table_fill(AOTModuleInstance *module_inst, uint32 tbl_idx, uint32 length,
  656. uint32 val, uint32 data_offset);
  657. uint32
  658. aot_table_grow(AOTModuleInstance *module_inst, uint32 tbl_idx,
  659. uint32 inc_entries, uint32 init_val);
  660. #endif
  661. AOTTableInstance *
  662. aot_next_tbl_inst(const AOTTableInstance *tbl_inst);
  663. bool
  664. aot_alloc_frame(WASMExecEnv *exec_env, uint32 func_index);
  665. void
  666. aot_free_frame(WASMExecEnv *exec_env);
  667. void
  668. aot_dump_call_stack(WASMExecEnv *exec_env);
  669. void
  670. aot_dump_perf_profiling(const AOTModuleInstance *module_inst);
  671. static inline AOTTableInstance *
  672. aot_get_table_inst(const AOTModuleInstance *module_inst, uint32 tbl_idx)
  673. {
  674. uint32 i = 0;
  675. AOTTableInstance *tbl_inst = (AOTTableInstance *)module_inst->tables.ptr;
  676. while (i != tbl_idx) {
  677. tbl_inst = aot_next_tbl_inst(tbl_inst);
  678. ++i;
  679. }
  680. return tbl_inst;
  681. }
  682. #ifdef __cplusplus
  683. } /* end of extern "C" */
  684. #endif
  685. #endif /* end of _AOT_RUNTIME_H_ */