wasm_runtime_common.h 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _WASM_COMMON_H
  6. #define _WASM_COMMON_H
  7. #include "bh_platform.h"
  8. #include "bh_common.h"
  9. #include "wasm_exec_env.h"
  10. #include "wasm_native.h"
  11. #include "../include/wasm_export.h"
  12. #include "../interpreter/wasm.h"
  13. #if WASM_ENABLE_GC != 0
  14. #include "gc/gc_object.h"
  15. #endif
  16. #if WASM_ENABLE_LIBC_WASI != 0
  17. #if WASM_ENABLE_UVWASI == 0
  18. #include "posix.h"
  19. #else
  20. #include "uvwasi.h"
  21. #endif
  22. #endif
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* Internal use for setting default running mode */
  27. #define Mode_Default 0
  28. #if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
  29. #define PUT_I64_TO_ADDR(addr, value) \
  30. do { \
  31. *(int64 *)(addr) = (int64)(value); \
  32. } while (0)
  33. #define PUT_F64_TO_ADDR(addr, value) \
  34. do { \
  35. *(float64 *)(addr) = (float64)(value); \
  36. } while (0)
  37. #define PUT_REF_TO_ADDR(addr, value) \
  38. do { \
  39. *(void **)(addr) = (void *)(value); \
  40. } while (0)
  41. #define GET_I64_FROM_ADDR(addr) (*(int64 *)(addr))
  42. #define GET_F64_FROM_ADDR(addr) (*(float64 *)(addr))
  43. #define GET_REF_FROM_ADDR(addr) (*(void **)(addr))
  44. /* For STORE opcodes */
  45. #define STORE_I64 PUT_I64_TO_ADDR
  46. static inline void
  47. STORE_U32(void *addr, uint32_t value)
  48. {
  49. *(uint32_t *)(addr) = (uint32_t)(value);
  50. }
  51. static inline void
  52. STORE_U16(void *addr, uint16_t value)
  53. {
  54. *(uint16_t *)(addr) = (uint16_t)(value);
  55. }
  56. static inline void
  57. STORE_U8(void *addr, uint8_t value)
  58. {
  59. *(uint8 *)addr = value;
  60. }
  61. /* For LOAD opcodes */
  62. #define LOAD_I64(addr) (*(int64 *)(addr))
  63. #define LOAD_F64(addr) (*(float64 *)(addr))
  64. #define LOAD_I32(addr) (*(int32 *)(addr))
  65. #define LOAD_U32(addr) (*(uint32 *)(addr))
  66. #define LOAD_I16(addr) (*(int16 *)(addr))
  67. #define LOAD_U16(addr) (*(uint16 *)(addr))
  68. #define STORE_PTR(addr, ptr) \
  69. do { \
  70. *(void **)addr = (void *)ptr; \
  71. } while (0)
  72. #else /* WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 */
  73. #define PUT_I64_TO_ADDR(addr, value) \
  74. do { \
  75. uint32 *addr_u32 = (uint32 *)(addr); \
  76. union { \
  77. int64 val; \
  78. uint32 parts[2]; \
  79. } u; \
  80. u.val = (int64)(value); \
  81. addr_u32[0] = u.parts[0]; \
  82. addr_u32[1] = u.parts[1]; \
  83. } while (0)
  84. #define PUT_F64_TO_ADDR(addr, value) \
  85. do { \
  86. uint32 *addr_u32 = (uint32 *)(addr); \
  87. union { \
  88. float64 val; \
  89. uint32 parts[2]; \
  90. } u; \
  91. u.val = (value); \
  92. addr_u32[0] = u.parts[0]; \
  93. addr_u32[1] = u.parts[1]; \
  94. } while (0)
  95. #if UINTPTR_MAX == UINT64_MAX
  96. #define PUT_REF_TO_ADDR(addr, value) \
  97. do { \
  98. uint32 *addr_u32 = (uint32 *)(addr); \
  99. union { \
  100. void *val; \
  101. uint32 parts[2]; \
  102. } u; \
  103. u.val = (void *)(value); \
  104. addr_u32[0] = u.parts[0]; \
  105. addr_u32[1] = u.parts[1]; \
  106. } while (0)
  107. #else
  108. #define PUT_REF_TO_ADDR(addr, value) \
  109. do { \
  110. *(void **)(addr) = (void *)(value); \
  111. } while (0)
  112. #endif
  113. static inline int64
  114. GET_I64_FROM_ADDR(uint32 *addr)
  115. {
  116. union {
  117. int64 val;
  118. uint32 parts[2];
  119. } u;
  120. u.parts[0] = addr[0];
  121. u.parts[1] = addr[1];
  122. return u.val;
  123. }
  124. static inline float64
  125. GET_F64_FROM_ADDR(uint32 *addr)
  126. {
  127. union {
  128. float64 val;
  129. uint32 parts[2];
  130. } u;
  131. u.parts[0] = addr[0];
  132. u.parts[1] = addr[1];
  133. return u.val;
  134. }
  135. #if UINTPTR_MAX == UINT64_MAX
  136. static inline void *
  137. GET_REF_FROM_ADDR(uint32 *addr)
  138. {
  139. union {
  140. void *val;
  141. uint32 parts[2];
  142. } u;
  143. u.parts[0] = addr[0];
  144. u.parts[1] = addr[1];
  145. return u.val;
  146. }
  147. #else
  148. #define GET_REF_FROM_ADDR(addr) (*(void **)(addr))
  149. #endif
  150. /* For STORE opcodes */
  151. #define STORE_I64(addr, value) \
  152. do { \
  153. uintptr_t addr_ = (uintptr_t)(addr); \
  154. union { \
  155. int64 val; \
  156. uint32 u32[2]; \
  157. uint16 u16[4]; \
  158. uint8 u8[8]; \
  159. } u; \
  160. if ((addr_ & (uintptr_t)7) == 0) \
  161. *(int64 *)(addr) = (int64)(value); \
  162. else { \
  163. u.val = (int64)(value); \
  164. if ((addr_ & (uintptr_t)3) == 0) { \
  165. ((uint32 *)(addr))[0] = u.u32[0]; \
  166. ((uint32 *)(addr))[1] = u.u32[1]; \
  167. } \
  168. else if ((addr_ & (uintptr_t)1) == 0) { \
  169. ((uint16 *)(addr))[0] = u.u16[0]; \
  170. ((uint16 *)(addr))[1] = u.u16[1]; \
  171. ((uint16 *)(addr))[2] = u.u16[2]; \
  172. ((uint16 *)(addr))[3] = u.u16[3]; \
  173. } \
  174. else { \
  175. int32 t; \
  176. for (t = 0; t < 8; t++) \
  177. ((uint8 *)(addr))[t] = u.u8[t]; \
  178. } \
  179. } \
  180. } while (0)
  181. static inline void
  182. STORE_U32(void *addr, uint32_t value)
  183. {
  184. uintptr_t addr_ = (uintptr_t)(addr);
  185. union {
  186. uint32_t val;
  187. uint16_t u16[2];
  188. uint8_t u8[4];
  189. } u;
  190. if ((addr_ & (uintptr_t)3) == 0)
  191. *(uint32_t *)(addr) = (uint32_t)(value);
  192. else {
  193. u.val = (uint32_t)(value);
  194. if ((addr_ & (uintptr_t)1) == 0) {
  195. ((uint16_t *)(addr))[0] = u.u16[0];
  196. ((uint16_t *)(addr))[1] = u.u16[1];
  197. }
  198. else {
  199. ((uint8_t *)(addr))[0] = u.u8[0];
  200. ((uint8_t *)(addr))[1] = u.u8[1];
  201. ((uint8_t *)(addr))[2] = u.u8[2];
  202. ((uint8_t *)(addr))[3] = u.u8[3];
  203. }
  204. }
  205. }
  206. static inline void
  207. STORE_U8(void *addr, uint8_t value)
  208. {
  209. *(uint8 *)addr = value;
  210. }
  211. static inline void
  212. STORE_U16(void *addr, uint16_t value)
  213. {
  214. union {
  215. uint16_t val;
  216. uint8_t u8[2];
  217. } u;
  218. u.val = (uint16_t)(value);
  219. ((uint8_t *)(addr))[0] = u.u8[0];
  220. ((uint8_t *)(addr))[1] = u.u8[1];
  221. }
  222. /* For LOAD opcodes */
  223. static inline int64
  224. LOAD_I64(void *addr)
  225. {
  226. uintptr_t addr1 = (uintptr_t)addr;
  227. union {
  228. int64 val;
  229. uint32 u32[2];
  230. uint16 u16[4];
  231. uint8 u8[8];
  232. } u;
  233. if ((addr1 & (uintptr_t)7) == 0)
  234. return *(int64 *)addr;
  235. if ((addr1 & (uintptr_t)3) == 0) {
  236. u.u32[0] = ((uint32 *)addr)[0];
  237. u.u32[1] = ((uint32 *)addr)[1];
  238. }
  239. else if ((addr1 & (uintptr_t)1) == 0) {
  240. u.u16[0] = ((uint16 *)addr)[0];
  241. u.u16[1] = ((uint16 *)addr)[1];
  242. u.u16[2] = ((uint16 *)addr)[2];
  243. u.u16[3] = ((uint16 *)addr)[3];
  244. }
  245. else {
  246. int32 t;
  247. for (t = 0; t < 8; t++)
  248. u.u8[t] = ((uint8 *)addr)[t];
  249. }
  250. return u.val;
  251. }
  252. static inline float64
  253. LOAD_F64(void *addr)
  254. {
  255. uintptr_t addr1 = (uintptr_t)addr;
  256. union {
  257. float64 val;
  258. uint32 u32[2];
  259. uint16 u16[4];
  260. uint8 u8[8];
  261. } u;
  262. if ((addr1 & (uintptr_t)7) == 0)
  263. return *(float64 *)addr;
  264. if ((addr1 & (uintptr_t)3) == 0) {
  265. u.u32[0] = ((uint32 *)addr)[0];
  266. u.u32[1] = ((uint32 *)addr)[1];
  267. }
  268. else if ((addr1 & (uintptr_t)1) == 0) {
  269. u.u16[0] = ((uint16 *)addr)[0];
  270. u.u16[1] = ((uint16 *)addr)[1];
  271. u.u16[2] = ((uint16 *)addr)[2];
  272. u.u16[3] = ((uint16 *)addr)[3];
  273. }
  274. else {
  275. int32 t;
  276. for (t = 0; t < 8; t++)
  277. u.u8[t] = ((uint8 *)addr)[t];
  278. }
  279. return u.val;
  280. }
  281. static inline int32
  282. LOAD_I32(void *addr)
  283. {
  284. uintptr_t addr1 = (uintptr_t)addr;
  285. union {
  286. int32 val;
  287. uint16 u16[2];
  288. uint8 u8[4];
  289. } u;
  290. if ((addr1 & (uintptr_t)3) == 0)
  291. return *(int32 *)addr;
  292. if ((addr1 & (uintptr_t)1) == 0) {
  293. u.u16[0] = ((uint16 *)addr)[0];
  294. u.u16[1] = ((uint16 *)addr)[1];
  295. }
  296. else {
  297. u.u8[0] = ((uint8 *)addr)[0];
  298. u.u8[1] = ((uint8 *)addr)[1];
  299. u.u8[2] = ((uint8 *)addr)[2];
  300. u.u8[3] = ((uint8 *)addr)[3];
  301. }
  302. return u.val;
  303. }
  304. static inline int16
  305. LOAD_I16(void *addr)
  306. {
  307. uintptr_t addr1 = (uintptr_t)addr;
  308. union {
  309. int16 val;
  310. uint8 u8[2];
  311. } u;
  312. if ((addr1 & (uintptr_t)1)) {
  313. u.u8[0] = ((uint8 *)addr)[0];
  314. u.u8[1] = ((uint8 *)addr)[1];
  315. return u.val;
  316. }
  317. return *(int16 *)addr;
  318. }
  319. #define LOAD_U32(addr) ((uint32)LOAD_I32(addr))
  320. #define LOAD_U16(addr) ((uint16)LOAD_I16(addr))
  321. #if UINTPTR_MAX == UINT32_MAX
  322. #define STORE_PTR(addr, ptr) STORE_U32(addr, (uintptr_t)ptr)
  323. #elif UINTPTR_MAX == UINT64_MAX
  324. #define STORE_PTR(addr, ptr) STORE_I64(addr, (uintptr_t)ptr)
  325. #endif
  326. #endif /* WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 */
  327. #if WASM_ENABLE_SHARED_MEMORY != 0
  328. #define SHARED_MEMORY_LOCK(memory) shared_memory_lock(memory)
  329. #define SHARED_MEMORY_UNLOCK(memory) shared_memory_unlock(memory)
  330. #else
  331. #define SHARED_MEMORY_LOCK(memory) (void)0
  332. #define SHARED_MEMORY_UNLOCK(memory) (void)0
  333. #endif
  334. #define CLAMP_U64_TO_U32(value) \
  335. ((value) > UINT32_MAX ? UINT32_MAX : (uint32)(value))
  336. typedef struct WASMModuleCommon {
  337. /* Module type, for module loaded from WASM bytecode binary,
  338. this field is Wasm_Module_Bytecode, and this structure should
  339. be treated as WASMModule structure;
  340. for module loaded from AOT binary, this field is
  341. Wasm_Module_AoT, and this structure should be treated as
  342. AOTModule structure. */
  343. uint32 module_type;
  344. /* The following uint8[1] member is a dummy just to indicate
  345. some module_type dependent members follow.
  346. Typically, it should be accessed by casting to the corresponding
  347. actual module_type dependent structure, not via this member. */
  348. uint8 module_data[1];
  349. } WASMModuleCommon;
  350. typedef struct WASMModuleInstanceCommon {
  351. /* Module instance type, for module instance loaded from WASM
  352. bytecode binary, this field is Wasm_Module_Bytecode, and this
  353. structure should be treated as WASMModuleInstance structure;
  354. for module instance loaded from AOT binary, this field is
  355. Wasm_Module_AoT, and this structure should be treated as
  356. AOTModuleInstance structure. */
  357. uint32 module_type;
  358. /* The following uint8[1] member is a dummy just to indicate
  359. some module_type dependent members follow.
  360. Typically, it should be accessed by casting to the corresponding
  361. actual module_type dependent structure, not via this member. */
  362. uint8 module_inst_data[1];
  363. } WASMModuleInstanceCommon;
  364. typedef struct WASMModuleMemConsumption {
  365. uint32 total_size;
  366. uint32 module_struct_size;
  367. uint32 types_size;
  368. uint32 imports_size;
  369. uint32 functions_size;
  370. uint32 tables_size;
  371. uint32 memories_size;
  372. uint32 globals_size;
  373. uint32 exports_size;
  374. uint32 table_segs_size;
  375. uint32 data_segs_size;
  376. uint32 const_strs_size;
  377. #if WASM_ENABLE_AOT != 0
  378. uint32 aot_code_size;
  379. #endif
  380. } WASMModuleMemConsumption;
  381. typedef struct WASMModuleInstMemConsumption {
  382. uint64 total_size;
  383. uint32 module_inst_struct_size;
  384. uint32 app_heap_size;
  385. uint64 memories_size;
  386. uint32 tables_size;
  387. uint32 globals_size;
  388. uint32 functions_size;
  389. uint32 exports_size;
  390. } WASMModuleInstMemConsumption;
  391. #if WASM_ENABLE_LIBC_WASI != 0
  392. #if WASM_ENABLE_UVWASI == 0
  393. typedef struct WASIContext {
  394. struct fd_table *curfds;
  395. struct fd_prestats *prestats;
  396. struct argv_environ_values *argv_environ;
  397. struct addr_pool *addr_pool;
  398. char *ns_lookup_buf;
  399. char **ns_lookup_list;
  400. char *argv_buf;
  401. char **argv_list;
  402. char *env_buf;
  403. char **env_list;
  404. uint32_t exit_code;
  405. } WASIContext;
  406. #else
  407. typedef struct WASIContext {
  408. uvwasi_t uvwasi;
  409. uint32_t exit_code;
  410. } WASIContext;
  411. #endif
  412. #endif
  413. #if WASM_ENABLE_MULTI_MODULE != 0
  414. typedef struct WASMRegisteredModule {
  415. bh_list_link l;
  416. /* point to a string pool */
  417. const char *module_name;
  418. WASMModuleCommon *module;
  419. /* to store the original module file buffer address */
  420. uint8 *orig_file_buf;
  421. uint32 orig_file_buf_size;
  422. } WASMRegisteredModule;
  423. #endif
  424. typedef package_type_t PackageType;
  425. typedef wasm_section_t WASMSection, AOTSection;
  426. typedef struct wasm_frame_t {
  427. /* wasm_instance_t */
  428. void *instance;
  429. uint32 module_offset;
  430. uint32 func_index;
  431. uint32 func_offset;
  432. const char *func_name_wp;
  433. uint32 *sp;
  434. uint8 *frame_ref;
  435. uint32 *lp;
  436. } WASMCApiFrame;
  437. #if WASM_ENABLE_JIT != 0
  438. typedef struct LLVMJITOptions {
  439. uint32 opt_level;
  440. uint32 size_level;
  441. uint32 segue_flags;
  442. bool quick_invoke_c_api_import;
  443. } LLVMJITOptions;
  444. #endif
  445. #ifdef OS_ENABLE_HW_BOUND_CHECK
  446. /* Signal info passing to interp/aot signal handler */
  447. typedef struct WASMSignalInfo {
  448. WASMExecEnv *exec_env_tls;
  449. #ifndef BH_PLATFORM_WINDOWS
  450. void *sig_addr;
  451. #else
  452. EXCEPTION_POINTERS *exce_info;
  453. #endif
  454. } WASMSignalInfo;
  455. /* Set exec_env of thread local storage */
  456. void
  457. wasm_runtime_set_exec_env_tls(WASMExecEnv *exec_env);
  458. /* Get exec_env of thread local storage */
  459. WASMExecEnv *
  460. wasm_runtime_get_exec_env_tls(void);
  461. #endif
  462. /* See wasm_export.h for description */
  463. WASM_RUNTIME_API_EXTERN bool
  464. wasm_runtime_init(void);
  465. /* Internal API */
  466. RunningMode
  467. wasm_runtime_get_default_running_mode(void);
  468. #if WASM_ENABLE_JIT != 0
  469. /* Internal API */
  470. LLVMJITOptions *
  471. wasm_runtime_get_llvm_jit_options(void);
  472. #endif
  473. #if WASM_ENABLE_GC != 0
  474. /* Internal API */
  475. uint32
  476. wasm_runtime_get_gc_heap_size_default(void);
  477. #endif
  478. /* See wasm_export.h for description */
  479. WASM_RUNTIME_API_EXTERN bool
  480. wasm_runtime_full_init(RuntimeInitArgs *init_args);
  481. /* See wasm_export.h for description */
  482. WASM_RUNTIME_API_EXTERN bool
  483. wasm_runtime_is_running_mode_supported(RunningMode running_mode);
  484. /* See wasm_export.h for description */
  485. WASM_RUNTIME_API_EXTERN bool
  486. wasm_runtime_set_default_running_mode(RunningMode running_mode);
  487. /* See wasm_export.h for description */
  488. WASM_RUNTIME_API_EXTERN void
  489. wasm_runtime_destroy(void);
  490. /* See wasm_export.h for description */
  491. WASM_RUNTIME_API_EXTERN PackageType
  492. get_package_type(const uint8 *buf, uint32 size);
  493. /* See wasm_export.h for description */
  494. WASM_RUNTIME_API_EXTERN bool
  495. wasm_runtime_is_xip_file(const uint8 *buf, uint32 size);
  496. /* See wasm_export.h for description */
  497. WASM_RUNTIME_API_EXTERN WASMModuleCommon *
  498. wasm_runtime_load(uint8 *buf, uint32 size, char *error_buf,
  499. uint32 error_buf_size);
  500. /* See wasm_export.h for description */
  501. WASM_RUNTIME_API_EXTERN WASMModuleCommon *
  502. wasm_runtime_load_from_sections(WASMSection *section_list, bool is_aot,
  503. char *error_buf, uint32 error_buf_size);
  504. /* See wasm_export.h for description */
  505. WASM_RUNTIME_API_EXTERN void
  506. wasm_runtime_unload(WASMModuleCommon *module);
  507. /* Internal API */
  508. uint32
  509. wasm_runtime_get_max_mem(uint32 max_memory_pages, uint32 module_init_page_count,
  510. uint32 module_max_page_count);
  511. /* Internal API */
  512. WASMModuleInstanceCommon *
  513. wasm_runtime_instantiate_internal(WASMModuleCommon *module,
  514. WASMModuleInstanceCommon *parent,
  515. WASMExecEnv *exec_env_main, uint32 stack_size,
  516. uint32 heap_size, uint32 max_memory_pages,
  517. char *error_buf, uint32 error_buf_size);
  518. /* Internal API */
  519. void
  520. wasm_runtime_deinstantiate_internal(WASMModuleInstanceCommon *module_inst,
  521. bool is_sub_inst);
  522. /* See wasm_export.h for description */
  523. WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
  524. wasm_runtime_instantiate(WASMModuleCommon *module, uint32 default_stack_size,
  525. uint32 host_managed_heap_size, char *error_buf,
  526. uint32 error_buf_size);
  527. /* See wasm_export.h for description */
  528. WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
  529. wasm_runtime_instantiate_ex(WASMModuleCommon *module,
  530. const InstantiationArgs *args, char *error_buf,
  531. uint32 error_buf_size);
  532. /* See wasm_export.h for description */
  533. WASM_RUNTIME_API_EXTERN bool
  534. wasm_runtime_set_running_mode(wasm_module_inst_t module_inst,
  535. RunningMode running_mode);
  536. /* See wasm_export.h for description */
  537. WASM_RUNTIME_API_EXTERN RunningMode
  538. wasm_runtime_get_running_mode(wasm_module_inst_t module_inst);
  539. /* See wasm_export.h for description */
  540. WASM_RUNTIME_API_EXTERN void
  541. wasm_runtime_deinstantiate(WASMModuleInstanceCommon *module_inst);
  542. /* See wasm_export.h for description */
  543. WASM_RUNTIME_API_EXTERN WASMModuleCommon *
  544. wasm_runtime_get_module(WASMModuleInstanceCommon *module_inst);
  545. /* See wasm_export.h for description */
  546. WASM_RUNTIME_API_EXTERN WASMFunctionInstanceCommon *
  547. wasm_runtime_lookup_function(WASMModuleInstanceCommon *const module_inst,
  548. const char *name);
  549. /* Internal API */
  550. WASMFuncType *
  551. wasm_runtime_get_function_type(const WASMFunctionInstanceCommon *function,
  552. uint32 module_type);
  553. /* See wasm_export.h for description */
  554. WASM_RUNTIME_API_EXTERN uint32
  555. wasm_func_get_param_count(WASMFunctionInstanceCommon *const func_inst,
  556. WASMModuleInstanceCommon *const module_inst);
  557. /* See wasm_export.h for description */
  558. WASM_RUNTIME_API_EXTERN uint32
  559. wasm_func_get_result_count(WASMFunctionInstanceCommon *const func_inst,
  560. WASMModuleInstanceCommon *const module_inst);
  561. /* See wasm_export.h for description */
  562. WASM_RUNTIME_API_EXTERN void
  563. wasm_func_get_param_types(WASMFunctionInstanceCommon *const func_inst,
  564. WASMModuleInstanceCommon *const module_inst,
  565. wasm_valkind_t *param_types);
  566. /* See wasm_export.h for description */
  567. WASM_RUNTIME_API_EXTERN void
  568. wasm_func_get_result_types(WASMFunctionInstanceCommon *const func_inst,
  569. WASMModuleInstanceCommon *const module_inst,
  570. wasm_valkind_t *result_types);
  571. /* See wasm_export.h for description */
  572. WASM_RUNTIME_API_EXTERN WASMExecEnv *
  573. wasm_runtime_create_exec_env(WASMModuleInstanceCommon *module_inst,
  574. uint32 stack_size);
  575. /* See wasm_export.h for description */
  576. WASM_RUNTIME_API_EXTERN void
  577. wasm_runtime_destroy_exec_env(WASMExecEnv *exec_env);
  578. WASM_RUNTIME_API_EXTERN void
  579. wasm_iterate_callstack(const wasm_exec_env_t exec_env,
  580. const wasm_frame_callback frame_handler,
  581. void *user_data);
  582. /* See wasm_export.h for description */
  583. WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
  584. wasm_runtime_get_module_inst(WASMExecEnv *exec_env);
  585. /* See wasm_export.h for description */
  586. WASM_RUNTIME_API_EXTERN void
  587. wasm_runtime_set_module_inst(WASMExecEnv *exec_env,
  588. WASMModuleInstanceCommon *const module_inst);
  589. /* See wasm_export.h for description */
  590. WASM_RUNTIME_API_EXTERN void *
  591. wasm_runtime_get_function_attachment(WASMExecEnv *exec_env);
  592. /* See wasm_export.h for description */
  593. WASM_RUNTIME_API_EXTERN void
  594. wasm_runtime_set_user_data(WASMExecEnv *exec_env, void *user_data);
  595. /* See wasm_export.h for description */
  596. WASM_RUNTIME_API_EXTERN void *
  597. wasm_runtime_get_user_data(WASMExecEnv *exec_env);
  598. /* See wasm_export.h for description */
  599. WASM_RUNTIME_API_EXTERN void
  600. wasm_runtime_set_native_stack_boundary(WASMExecEnv *exec_env,
  601. uint8 *native_stack_boundary);
  602. #if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
  603. /* See wasm_export.h for description */
  604. WASM_RUNTIME_API_EXTERN void
  605. wasm_runtime_set_bounds_checks(WASMModuleInstanceCommon *module_inst,
  606. bool enable);
  607. /* See wasm_export.h for description */
  608. WASM_RUNTIME_API_EXTERN bool
  609. wasm_runtime_is_bounds_checks_enabled(WASMModuleInstanceCommon *module_inst);
  610. #endif
  611. #ifdef OS_ENABLE_HW_BOUND_CHECK
  612. /* Access exception check guard page to trigger the signal handler */
  613. void
  614. wasm_runtime_access_exce_check_guard_page();
  615. #endif
  616. /* See wasm_export.h for description */
  617. WASM_RUNTIME_API_EXTERN bool
  618. wasm_runtime_call_wasm(WASMExecEnv *exec_env,
  619. WASMFunctionInstanceCommon *function, uint32 argc,
  620. uint32 argv[]);
  621. WASM_RUNTIME_API_EXTERN bool
  622. wasm_runtime_call_wasm_a(WASMExecEnv *exec_env,
  623. WASMFunctionInstanceCommon *function,
  624. uint32 num_results, wasm_val_t *results,
  625. uint32 num_args, wasm_val_t *args);
  626. WASM_RUNTIME_API_EXTERN bool
  627. wasm_runtime_call_wasm_v(WASMExecEnv *exec_env,
  628. WASMFunctionInstanceCommon *function,
  629. uint32 num_results, wasm_val_t *results,
  630. uint32 num_args, ...);
  631. /* See wasm_export.h for description */
  632. WASM_RUNTIME_API_EXTERN bool
  633. wasm_runtime_call_indirect(WASMExecEnv *exec_env, uint32 element_index,
  634. uint32 argc, uint32 argv[]);
  635. #if WASM_ENABLE_DEBUG_INTERP != 0
  636. /* See wasm_export.h for description */
  637. WASM_RUNTIME_API_EXTERN uint32
  638. wasm_runtime_start_debug_instance_with_port(WASMExecEnv *exec_env,
  639. int32_t port);
  640. /* See wasm_export.h for description */
  641. WASM_RUNTIME_API_EXTERN uint32
  642. wasm_runtime_start_debug_instance(WASMExecEnv *exec_env);
  643. #endif
  644. bool
  645. wasm_runtime_create_exec_env_singleton(WASMModuleInstanceCommon *module_inst);
  646. /* See wasm_export.h for description */
  647. WASM_RUNTIME_API_EXTERN WASMExecEnv *
  648. wasm_runtime_get_exec_env_singleton(WASMModuleInstanceCommon *module_inst);
  649. /* See wasm_export.h for description */
  650. WASM_RUNTIME_API_EXTERN bool
  651. wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
  652. char *argv[]);
  653. /* See wasm_export.h for description */
  654. WASM_RUNTIME_API_EXTERN bool
  655. wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
  656. const char *name, int32 argc, char *argv[]);
  657. /* See wasm_export.h for description */
  658. WASM_RUNTIME_API_EXTERN void
  659. wasm_runtime_set_exception(WASMModuleInstanceCommon *module,
  660. const char *exception);
  661. /* See wasm_export.h for description */
  662. WASM_RUNTIME_API_EXTERN const char *
  663. wasm_runtime_get_exception(WASMModuleInstanceCommon *module);
  664. /* See wasm_export.h for description */
  665. WASM_RUNTIME_API_EXTERN void
  666. wasm_runtime_clear_exception(WASMModuleInstanceCommon *module_inst);
  667. /* See wasm_export.h for description */
  668. WASM_RUNTIME_API_EXTERN void
  669. wasm_runtime_terminate(WASMModuleInstanceCommon *module);
  670. /* Internal API */
  671. void
  672. wasm_runtime_set_custom_data_internal(WASMModuleInstanceCommon *module_inst,
  673. void *custom_data);
  674. /* See wasm_export.h for description */
  675. WASM_RUNTIME_API_EXTERN void
  676. wasm_runtime_set_custom_data(WASMModuleInstanceCommon *module_inst,
  677. void *custom_data);
  678. /* See wasm_export.h for description */
  679. WASM_RUNTIME_API_EXTERN void *
  680. wasm_runtime_get_custom_data(WASMModuleInstanceCommon *module_inst);
  681. /* Internal API */
  682. uint64
  683. wasm_runtime_module_malloc_internal(WASMModuleInstanceCommon *module_inst,
  684. WASMExecEnv *exec_env, uint64 size,
  685. void **p_native_addr);
  686. /* Internal API */
  687. uint64
  688. wasm_runtime_module_realloc_internal(WASMModuleInstanceCommon *module_inst,
  689. WASMExecEnv *exec_env, uint64 ptr,
  690. uint64 size, void **p_native_addr);
  691. /* Internal API */
  692. void
  693. wasm_runtime_module_free_internal(WASMModuleInstanceCommon *module_inst,
  694. WASMExecEnv *exec_env, uint64 ptr);
  695. /* See wasm_export.h for description */
  696. WASM_RUNTIME_API_EXTERN uint64
  697. wasm_runtime_module_malloc(WASMModuleInstanceCommon *module_inst, uint64 size,
  698. void **p_native_addr);
  699. /* See wasm_export.h for description */
  700. WASM_RUNTIME_API_EXTERN void
  701. wasm_runtime_module_free(WASMModuleInstanceCommon *module_inst, uint64 ptr);
  702. /* See wasm_export.h for description */
  703. WASM_RUNTIME_API_EXTERN uint64
  704. wasm_runtime_module_dup_data(WASMModuleInstanceCommon *module_inst,
  705. const char *src, uint64 size);
  706. /* See wasm_export.h for description */
  707. WASM_RUNTIME_API_EXTERN bool
  708. wasm_runtime_validate_app_addr(WASMModuleInstanceCommon *module_inst,
  709. uint64 app_offset, uint64 size);
  710. /* See wasm_export.h for description */
  711. WASM_RUNTIME_API_EXTERN bool
  712. wasm_runtime_validate_app_str_addr(WASMModuleInstanceCommon *module_inst,
  713. uint64 app_str_offset);
  714. /* See wasm_export.h for description */
  715. WASM_RUNTIME_API_EXTERN bool
  716. wasm_runtime_validate_native_addr(WASMModuleInstanceCommon *module_inst,
  717. void *native_ptr, uint64 size);
  718. /* See wasm_export.h for description */
  719. WASM_RUNTIME_API_EXTERN void *
  720. wasm_runtime_addr_app_to_native(WASMModuleInstanceCommon *module_inst,
  721. uint64 app_offset);
  722. /* See wasm_export.h for description */
  723. WASM_RUNTIME_API_EXTERN uint64
  724. wasm_runtime_addr_native_to_app(WASMModuleInstanceCommon *module_inst,
  725. void *native_ptr);
  726. /* See wasm_export.h for description */
  727. WASM_RUNTIME_API_EXTERN bool
  728. wasm_runtime_get_app_addr_range(WASMModuleInstanceCommon *module_inst,
  729. uint64 app_offset, uint64 *p_app_start_offset,
  730. uint64 *p_app_end_offset);
  731. /* See wasm_export.h for description */
  732. WASM_RUNTIME_API_EXTERN bool
  733. wasm_runtime_get_native_addr_range(WASMModuleInstanceCommon *module_inst,
  734. uint8 *native_ptr,
  735. uint8 **p_native_start_addr,
  736. uint8 **p_native_end_addr);
  737. /* See wasm_export.h for description */
  738. WASM_RUNTIME_API_EXTERN const uint8 *
  739. wasm_runtime_get_custom_section(WASMModuleCommon *const module_comm,
  740. const char *name, uint32 *len);
  741. #if WASM_ENABLE_MULTI_MODULE != 0
  742. WASM_RUNTIME_API_EXTERN void
  743. wasm_runtime_set_module_reader(const module_reader reader,
  744. const module_destroyer destroyer);
  745. module_reader
  746. wasm_runtime_get_module_reader(void);
  747. module_destroyer
  748. wasm_runtime_get_module_destroyer(void);
  749. bool
  750. wasm_runtime_register_module_internal(const char *module_name,
  751. WASMModuleCommon *module,
  752. uint8 *orig_file_buf,
  753. uint32 orig_file_buf_size,
  754. char *error_buf, uint32 error_buf_size);
  755. void
  756. wasm_runtime_unregister_module(const WASMModuleCommon *module);
  757. WASMModuleCommon *
  758. wasm_runtime_find_module_registered(const char *module_name);
  759. bool
  760. wasm_runtime_add_loading_module(const char *module_name, char *error_buf,
  761. uint32 error_buf_size);
  762. void
  763. wasm_runtime_delete_loading_module(const char *module_name);
  764. bool
  765. wasm_runtime_is_loading_module(const char *module_name);
  766. void
  767. wasm_runtime_destroy_loading_module_list(void);
  768. WASMModuleCommon *
  769. wasm_runtime_search_sub_module(const WASMModuleCommon *parent_module,
  770. const char *sub_module_name);
  771. bool
  772. wasm_runtime_register_sub_module(const WASMModuleCommon *parent_module,
  773. const char *sub_module_name,
  774. WASMModuleCommon *sub_module);
  775. WASMModuleCommon *
  776. wasm_runtime_load_depended_module(const WASMModuleCommon *parent_module,
  777. const char *sub_module_name, char *error_buf,
  778. uint32 error_buf_size);
  779. bool
  780. wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
  781. WASMModuleInstanceCommon *module_inst,
  782. uint32 stack_size, uint32 heap_size,
  783. uint32 max_memory_pages, char *error_buf,
  784. uint32 error_buf_size);
  785. void
  786. wasm_runtime_sub_module_deinstantiate(WASMModuleInstanceCommon *module_inst);
  787. #endif
  788. #if WASM_ENABLE_LIBC_WASI != 0 || WASM_ENABLE_MULTI_MODULE != 0
  789. WASMExport *
  790. loader_find_export(const WASMModuleCommon *module, const char *module_name,
  791. const char *field_name, uint8 export_kind, char *error_buf,
  792. uint32 error_buf_size);
  793. #endif /* WASM_ENABLE_MULTI_MODULE */
  794. bool
  795. wasm_runtime_is_built_in_module(const char *module_name);
  796. #if WASM_ENABLE_THREAD_MGR != 0
  797. bool
  798. wasm_exec_env_get_aux_stack(WASMExecEnv *exec_env, uint64 *start_offset,
  799. uint32 *size);
  800. bool
  801. wasm_exec_env_set_aux_stack(WASMExecEnv *exec_env, uint64 start_offset,
  802. uint32 size);
  803. #endif
  804. #if WASM_ENABLE_LIBC_WASI != 0
  805. WASM_RUNTIME_API_EXTERN void
  806. wasm_runtime_set_wasi_args_ex(WASMModuleCommon *module, const char *dir_list[],
  807. uint32 dir_count, const char *map_dir_list[],
  808. uint32 map_dir_count, const char *env_list[],
  809. uint32 env_count, char *argv[], int argc,
  810. int64 stdinfd, int64 stdoutfd, int64 stderrfd);
  811. /* See wasm_export.h for description */
  812. WASM_RUNTIME_API_EXTERN void
  813. wasm_runtime_set_wasi_args(WASMModuleCommon *module, const char *dir_list[],
  814. uint32 dir_count, const char *map_dir_list[],
  815. uint32 map_dir_count, const char *env_list[],
  816. uint32 env_count, char *argv[], int argc);
  817. /* See wasm_export.h for description */
  818. WASM_RUNTIME_API_EXTERN bool
  819. wasm_runtime_is_wasi_mode(WASMModuleInstanceCommon *module_inst);
  820. /* See wasm_export.h for description */
  821. WASM_RUNTIME_API_EXTERN WASMFunctionInstanceCommon *
  822. wasm_runtime_lookup_wasi_start_function(WASMModuleInstanceCommon *module_inst);
  823. /* See wasm_export.h for description */
  824. WASM_RUNTIME_API_EXTERN uint32_t
  825. wasm_runtime_get_wasi_exit_code(WASMModuleInstanceCommon *module_inst);
  826. bool
  827. wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
  828. const char *dir_list[], uint32 dir_count,
  829. const char *map_dir_list[], uint32 map_dir_count,
  830. const char *env[], uint32 env_count,
  831. const char *addr_pool[], uint32 addr_pool_size,
  832. const char *ns_lookup_pool[], uint32 ns_lookup_pool_size,
  833. char *argv[], uint32 argc, os_raw_file_handle stdinfd,
  834. os_raw_file_handle stdoutfd, os_raw_file_handle stderrfd,
  835. char *error_buf, uint32 error_buf_size);
  836. void
  837. wasm_runtime_destroy_wasi(WASMModuleInstanceCommon *module_inst);
  838. void
  839. wasm_runtime_set_wasi_ctx(WASMModuleInstanceCommon *module_inst,
  840. WASIContext *wasi_ctx);
  841. WASIContext *
  842. wasm_runtime_get_wasi_ctx(WASMModuleInstanceCommon *module_inst);
  843. WASM_RUNTIME_API_EXTERN void
  844. wasm_runtime_set_wasi_addr_pool(wasm_module_t module, const char *addr_pool[],
  845. uint32 addr_pool_size);
  846. WASM_RUNTIME_API_EXTERN void
  847. wasm_runtime_set_wasi_ns_lookup_pool(wasm_module_t module,
  848. const char *ns_lookup_pool[],
  849. uint32 ns_lookup_pool_size);
  850. #endif /* end of WASM_ENABLE_LIBC_WASI */
  851. #if WASM_ENABLE_GC != 0
  852. void
  853. wasm_runtime_set_gc_heap_handle(WASMModuleInstanceCommon *module_inst,
  854. void *gc_heap_handle);
  855. void *
  856. wasm_runtime_get_gc_heap_handle(WASMModuleInstanceCommon *module_inst);
  857. #endif
  858. #if WASM_ENABLE_REF_TYPES != 0
  859. /* See wasm_export.h for description */
  860. WASM_RUNTIME_API_EXTERN bool
  861. wasm_externref_obj2ref(WASMModuleInstanceCommon *module_inst, void *extern_obj,
  862. uint32 *p_externref_idx);
  863. /* See wasm_export.h for description */
  864. WASM_RUNTIME_API_EXTERN bool
  865. wasm_externref_ref2obj(uint32 externref_idx, void **p_extern_obj);
  866. /* See wasm_export.h for description */
  867. WASM_RUNTIME_API_EXTERN bool
  868. wasm_externref_retain(uint32 externref_idx);
  869. /**
  870. * Reclaim the externref objects/indexes which are not used by
  871. * module instance
  872. */
  873. void
  874. wasm_externref_reclaim(WASMModuleInstanceCommon *module_inst);
  875. /**
  876. * Cleanup the externref objects/indexes of the module instance
  877. */
  878. void
  879. wasm_externref_cleanup(WASMModuleInstanceCommon *module_inst);
  880. #endif /* end of WASM_ENABLE_REF_TYPES */
  881. #if WASM_ENABLE_DUMP_CALL_STACK != 0
  882. /**
  883. * @brief Internal implementation for dumping or printing callstack line
  884. *
  885. * @note if dump_or_print is true, then print to stdout directly;
  886. * if dump_or_print is false, but *buf is NULL, then return the length of the
  887. * line;
  888. * if dump_or_print is false, and *buf is not NULL, then dump content to
  889. * the memory pointed by *buf, and adjust *buf and *len according to actual
  890. * bytes dumped, and return the actual dumped length
  891. *
  892. * @param line_buf current line to dump or print
  893. * @param dump_or_print whether to print to stdout or dump to buf
  894. * @param buf [INOUT] pointer to the buffer
  895. * @param len [INOUT] pointer to remaining length
  896. * @return bytes printed to stdout or dumped to buf
  897. */
  898. uint32
  899. wasm_runtime_dump_line_buf_impl(const char *line_buf, bool dump_or_print,
  900. char **buf, uint32 *len);
  901. #endif /* end of WASM_ENABLE_DUMP_CALL_STACK != 0 */
  902. /* Get module of the current exec_env */
  903. WASMModuleCommon *
  904. wasm_exec_env_get_module(WASMExecEnv *exec_env);
  905. /* See wasm_export.h for description */
  906. WASM_RUNTIME_API_EXTERN bool
  907. wasm_runtime_register_natives(const char *module_name,
  908. NativeSymbol *native_symbols,
  909. uint32 n_native_symbols);
  910. /* See wasm_export.h for description */
  911. WASM_RUNTIME_API_EXTERN bool
  912. wasm_runtime_register_natives_raw(const char *module_name,
  913. NativeSymbol *native_symbols,
  914. uint32 n_native_symbols);
  915. /* See wasm_export.h for description */
  916. WASM_RUNTIME_API_EXTERN bool
  917. wasm_runtime_unregister_natives(const char *module_name,
  918. NativeSymbol *native_symbols);
  919. /* See wasm_export.h for description */
  920. WASM_RUNTIME_API_EXTERN void *
  921. wasm_runtime_create_context_key(void (*dtor)(WASMModuleInstanceCommon *inst,
  922. void *ctx));
  923. /* See wasm_export.h for description */
  924. WASM_RUNTIME_API_EXTERN void
  925. wasm_runtime_destroy_context_key(void *key);
  926. /* See wasm_export.h for description */
  927. WASM_RUNTIME_API_EXTERN void
  928. wasm_runtime_set_context(WASMModuleInstanceCommon *inst, void *key, void *ctx);
  929. /* See wasm_export.h for description */
  930. WASM_RUNTIME_API_EXTERN void
  931. wasm_runtime_set_context_spread(WASMModuleInstanceCommon *inst, void *key,
  932. void *ctx);
  933. /* See wasm_export.h for description */
  934. WASM_RUNTIME_API_EXTERN void *
  935. wasm_runtime_get_context(WASMModuleInstanceCommon *inst, void *key);
  936. bool
  937. wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
  938. const WASMFuncType *func_type, const char *signature,
  939. void *attachment, uint32 *argv, uint32 argc,
  940. uint32 *ret);
  941. bool
  942. wasm_runtime_invoke_native_raw(WASMExecEnv *exec_env, void *func_ptr,
  943. const WASMFuncType *func_type,
  944. const char *signature, void *attachment,
  945. uint32 *argv, uint32 argc, uint32 *ret);
  946. void
  947. wasm_runtime_read_v128(const uint8 *bytes, uint64 *ret1, uint64 *ret2);
  948. void
  949. wasm_runtime_dump_module_mem_consumption(const WASMModuleCommon *module);
  950. void
  951. wasm_runtime_dump_module_inst_mem_consumption(
  952. const WASMModuleInstanceCommon *module_inst);
  953. void
  954. wasm_runtime_dump_exec_env_mem_consumption(const WASMExecEnv *exec_env);
  955. bool
  956. wasm_runtime_get_table_elem_type(const WASMModuleCommon *module_comm,
  957. uint32 table_idx, uint8 *out_elem_type,
  958. #if WASM_ENABLE_GC != 0
  959. WASMRefType **out_ref_type,
  960. #endif
  961. uint32 *out_min_size, uint32 *out_max_size);
  962. bool
  963. wasm_runtime_get_table_inst_elem_type(
  964. const WASMModuleInstanceCommon *module_inst_comm, uint32 table_idx,
  965. uint8 *out_elem_type,
  966. #if WASM_ENABLE_GC != 0
  967. WASMRefType **out_ref_type,
  968. #endif
  969. uint32 *out_min_size, uint32 *out_max_size);
  970. bool
  971. wasm_runtime_get_export_func_type(const WASMModuleCommon *module_comm,
  972. const WASMExport *export_,
  973. WASMFuncType **out);
  974. bool
  975. wasm_runtime_get_export_global_type(const WASMModuleCommon *module_comm,
  976. const WASMExport *export_,
  977. uint8 *out_val_type, bool *out_mutability);
  978. bool
  979. wasm_runtime_get_export_memory_type(const WASMModuleCommon *module_comm,
  980. const WASMExport *export_,
  981. uint32 *out_min_page, uint32 *out_max_page);
  982. bool
  983. wasm_runtime_get_export_table_type(const WASMModuleCommon *module_comm,
  984. const WASMExport *export_,
  985. uint8 *out_elem_type,
  986. #if WASM_ENABLE_GC != 0
  987. WASMRefType **out_ref_type,
  988. #endif
  989. uint32 *out_min_size, uint32 *out_max_size);
  990. bool
  991. wasm_runtime_invoke_c_api_native(WASMModuleInstanceCommon *module_inst,
  992. void *func_ptr, WASMFuncType *func_type,
  993. uint32 argc, uint32 *argv, bool with_env,
  994. void *wasm_c_api_env);
  995. struct CApiFuncImport;
  996. /* A quick version of wasm_runtime_invoke_c_api_native to directly invoke
  997. wasm-c-api import function from jitted code to improve performance */
  998. bool
  999. wasm_runtime_quick_invoke_c_api_native(WASMModuleInstanceCommon *module_inst,
  1000. struct CApiFuncImport *c_api_import,
  1001. wasm_val_t *params, uint32 param_count,
  1002. wasm_val_t *results,
  1003. uint32 result_count);
  1004. void
  1005. wasm_runtime_show_app_heap_corrupted_prompt(void);
  1006. #if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
  1007. void
  1008. wasm_runtime_destroy_custom_sections(WASMCustomSection *section_list);
  1009. #endif
  1010. WASM_RUNTIME_API_EXTERN bool
  1011. wasm_runtime_is_import_func_linked(const char *module_name,
  1012. const char *func_name);
  1013. WASM_RUNTIME_API_EXTERN bool
  1014. wasm_runtime_is_import_global_linked(const char *module_name,
  1015. const char *global_name);
  1016. WASM_RUNTIME_API_EXTERN bool
  1017. wasm_runtime_begin_blocking_op(WASMExecEnv *exec_env);
  1018. WASM_RUNTIME_API_EXTERN void
  1019. wasm_runtime_end_blocking_op(WASMExecEnv *exec_env);
  1020. void
  1021. wasm_runtime_interrupt_blocking_op(WASMExecEnv *exec_env);
  1022. WASM_RUNTIME_API_EXTERN bool
  1023. wasm_runtime_detect_native_stack_overflow(WASMExecEnv *exec_env);
  1024. WASM_RUNTIME_API_EXTERN bool
  1025. wasm_runtime_detect_native_stack_overflow_size(WASMExecEnv *exec_env,
  1026. uint32 requested_size);
  1027. WASM_RUNTIME_API_EXTERN bool
  1028. wasm_runtime_is_underlying_binary_freeable(WASMModuleCommon *const module);
  1029. #if WASM_ENABLE_LINUX_PERF != 0
  1030. bool
  1031. wasm_runtime_get_linux_perf(void);
  1032. void
  1033. wasm_runtime_set_linux_perf(bool flag);
  1034. #endif
  1035. #ifdef __cplusplus
  1036. }
  1037. #endif
  1038. #endif /* end of _WASM_COMMON_H */