wasm_runtime_common.h 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  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. #if WASM_ENABLE_JIT != 0
  427. typedef struct LLVMJITOptions {
  428. uint32 opt_level;
  429. uint32 size_level;
  430. uint32 segue_flags;
  431. bool quick_invoke_c_api_import;
  432. } LLVMJITOptions;
  433. #endif
  434. #ifdef OS_ENABLE_HW_BOUND_CHECK
  435. /* Signal info passing to interp/aot signal handler */
  436. typedef struct WASMSignalInfo {
  437. WASMExecEnv *exec_env_tls;
  438. #ifndef BH_PLATFORM_WINDOWS
  439. void *sig_addr;
  440. #else
  441. EXCEPTION_POINTERS *exce_info;
  442. #endif
  443. } WASMSignalInfo;
  444. /* Set exec_env of thread local storage */
  445. void
  446. wasm_runtime_set_exec_env_tls(WASMExecEnv *exec_env);
  447. /* Get exec_env of thread local storage */
  448. WASMExecEnv *
  449. wasm_runtime_get_exec_env_tls(void);
  450. #endif
  451. /* See wasm_export.h for description */
  452. WASM_RUNTIME_API_EXTERN bool
  453. wasm_runtime_init(void);
  454. /* Internal API */
  455. RunningMode
  456. wasm_runtime_get_default_running_mode(void);
  457. #if WASM_ENABLE_JIT != 0
  458. /* Internal API */
  459. LLVMJITOptions *
  460. wasm_runtime_get_llvm_jit_options(void);
  461. #endif
  462. #if WASM_ENABLE_GC != 0
  463. /* Internal API */
  464. uint32
  465. wasm_runtime_get_gc_heap_size_default(void);
  466. #endif
  467. /* See wasm_export.h for description */
  468. WASM_RUNTIME_API_EXTERN bool
  469. wasm_runtime_full_init(RuntimeInitArgs *init_args);
  470. /* See wasm_export.h for description */
  471. WASM_RUNTIME_API_EXTERN bool
  472. wasm_runtime_is_running_mode_supported(RunningMode running_mode);
  473. /* See wasm_export.h for description */
  474. WASM_RUNTIME_API_EXTERN bool
  475. wasm_runtime_set_default_running_mode(RunningMode running_mode);
  476. /* See wasm_export.h for description */
  477. WASM_RUNTIME_API_EXTERN void
  478. wasm_runtime_destroy(void);
  479. /* See wasm_export.h for description */
  480. WASM_RUNTIME_API_EXTERN PackageType
  481. get_package_type(const uint8 *buf, uint32 size);
  482. /* See wasm_export.h for description */
  483. WASM_RUNTIME_API_EXTERN bool
  484. wasm_runtime_is_xip_file(const uint8 *buf, uint32 size);
  485. /* See wasm_export.h for description */
  486. WASM_RUNTIME_API_EXTERN WASMModuleCommon *
  487. wasm_runtime_load(uint8 *buf, uint32 size, char *error_buf,
  488. uint32 error_buf_size);
  489. /* See wasm_export.h for description */
  490. WASM_RUNTIME_API_EXTERN WASMModuleCommon *
  491. wasm_runtime_load_from_sections(WASMSection *section_list, bool is_aot,
  492. char *error_buf, uint32 error_buf_size);
  493. /* See wasm_export.h for description */
  494. WASM_RUNTIME_API_EXTERN void
  495. wasm_runtime_unload(WASMModuleCommon *module);
  496. /* Internal API */
  497. uint32
  498. wasm_runtime_get_max_mem(uint32 max_memory_pages, uint32 module_init_page_count,
  499. uint32 module_max_page_count);
  500. /* Internal API */
  501. WASMModuleInstanceCommon *
  502. wasm_runtime_instantiate_internal(WASMModuleCommon *module,
  503. WASMModuleInstanceCommon *parent,
  504. WASMExecEnv *exec_env_main, uint32 stack_size,
  505. uint32 heap_size, uint32 max_memory_pages,
  506. char *error_buf, uint32 error_buf_size);
  507. /* Internal API */
  508. void
  509. wasm_runtime_deinstantiate_internal(WASMModuleInstanceCommon *module_inst,
  510. bool is_sub_inst);
  511. /* See wasm_export.h for description */
  512. WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
  513. wasm_runtime_instantiate(WASMModuleCommon *module, uint32 default_stack_size,
  514. uint32 host_managed_heap_size, char *error_buf,
  515. uint32 error_buf_size);
  516. /* See wasm_export.h for description */
  517. WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
  518. wasm_runtime_instantiate_ex(WASMModuleCommon *module,
  519. const InstantiationArgs *args, char *error_buf,
  520. uint32 error_buf_size);
  521. /* See wasm_export.h for description */
  522. WASM_RUNTIME_API_EXTERN bool
  523. wasm_runtime_set_running_mode(wasm_module_inst_t module_inst,
  524. RunningMode running_mode);
  525. /* See wasm_export.h for description */
  526. WASM_RUNTIME_API_EXTERN RunningMode
  527. wasm_runtime_get_running_mode(wasm_module_inst_t module_inst);
  528. /* See wasm_export.h for description */
  529. WASM_RUNTIME_API_EXTERN void
  530. wasm_runtime_deinstantiate(WASMModuleInstanceCommon *module_inst);
  531. /* See wasm_export.h for description */
  532. WASM_RUNTIME_API_EXTERN WASMModuleCommon *
  533. wasm_runtime_get_module(WASMModuleInstanceCommon *module_inst);
  534. /* See wasm_export.h for description */
  535. WASM_RUNTIME_API_EXTERN WASMFunctionInstanceCommon *
  536. wasm_runtime_lookup_function(WASMModuleInstanceCommon *const module_inst,
  537. const char *name);
  538. /* Internal API */
  539. WASMFuncType *
  540. wasm_runtime_get_function_type(const WASMFunctionInstanceCommon *function,
  541. uint32 module_type);
  542. /* See wasm_export.h for description */
  543. WASM_RUNTIME_API_EXTERN uint32
  544. wasm_func_get_param_count(WASMFunctionInstanceCommon *const func_inst,
  545. WASMModuleInstanceCommon *const module_inst);
  546. /* See wasm_export.h for description */
  547. WASM_RUNTIME_API_EXTERN uint32
  548. wasm_func_get_result_count(WASMFunctionInstanceCommon *const func_inst,
  549. WASMModuleInstanceCommon *const module_inst);
  550. /* See wasm_export.h for description */
  551. WASM_RUNTIME_API_EXTERN void
  552. wasm_func_get_param_types(WASMFunctionInstanceCommon *const func_inst,
  553. WASMModuleInstanceCommon *const module_inst,
  554. wasm_valkind_t *param_types);
  555. /* See wasm_export.h for description */
  556. WASM_RUNTIME_API_EXTERN void
  557. wasm_func_get_result_types(WASMFunctionInstanceCommon *const func_inst,
  558. WASMModuleInstanceCommon *const module_inst,
  559. wasm_valkind_t *result_types);
  560. /* See wasm_export.h for description */
  561. WASM_RUNTIME_API_EXTERN WASMExecEnv *
  562. wasm_runtime_create_exec_env(WASMModuleInstanceCommon *module_inst,
  563. uint32 stack_size);
  564. /* See wasm_export.h for description */
  565. WASM_RUNTIME_API_EXTERN void
  566. wasm_runtime_destroy_exec_env(WASMExecEnv *exec_env);
  567. #if WAMR_ENABLE_COPY_CALLSTACK != 0
  568. WASM_RUNTIME_API_EXTERN uint32_t
  569. wasm_copy_callstack(const wasm_exec_env_t exec_env, wasm_frame_t *buffer,
  570. const uint32 length, const uint32 skip_n, char *error_buf,
  571. uint32 error_buf_size);
  572. #endif // WAMR_ENABLE_COPY_CALLSTACK
  573. /* See wasm_export.h for description */
  574. WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
  575. wasm_runtime_get_module_inst(WASMExecEnv *exec_env);
  576. /* See wasm_export.h for description */
  577. WASM_RUNTIME_API_EXTERN void
  578. wasm_runtime_set_module_inst(WASMExecEnv *exec_env,
  579. WASMModuleInstanceCommon *const module_inst);
  580. /* See wasm_export.h for description */
  581. WASM_RUNTIME_API_EXTERN void *
  582. wasm_runtime_get_function_attachment(WASMExecEnv *exec_env);
  583. /* See wasm_export.h for description */
  584. WASM_RUNTIME_API_EXTERN void
  585. wasm_runtime_set_user_data(WASMExecEnv *exec_env, void *user_data);
  586. /* See wasm_export.h for description */
  587. WASM_RUNTIME_API_EXTERN void *
  588. wasm_runtime_get_user_data(WASMExecEnv *exec_env);
  589. /* See wasm_export.h for description */
  590. WASM_RUNTIME_API_EXTERN void
  591. wasm_runtime_set_native_stack_boundary(WASMExecEnv *exec_env,
  592. uint8 *native_stack_boundary);
  593. #if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
  594. /* See wasm_export.h for description */
  595. WASM_RUNTIME_API_EXTERN void
  596. wasm_runtime_set_bounds_checks(WASMModuleInstanceCommon *module_inst,
  597. bool enable);
  598. /* See wasm_export.h for description */
  599. WASM_RUNTIME_API_EXTERN bool
  600. wasm_runtime_is_bounds_checks_enabled(WASMModuleInstanceCommon *module_inst);
  601. #endif
  602. #ifdef OS_ENABLE_HW_BOUND_CHECK
  603. /* Access exception check guard page to trigger the signal handler */
  604. void
  605. wasm_runtime_access_exce_check_guard_page();
  606. #endif
  607. /* See wasm_export.h for description */
  608. WASM_RUNTIME_API_EXTERN bool
  609. wasm_runtime_call_wasm(WASMExecEnv *exec_env,
  610. WASMFunctionInstanceCommon *function, uint32 argc,
  611. uint32 argv[]);
  612. WASM_RUNTIME_API_EXTERN bool
  613. wasm_runtime_call_wasm_a(WASMExecEnv *exec_env,
  614. WASMFunctionInstanceCommon *function,
  615. uint32 num_results, wasm_val_t *results,
  616. uint32 num_args, wasm_val_t *args);
  617. WASM_RUNTIME_API_EXTERN bool
  618. wasm_runtime_call_wasm_v(WASMExecEnv *exec_env,
  619. WASMFunctionInstanceCommon *function,
  620. uint32 num_results, wasm_val_t *results,
  621. uint32 num_args, ...);
  622. /* See wasm_export.h for description */
  623. WASM_RUNTIME_API_EXTERN bool
  624. wasm_runtime_call_indirect(WASMExecEnv *exec_env, uint32 element_index,
  625. uint32 argc, uint32 argv[]);
  626. #if WASM_ENABLE_DEBUG_INTERP != 0
  627. /* See wasm_export.h for description */
  628. WASM_RUNTIME_API_EXTERN uint32
  629. wasm_runtime_start_debug_instance_with_port(WASMExecEnv *exec_env,
  630. int32_t port);
  631. /* See wasm_export.h for description */
  632. WASM_RUNTIME_API_EXTERN uint32
  633. wasm_runtime_start_debug_instance(WASMExecEnv *exec_env);
  634. #endif
  635. bool
  636. wasm_runtime_create_exec_env_singleton(WASMModuleInstanceCommon *module_inst);
  637. /* See wasm_export.h for description */
  638. WASM_RUNTIME_API_EXTERN WASMExecEnv *
  639. wasm_runtime_get_exec_env_singleton(WASMModuleInstanceCommon *module_inst);
  640. /* See wasm_export.h for description */
  641. WASM_RUNTIME_API_EXTERN bool
  642. wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
  643. char *argv[]);
  644. /* See wasm_export.h for description */
  645. WASM_RUNTIME_API_EXTERN bool
  646. wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
  647. const char *name, int32 argc, char *argv[]);
  648. /* See wasm_export.h for description */
  649. WASM_RUNTIME_API_EXTERN void
  650. wasm_runtime_set_exception(WASMModuleInstanceCommon *module,
  651. const char *exception);
  652. /* See wasm_export.h for description */
  653. WASM_RUNTIME_API_EXTERN const char *
  654. wasm_runtime_get_exception(WASMModuleInstanceCommon *module);
  655. /* See wasm_export.h for description */
  656. WASM_RUNTIME_API_EXTERN void
  657. wasm_runtime_clear_exception(WASMModuleInstanceCommon *module_inst);
  658. /* See wasm_export.h for description */
  659. WASM_RUNTIME_API_EXTERN void
  660. wasm_runtime_terminate(WASMModuleInstanceCommon *module);
  661. /* Internal API */
  662. void
  663. wasm_runtime_set_custom_data_internal(WASMModuleInstanceCommon *module_inst,
  664. void *custom_data);
  665. /* See wasm_export.h for description */
  666. WASM_RUNTIME_API_EXTERN void
  667. wasm_runtime_set_custom_data(WASMModuleInstanceCommon *module_inst,
  668. void *custom_data);
  669. /* See wasm_export.h for description */
  670. WASM_RUNTIME_API_EXTERN void *
  671. wasm_runtime_get_custom_data(WASMModuleInstanceCommon *module_inst);
  672. /* Internal API */
  673. uint64
  674. wasm_runtime_module_malloc_internal(WASMModuleInstanceCommon *module_inst,
  675. WASMExecEnv *exec_env, uint64 size,
  676. void **p_native_addr);
  677. /* Internal API */
  678. uint64
  679. wasm_runtime_module_realloc_internal(WASMModuleInstanceCommon *module_inst,
  680. WASMExecEnv *exec_env, uint64 ptr,
  681. uint64 size, void **p_native_addr);
  682. /* Internal API */
  683. void
  684. wasm_runtime_module_free_internal(WASMModuleInstanceCommon *module_inst,
  685. WASMExecEnv *exec_env, uint64 ptr);
  686. /* See wasm_export.h for description */
  687. WASM_RUNTIME_API_EXTERN uint64
  688. wasm_runtime_module_malloc(WASMModuleInstanceCommon *module_inst, uint64 size,
  689. void **p_native_addr);
  690. /* See wasm_export.h for description */
  691. WASM_RUNTIME_API_EXTERN void
  692. wasm_runtime_module_free(WASMModuleInstanceCommon *module_inst, uint64 ptr);
  693. /* See wasm_export.h for description */
  694. WASM_RUNTIME_API_EXTERN uint64
  695. wasm_runtime_module_dup_data(WASMModuleInstanceCommon *module_inst,
  696. const char *src, uint64 size);
  697. /* See wasm_export.h for description */
  698. WASM_RUNTIME_API_EXTERN bool
  699. wasm_runtime_validate_app_addr(WASMModuleInstanceCommon *module_inst,
  700. uint64 app_offset, uint64 size);
  701. /* See wasm_export.h for description */
  702. WASM_RUNTIME_API_EXTERN bool
  703. wasm_runtime_validate_app_str_addr(WASMModuleInstanceCommon *module_inst,
  704. uint64 app_str_offset);
  705. /* See wasm_export.h for description */
  706. WASM_RUNTIME_API_EXTERN bool
  707. wasm_runtime_validate_native_addr(WASMModuleInstanceCommon *module_inst,
  708. void *native_ptr, uint64 size);
  709. /* See wasm_export.h for description */
  710. WASM_RUNTIME_API_EXTERN void *
  711. wasm_runtime_addr_app_to_native(WASMModuleInstanceCommon *module_inst,
  712. uint64 app_offset);
  713. /* See wasm_export.h for description */
  714. WASM_RUNTIME_API_EXTERN uint64
  715. wasm_runtime_addr_native_to_app(WASMModuleInstanceCommon *module_inst,
  716. void *native_ptr);
  717. /* See wasm_export.h for description */
  718. WASM_RUNTIME_API_EXTERN bool
  719. wasm_runtime_get_app_addr_range(WASMModuleInstanceCommon *module_inst,
  720. uint64 app_offset, uint64 *p_app_start_offset,
  721. uint64 *p_app_end_offset);
  722. /* See wasm_export.h for description */
  723. WASM_RUNTIME_API_EXTERN bool
  724. wasm_runtime_get_native_addr_range(WASMModuleInstanceCommon *module_inst,
  725. uint8 *native_ptr,
  726. uint8 **p_native_start_addr,
  727. uint8 **p_native_end_addr);
  728. /* See wasm_export.h for description */
  729. WASM_RUNTIME_API_EXTERN const uint8 *
  730. wasm_runtime_get_custom_section(WASMModuleCommon *const module_comm,
  731. const char *name, uint32 *len);
  732. #if WASM_ENABLE_MULTI_MODULE != 0
  733. WASM_RUNTIME_API_EXTERN void
  734. wasm_runtime_set_module_reader(const module_reader reader,
  735. const module_destroyer destroyer);
  736. module_reader
  737. wasm_runtime_get_module_reader(void);
  738. module_destroyer
  739. wasm_runtime_get_module_destroyer(void);
  740. bool
  741. wasm_runtime_register_module_internal(const char *module_name,
  742. WASMModuleCommon *module,
  743. uint8 *orig_file_buf,
  744. uint32 orig_file_buf_size,
  745. char *error_buf, uint32 error_buf_size);
  746. void
  747. wasm_runtime_unregister_module(const WASMModuleCommon *module);
  748. WASMModuleCommon *
  749. wasm_runtime_find_module_registered(const char *module_name);
  750. bool
  751. wasm_runtime_add_loading_module(const char *module_name, char *error_buf,
  752. uint32 error_buf_size);
  753. void
  754. wasm_runtime_delete_loading_module(const char *module_name);
  755. bool
  756. wasm_runtime_is_loading_module(const char *module_name);
  757. void
  758. wasm_runtime_destroy_loading_module_list(void);
  759. WASMModuleCommon *
  760. wasm_runtime_search_sub_module(const WASMModuleCommon *parent_module,
  761. const char *sub_module_name);
  762. bool
  763. wasm_runtime_register_sub_module(const WASMModuleCommon *parent_module,
  764. const char *sub_module_name,
  765. WASMModuleCommon *sub_module);
  766. WASMModuleCommon *
  767. wasm_runtime_load_depended_module(const WASMModuleCommon *parent_module,
  768. const char *sub_module_name, char *error_buf,
  769. uint32 error_buf_size);
  770. bool
  771. wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
  772. WASMModuleInstanceCommon *module_inst,
  773. uint32 stack_size, uint32 heap_size,
  774. uint32 max_memory_pages, char *error_buf,
  775. uint32 error_buf_size);
  776. void
  777. wasm_runtime_sub_module_deinstantiate(WASMModuleInstanceCommon *module_inst);
  778. #endif
  779. #if WASM_ENABLE_LIBC_WASI != 0 || WASM_ENABLE_MULTI_MODULE != 0
  780. WASMExport *
  781. loader_find_export(const WASMModuleCommon *module, const char *module_name,
  782. const char *field_name, uint8 export_kind, char *error_buf,
  783. uint32 error_buf_size);
  784. #endif /* WASM_ENABLE_MULTI_MODULE */
  785. bool
  786. wasm_runtime_is_built_in_module(const char *module_name);
  787. #if WASM_ENABLE_THREAD_MGR != 0
  788. bool
  789. wasm_exec_env_get_aux_stack(WASMExecEnv *exec_env, uint64 *start_offset,
  790. uint32 *size);
  791. bool
  792. wasm_exec_env_set_aux_stack(WASMExecEnv *exec_env, uint64 start_offset,
  793. uint32 size);
  794. #endif
  795. #if WASM_ENABLE_LIBC_WASI != 0
  796. WASM_RUNTIME_API_EXTERN void
  797. wasm_runtime_set_wasi_args_ex(WASMModuleCommon *module, const char *dir_list[],
  798. uint32 dir_count, const char *map_dir_list[],
  799. uint32 map_dir_count, const char *env_list[],
  800. uint32 env_count, char *argv[], int argc,
  801. int64 stdinfd, int64 stdoutfd, int64 stderrfd);
  802. /* See wasm_export.h for description */
  803. WASM_RUNTIME_API_EXTERN void
  804. wasm_runtime_set_wasi_args(WASMModuleCommon *module, const char *dir_list[],
  805. uint32 dir_count, const char *map_dir_list[],
  806. uint32 map_dir_count, const char *env_list[],
  807. uint32 env_count, char *argv[], int argc);
  808. /* See wasm_export.h for description */
  809. WASM_RUNTIME_API_EXTERN bool
  810. wasm_runtime_is_wasi_mode(WASMModuleInstanceCommon *module_inst);
  811. /* See wasm_export.h for description */
  812. WASM_RUNTIME_API_EXTERN WASMFunctionInstanceCommon *
  813. wasm_runtime_lookup_wasi_start_function(WASMModuleInstanceCommon *module_inst);
  814. /* See wasm_export.h for description */
  815. WASM_RUNTIME_API_EXTERN uint32_t
  816. wasm_runtime_get_wasi_exit_code(WASMModuleInstanceCommon *module_inst);
  817. bool
  818. wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
  819. const char *dir_list[], uint32 dir_count,
  820. const char *map_dir_list[], uint32 map_dir_count,
  821. const char *env[], uint32 env_count,
  822. const char *addr_pool[], uint32 addr_pool_size,
  823. const char *ns_lookup_pool[], uint32 ns_lookup_pool_size,
  824. char *argv[], uint32 argc, os_raw_file_handle stdinfd,
  825. os_raw_file_handle stdoutfd, os_raw_file_handle stderrfd,
  826. char *error_buf, uint32 error_buf_size);
  827. void
  828. wasm_runtime_destroy_wasi(WASMModuleInstanceCommon *module_inst);
  829. void
  830. wasm_runtime_set_wasi_ctx(WASMModuleInstanceCommon *module_inst,
  831. WASIContext *wasi_ctx);
  832. WASIContext *
  833. wasm_runtime_get_wasi_ctx(WASMModuleInstanceCommon *module_inst);
  834. WASM_RUNTIME_API_EXTERN void
  835. wasm_runtime_set_wasi_addr_pool(wasm_module_t module, const char *addr_pool[],
  836. uint32 addr_pool_size);
  837. WASM_RUNTIME_API_EXTERN void
  838. wasm_runtime_set_wasi_ns_lookup_pool(wasm_module_t module,
  839. const char *ns_lookup_pool[],
  840. uint32 ns_lookup_pool_size);
  841. #endif /* end of WASM_ENABLE_LIBC_WASI */
  842. #if WASM_ENABLE_GC != 0
  843. void
  844. wasm_runtime_set_gc_heap_handle(WASMModuleInstanceCommon *module_inst,
  845. void *gc_heap_handle);
  846. void *
  847. wasm_runtime_get_gc_heap_handle(WASMModuleInstanceCommon *module_inst);
  848. #endif
  849. #if WASM_ENABLE_REF_TYPES != 0
  850. /* See wasm_export.h for description */
  851. WASM_RUNTIME_API_EXTERN bool
  852. wasm_externref_obj2ref(WASMModuleInstanceCommon *module_inst, void *extern_obj,
  853. uint32 *p_externref_idx);
  854. /* See wasm_export.h for description */
  855. WASM_RUNTIME_API_EXTERN bool
  856. wasm_externref_ref2obj(uint32 externref_idx, void **p_extern_obj);
  857. /* See wasm_export.h for description */
  858. WASM_RUNTIME_API_EXTERN bool
  859. wasm_externref_retain(uint32 externref_idx);
  860. /**
  861. * Reclaim the externref objects/indexes which are not used by
  862. * module instance
  863. */
  864. void
  865. wasm_externref_reclaim(WASMModuleInstanceCommon *module_inst);
  866. /**
  867. * Cleanup the externref objects/indexes of the module instance
  868. */
  869. void
  870. wasm_externref_cleanup(WASMModuleInstanceCommon *module_inst);
  871. #endif /* end of WASM_ENABLE_REF_TYPES */
  872. #if WASM_ENABLE_DUMP_CALL_STACK != 0
  873. /**
  874. * @brief Internal implementation for dumping or printing callstack line
  875. *
  876. * @note if dump_or_print is true, then print to stdout directly;
  877. * if dump_or_print is false, but *buf is NULL, then return the length of the
  878. * line;
  879. * if dump_or_print is false, and *buf is not NULL, then dump content to
  880. * the memory pointed by *buf, and adjust *buf and *len according to actual
  881. * bytes dumped, and return the actual dumped length
  882. *
  883. * @param line_buf current line to dump or print
  884. * @param dump_or_print whether to print to stdout or dump to buf
  885. * @param buf [INOUT] pointer to the buffer
  886. * @param len [INOUT] pointer to remaining length
  887. * @return bytes printed to stdout or dumped to buf
  888. */
  889. uint32
  890. wasm_runtime_dump_line_buf_impl(const char *line_buf, bool dump_or_print,
  891. char **buf, uint32 *len);
  892. #endif /* end of WASM_ENABLE_DUMP_CALL_STACK != 0 */
  893. /* Get module of the current exec_env */
  894. WASMModuleCommon *
  895. wasm_exec_env_get_module(WASMExecEnv *exec_env);
  896. /* See wasm_export.h for description */
  897. WASM_RUNTIME_API_EXTERN bool
  898. wasm_runtime_register_natives(const char *module_name,
  899. NativeSymbol *native_symbols,
  900. uint32 n_native_symbols);
  901. /* See wasm_export.h for description */
  902. WASM_RUNTIME_API_EXTERN bool
  903. wasm_runtime_register_natives_raw(const char *module_name,
  904. NativeSymbol *native_symbols,
  905. uint32 n_native_symbols);
  906. /* See wasm_export.h for description */
  907. WASM_RUNTIME_API_EXTERN bool
  908. wasm_runtime_unregister_natives(const char *module_name,
  909. NativeSymbol *native_symbols);
  910. /* See wasm_export.h for description */
  911. WASM_RUNTIME_API_EXTERN void *
  912. wasm_runtime_create_context_key(void (*dtor)(WASMModuleInstanceCommon *inst,
  913. void *ctx));
  914. /* See wasm_export.h for description */
  915. WASM_RUNTIME_API_EXTERN void
  916. wasm_runtime_destroy_context_key(void *key);
  917. /* See wasm_export.h for description */
  918. WASM_RUNTIME_API_EXTERN void
  919. wasm_runtime_set_context(WASMModuleInstanceCommon *inst, void *key, void *ctx);
  920. /* See wasm_export.h for description */
  921. WASM_RUNTIME_API_EXTERN void
  922. wasm_runtime_set_context_spread(WASMModuleInstanceCommon *inst, void *key,
  923. void *ctx);
  924. /* See wasm_export.h for description */
  925. WASM_RUNTIME_API_EXTERN void *
  926. wasm_runtime_get_context(WASMModuleInstanceCommon *inst, void *key);
  927. bool
  928. wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
  929. const WASMFuncType *func_type, const char *signature,
  930. void *attachment, uint32 *argv, uint32 argc,
  931. uint32 *ret);
  932. bool
  933. wasm_runtime_invoke_native_raw(WASMExecEnv *exec_env, void *func_ptr,
  934. const WASMFuncType *func_type,
  935. const char *signature, void *attachment,
  936. uint32 *argv, uint32 argc, uint32 *ret);
  937. void
  938. wasm_runtime_read_v128(const uint8 *bytes, uint64 *ret1, uint64 *ret2);
  939. void
  940. wasm_runtime_dump_module_mem_consumption(const WASMModuleCommon *module);
  941. void
  942. wasm_runtime_dump_module_inst_mem_consumption(
  943. const WASMModuleInstanceCommon *module_inst);
  944. void
  945. wasm_runtime_dump_exec_env_mem_consumption(const WASMExecEnv *exec_env);
  946. bool
  947. wasm_runtime_get_table_elem_type(const WASMModuleCommon *module_comm,
  948. uint32 table_idx, uint8 *out_elem_type,
  949. #if WASM_ENABLE_GC != 0
  950. WASMRefType **out_ref_type,
  951. #endif
  952. uint32 *out_min_size, uint32 *out_max_size);
  953. bool
  954. wasm_runtime_get_table_inst_elem_type(
  955. const WASMModuleInstanceCommon *module_inst_comm, uint32 table_idx,
  956. uint8 *out_elem_type,
  957. #if WASM_ENABLE_GC != 0
  958. WASMRefType **out_ref_type,
  959. #endif
  960. uint32 *out_min_size, uint32 *out_max_size);
  961. bool
  962. wasm_runtime_get_export_func_type(const WASMModuleCommon *module_comm,
  963. const WASMExport *export_,
  964. WASMFuncType **out);
  965. bool
  966. wasm_runtime_get_export_global_type(const WASMModuleCommon *module_comm,
  967. const WASMExport *export_,
  968. uint8 *out_val_type, bool *out_mutability);
  969. bool
  970. wasm_runtime_get_export_memory_type(const WASMModuleCommon *module_comm,
  971. const WASMExport *export_,
  972. uint32 *out_min_page, uint32 *out_max_page);
  973. bool
  974. wasm_runtime_get_export_table_type(const WASMModuleCommon *module_comm,
  975. const WASMExport *export_,
  976. uint8 *out_elem_type,
  977. #if WASM_ENABLE_GC != 0
  978. WASMRefType **out_ref_type,
  979. #endif
  980. uint32 *out_min_size, uint32 *out_max_size);
  981. bool
  982. wasm_runtime_invoke_c_api_native(WASMModuleInstanceCommon *module_inst,
  983. void *func_ptr, WASMFuncType *func_type,
  984. uint32 argc, uint32 *argv, bool with_env,
  985. void *wasm_c_api_env);
  986. struct CApiFuncImport;
  987. /* A quick version of wasm_runtime_invoke_c_api_native to directly invoke
  988. wasm-c-api import function from jitted code to improve performance */
  989. bool
  990. wasm_runtime_quick_invoke_c_api_native(WASMModuleInstanceCommon *module_inst,
  991. struct CApiFuncImport *c_api_import,
  992. wasm_val_t *params, uint32 param_count,
  993. wasm_val_t *results,
  994. uint32 result_count);
  995. void
  996. wasm_runtime_show_app_heap_corrupted_prompt(void);
  997. #if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
  998. void
  999. wasm_runtime_destroy_custom_sections(WASMCustomSection *section_list);
  1000. #endif
  1001. WASM_RUNTIME_API_EXTERN bool
  1002. wasm_runtime_is_import_func_linked(const char *module_name,
  1003. const char *func_name);
  1004. WASM_RUNTIME_API_EXTERN bool
  1005. wasm_runtime_is_import_global_linked(const char *module_name,
  1006. const char *global_name);
  1007. WASM_RUNTIME_API_EXTERN bool
  1008. wasm_runtime_begin_blocking_op(WASMExecEnv *exec_env);
  1009. WASM_RUNTIME_API_EXTERN void
  1010. wasm_runtime_end_blocking_op(WASMExecEnv *exec_env);
  1011. void
  1012. wasm_runtime_interrupt_blocking_op(WASMExecEnv *exec_env);
  1013. WASM_RUNTIME_API_EXTERN bool
  1014. wasm_runtime_detect_native_stack_overflow(WASMExecEnv *exec_env);
  1015. WASM_RUNTIME_API_EXTERN bool
  1016. wasm_runtime_detect_native_stack_overflow_size(WASMExecEnv *exec_env,
  1017. uint32 requested_size);
  1018. WASM_RUNTIME_API_EXTERN bool
  1019. wasm_runtime_is_underlying_binary_freeable(WASMModuleCommon *const module);
  1020. #if WASM_ENABLE_LINUX_PERF != 0
  1021. bool
  1022. wasm_runtime_get_linux_perf(void);
  1023. void
  1024. wasm_runtime_set_linux_perf(bool flag);
  1025. #endif
  1026. #ifdef __cplusplus
  1027. }
  1028. #endif
  1029. #endif /* end of _WASM_COMMON_H */