wasm_runtime_common.h 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  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_ptr_t buffer,
  570. const uint32 length, const uint32 skip_n);
  571. #endif // WAMR_ENABLE_COPY_CALLSTACK
  572. /* See wasm_export.h for description */
  573. WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
  574. wasm_runtime_get_module_inst(WASMExecEnv *exec_env);
  575. /* See wasm_export.h for description */
  576. WASM_RUNTIME_API_EXTERN void
  577. wasm_runtime_set_module_inst(WASMExecEnv *exec_env,
  578. WASMModuleInstanceCommon *const module_inst);
  579. /* See wasm_export.h for description */
  580. WASM_RUNTIME_API_EXTERN void *
  581. wasm_runtime_get_function_attachment(WASMExecEnv *exec_env);
  582. /* See wasm_export.h for description */
  583. WASM_RUNTIME_API_EXTERN void
  584. wasm_runtime_set_user_data(WASMExecEnv *exec_env, void *user_data);
  585. /* See wasm_export.h for description */
  586. WASM_RUNTIME_API_EXTERN void *
  587. wasm_runtime_get_user_data(WASMExecEnv *exec_env);
  588. /* See wasm_export.h for description */
  589. WASM_RUNTIME_API_EXTERN void
  590. wasm_runtime_set_native_stack_boundary(WASMExecEnv *exec_env,
  591. uint8 *native_stack_boundary);
  592. #if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
  593. /* See wasm_export.h for description */
  594. WASM_RUNTIME_API_EXTERN void
  595. wasm_runtime_set_bounds_checks(WASMModuleInstanceCommon *module_inst,
  596. bool enable);
  597. /* See wasm_export.h for description */
  598. WASM_RUNTIME_API_EXTERN bool
  599. wasm_runtime_is_bounds_checks_enabled(WASMModuleInstanceCommon *module_inst);
  600. #endif
  601. #ifdef OS_ENABLE_HW_BOUND_CHECK
  602. /* Access exception check guard page to trigger the signal handler */
  603. void
  604. wasm_runtime_access_exce_check_guard_page();
  605. #endif
  606. /* See wasm_export.h for description */
  607. WASM_RUNTIME_API_EXTERN bool
  608. wasm_runtime_call_wasm(WASMExecEnv *exec_env,
  609. WASMFunctionInstanceCommon *function, uint32 argc,
  610. uint32 argv[]);
  611. WASM_RUNTIME_API_EXTERN bool
  612. wasm_runtime_call_wasm_a(WASMExecEnv *exec_env,
  613. WASMFunctionInstanceCommon *function,
  614. uint32 num_results, wasm_val_t *results,
  615. uint32 num_args, wasm_val_t *args);
  616. WASM_RUNTIME_API_EXTERN bool
  617. wasm_runtime_call_wasm_v(WASMExecEnv *exec_env,
  618. WASMFunctionInstanceCommon *function,
  619. uint32 num_results, wasm_val_t *results,
  620. uint32 num_args, ...);
  621. /* See wasm_export.h for description */
  622. WASM_RUNTIME_API_EXTERN bool
  623. wasm_runtime_call_indirect(WASMExecEnv *exec_env, uint32 element_index,
  624. uint32 argc, uint32 argv[]);
  625. #if WASM_ENABLE_DEBUG_INTERP != 0
  626. /* See wasm_export.h for description */
  627. WASM_RUNTIME_API_EXTERN uint32
  628. wasm_runtime_start_debug_instance_with_port(WASMExecEnv *exec_env,
  629. int32_t port);
  630. /* See wasm_export.h for description */
  631. WASM_RUNTIME_API_EXTERN uint32
  632. wasm_runtime_start_debug_instance(WASMExecEnv *exec_env);
  633. #endif
  634. bool
  635. wasm_runtime_create_exec_env_singleton(WASMModuleInstanceCommon *module_inst);
  636. /* See wasm_export.h for description */
  637. WASM_RUNTIME_API_EXTERN WASMExecEnv *
  638. wasm_runtime_get_exec_env_singleton(WASMModuleInstanceCommon *module_inst);
  639. /* See wasm_export.h for description */
  640. WASM_RUNTIME_API_EXTERN bool
  641. wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
  642. char *argv[]);
  643. /* See wasm_export.h for description */
  644. WASM_RUNTIME_API_EXTERN bool
  645. wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
  646. const char *name, int32 argc, char *argv[]);
  647. /* See wasm_export.h for description */
  648. WASM_RUNTIME_API_EXTERN void
  649. wasm_runtime_set_exception(WASMModuleInstanceCommon *module,
  650. const char *exception);
  651. /* See wasm_export.h for description */
  652. WASM_RUNTIME_API_EXTERN const char *
  653. wasm_runtime_get_exception(WASMModuleInstanceCommon *module);
  654. /* See wasm_export.h for description */
  655. WASM_RUNTIME_API_EXTERN void
  656. wasm_runtime_clear_exception(WASMModuleInstanceCommon *module_inst);
  657. /* See wasm_export.h for description */
  658. WASM_RUNTIME_API_EXTERN void
  659. wasm_runtime_terminate(WASMModuleInstanceCommon *module);
  660. /* Internal API */
  661. void
  662. wasm_runtime_set_custom_data_internal(WASMModuleInstanceCommon *module_inst,
  663. void *custom_data);
  664. /* See wasm_export.h for description */
  665. WASM_RUNTIME_API_EXTERN void
  666. wasm_runtime_set_custom_data(WASMModuleInstanceCommon *module_inst,
  667. void *custom_data);
  668. /* See wasm_export.h for description */
  669. WASM_RUNTIME_API_EXTERN void *
  670. wasm_runtime_get_custom_data(WASMModuleInstanceCommon *module_inst);
  671. /* Internal API */
  672. uint64
  673. wasm_runtime_module_malloc_internal(WASMModuleInstanceCommon *module_inst,
  674. WASMExecEnv *exec_env, uint64 size,
  675. void **p_native_addr);
  676. /* Internal API */
  677. uint64
  678. wasm_runtime_module_realloc_internal(WASMModuleInstanceCommon *module_inst,
  679. WASMExecEnv *exec_env, uint64 ptr,
  680. uint64 size, void **p_native_addr);
  681. /* Internal API */
  682. void
  683. wasm_runtime_module_free_internal(WASMModuleInstanceCommon *module_inst,
  684. WASMExecEnv *exec_env, uint64 ptr);
  685. /* See wasm_export.h for description */
  686. WASM_RUNTIME_API_EXTERN uint64
  687. wasm_runtime_module_malloc(WASMModuleInstanceCommon *module_inst, uint64 size,
  688. void **p_native_addr);
  689. /* See wasm_export.h for description */
  690. WASM_RUNTIME_API_EXTERN void
  691. wasm_runtime_module_free(WASMModuleInstanceCommon *module_inst, uint64 ptr);
  692. /* See wasm_export.h for description */
  693. WASM_RUNTIME_API_EXTERN uint64
  694. wasm_runtime_module_dup_data(WASMModuleInstanceCommon *module_inst,
  695. const char *src, uint64 size);
  696. /* See wasm_export.h for description */
  697. WASM_RUNTIME_API_EXTERN bool
  698. wasm_runtime_validate_app_addr(WASMModuleInstanceCommon *module_inst,
  699. uint64 app_offset, uint64 size);
  700. /* See wasm_export.h for description */
  701. WASM_RUNTIME_API_EXTERN bool
  702. wasm_runtime_validate_app_str_addr(WASMModuleInstanceCommon *module_inst,
  703. uint64 app_str_offset);
  704. /* See wasm_export.h for description */
  705. WASM_RUNTIME_API_EXTERN bool
  706. wasm_runtime_validate_native_addr(WASMModuleInstanceCommon *module_inst,
  707. void *native_ptr, uint64 size);
  708. /* See wasm_export.h for description */
  709. WASM_RUNTIME_API_EXTERN void *
  710. wasm_runtime_addr_app_to_native(WASMModuleInstanceCommon *module_inst,
  711. uint64 app_offset);
  712. /* See wasm_export.h for description */
  713. WASM_RUNTIME_API_EXTERN uint64
  714. wasm_runtime_addr_native_to_app(WASMModuleInstanceCommon *module_inst,
  715. void *native_ptr);
  716. /* See wasm_export.h for description */
  717. WASM_RUNTIME_API_EXTERN bool
  718. wasm_runtime_get_app_addr_range(WASMModuleInstanceCommon *module_inst,
  719. uint64 app_offset, uint64 *p_app_start_offset,
  720. uint64 *p_app_end_offset);
  721. /* See wasm_export.h for description */
  722. WASM_RUNTIME_API_EXTERN bool
  723. wasm_runtime_get_native_addr_range(WASMModuleInstanceCommon *module_inst,
  724. uint8 *native_ptr,
  725. uint8 **p_native_start_addr,
  726. uint8 **p_native_end_addr);
  727. /* See wasm_export.h for description */
  728. WASM_RUNTIME_API_EXTERN const uint8 *
  729. wasm_runtime_get_custom_section(WASMModuleCommon *const module_comm,
  730. const char *name, uint32 *len);
  731. #if WASM_ENABLE_MULTI_MODULE != 0
  732. WASM_RUNTIME_API_EXTERN void
  733. wasm_runtime_set_module_reader(const module_reader reader,
  734. const module_destroyer destroyer);
  735. module_reader
  736. wasm_runtime_get_module_reader(void);
  737. module_destroyer
  738. wasm_runtime_get_module_destroyer(void);
  739. bool
  740. wasm_runtime_register_module_internal(const char *module_name,
  741. WASMModuleCommon *module,
  742. uint8 *orig_file_buf,
  743. uint32 orig_file_buf_size,
  744. char *error_buf, uint32 error_buf_size);
  745. void
  746. wasm_runtime_unregister_module(const WASMModuleCommon *module);
  747. WASMModuleCommon *
  748. wasm_runtime_find_module_registered(const char *module_name);
  749. bool
  750. wasm_runtime_add_loading_module(const char *module_name, char *error_buf,
  751. uint32 error_buf_size);
  752. void
  753. wasm_runtime_delete_loading_module(const char *module_name);
  754. bool
  755. wasm_runtime_is_loading_module(const char *module_name);
  756. void
  757. wasm_runtime_destroy_loading_module_list(void);
  758. WASMModuleCommon *
  759. wasm_runtime_search_sub_module(const WASMModuleCommon *parent_module,
  760. const char *sub_module_name);
  761. bool
  762. wasm_runtime_register_sub_module(const WASMModuleCommon *parent_module,
  763. const char *sub_module_name,
  764. WASMModuleCommon *sub_module);
  765. WASMModuleCommon *
  766. wasm_runtime_load_depended_module(const WASMModuleCommon *parent_module,
  767. const char *sub_module_name, char *error_buf,
  768. uint32 error_buf_size);
  769. bool
  770. wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
  771. WASMModuleInstanceCommon *module_inst,
  772. uint32 stack_size, uint32 heap_size,
  773. uint32 max_memory_pages, char *error_buf,
  774. uint32 error_buf_size);
  775. void
  776. wasm_runtime_sub_module_deinstantiate(WASMModuleInstanceCommon *module_inst);
  777. #endif
  778. #if WASM_ENABLE_LIBC_WASI != 0 || WASM_ENABLE_MULTI_MODULE != 0
  779. WASMExport *
  780. loader_find_export(const WASMModuleCommon *module, const char *module_name,
  781. const char *field_name, uint8 export_kind, char *error_buf,
  782. uint32 error_buf_size);
  783. #endif /* WASM_ENABLE_MULTI_MODULE */
  784. bool
  785. wasm_runtime_is_built_in_module(const char *module_name);
  786. #if WASM_ENABLE_THREAD_MGR != 0
  787. bool
  788. wasm_exec_env_get_aux_stack(WASMExecEnv *exec_env, uint64 *start_offset,
  789. uint32 *size);
  790. bool
  791. wasm_exec_env_set_aux_stack(WASMExecEnv *exec_env, uint64 start_offset,
  792. uint32 size);
  793. #endif
  794. #if WASM_ENABLE_LIBC_WASI != 0
  795. WASM_RUNTIME_API_EXTERN void
  796. wasm_runtime_set_wasi_args_ex(WASMModuleCommon *module, const char *dir_list[],
  797. uint32 dir_count, const char *map_dir_list[],
  798. uint32 map_dir_count, const char *env_list[],
  799. uint32 env_count, char *argv[], int argc,
  800. int64 stdinfd, int64 stdoutfd, int64 stderrfd);
  801. /* See wasm_export.h for description */
  802. WASM_RUNTIME_API_EXTERN void
  803. wasm_runtime_set_wasi_args(WASMModuleCommon *module, const char *dir_list[],
  804. uint32 dir_count, const char *map_dir_list[],
  805. uint32 map_dir_count, const char *env_list[],
  806. uint32 env_count, char *argv[], int argc);
  807. /* See wasm_export.h for description */
  808. WASM_RUNTIME_API_EXTERN bool
  809. wasm_runtime_is_wasi_mode(WASMModuleInstanceCommon *module_inst);
  810. /* See wasm_export.h for description */
  811. WASM_RUNTIME_API_EXTERN WASMFunctionInstanceCommon *
  812. wasm_runtime_lookup_wasi_start_function(WASMModuleInstanceCommon *module_inst);
  813. /* See wasm_export.h for description */
  814. WASM_RUNTIME_API_EXTERN uint32_t
  815. wasm_runtime_get_wasi_exit_code(WASMModuleInstanceCommon *module_inst);
  816. bool
  817. wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
  818. const char *dir_list[], uint32 dir_count,
  819. const char *map_dir_list[], uint32 map_dir_count,
  820. const char *env[], uint32 env_count,
  821. const char *addr_pool[], uint32 addr_pool_size,
  822. const char *ns_lookup_pool[], uint32 ns_lookup_pool_size,
  823. char *argv[], uint32 argc, os_raw_file_handle stdinfd,
  824. os_raw_file_handle stdoutfd, os_raw_file_handle stderrfd,
  825. char *error_buf, uint32 error_buf_size);
  826. void
  827. wasm_runtime_destroy_wasi(WASMModuleInstanceCommon *module_inst);
  828. void
  829. wasm_runtime_set_wasi_ctx(WASMModuleInstanceCommon *module_inst,
  830. WASIContext *wasi_ctx);
  831. WASIContext *
  832. wasm_runtime_get_wasi_ctx(WASMModuleInstanceCommon *module_inst);
  833. WASM_RUNTIME_API_EXTERN void
  834. wasm_runtime_set_wasi_addr_pool(wasm_module_t module, const char *addr_pool[],
  835. uint32 addr_pool_size);
  836. WASM_RUNTIME_API_EXTERN void
  837. wasm_runtime_set_wasi_ns_lookup_pool(wasm_module_t module,
  838. const char *ns_lookup_pool[],
  839. uint32 ns_lookup_pool_size);
  840. #endif /* end of WASM_ENABLE_LIBC_WASI */
  841. #if WASM_ENABLE_GC != 0
  842. void
  843. wasm_runtime_set_gc_heap_handle(WASMModuleInstanceCommon *module_inst,
  844. void *gc_heap_handle);
  845. void *
  846. wasm_runtime_get_gc_heap_handle(WASMModuleInstanceCommon *module_inst);
  847. #endif
  848. #if WASM_ENABLE_REF_TYPES != 0
  849. /* See wasm_export.h for description */
  850. WASM_RUNTIME_API_EXTERN bool
  851. wasm_externref_obj2ref(WASMModuleInstanceCommon *module_inst, void *extern_obj,
  852. uint32 *p_externref_idx);
  853. /* See wasm_export.h for description */
  854. WASM_RUNTIME_API_EXTERN bool
  855. wasm_externref_ref2obj(uint32 externref_idx, void **p_extern_obj);
  856. /* See wasm_export.h for description */
  857. WASM_RUNTIME_API_EXTERN bool
  858. wasm_externref_retain(uint32 externref_idx);
  859. /**
  860. * Reclaim the externref objects/indexes which are not used by
  861. * module instance
  862. */
  863. void
  864. wasm_externref_reclaim(WASMModuleInstanceCommon *module_inst);
  865. /**
  866. * Cleanup the externref objects/indexes of the module instance
  867. */
  868. void
  869. wasm_externref_cleanup(WASMModuleInstanceCommon *module_inst);
  870. #endif /* end of WASM_ENABLE_REF_TYPES */
  871. #if WASM_ENABLE_DUMP_CALL_STACK != 0
  872. /**
  873. * @brief Internal implementation for dumping or printing callstack line
  874. *
  875. * @note if dump_or_print is true, then print to stdout directly;
  876. * if dump_or_print is false, but *buf is NULL, then return the length of the
  877. * line;
  878. * if dump_or_print is false, and *buf is not NULL, then dump content to
  879. * the memory pointed by *buf, and adjust *buf and *len according to actual
  880. * bytes dumped, and return the actual dumped length
  881. *
  882. * @param line_buf current line to dump or print
  883. * @param dump_or_print whether to print to stdout or dump to buf
  884. * @param buf [INOUT] pointer to the buffer
  885. * @param len [INOUT] pointer to remaining length
  886. * @return bytes printed to stdout or dumped to buf
  887. */
  888. uint32
  889. wasm_runtime_dump_line_buf_impl(const char *line_buf, bool dump_or_print,
  890. char **buf, uint32 *len);
  891. #endif /* end of WASM_ENABLE_DUMP_CALL_STACK != 0 */
  892. /* Get module of the current exec_env */
  893. WASMModuleCommon *
  894. wasm_exec_env_get_module(WASMExecEnv *exec_env);
  895. /* See wasm_export.h for description */
  896. WASM_RUNTIME_API_EXTERN bool
  897. wasm_runtime_register_natives(const char *module_name,
  898. NativeSymbol *native_symbols,
  899. uint32 n_native_symbols);
  900. /* See wasm_export.h for description */
  901. WASM_RUNTIME_API_EXTERN bool
  902. wasm_runtime_register_natives_raw(const char *module_name,
  903. NativeSymbol *native_symbols,
  904. uint32 n_native_symbols);
  905. /* See wasm_export.h for description */
  906. WASM_RUNTIME_API_EXTERN bool
  907. wasm_runtime_unregister_natives(const char *module_name,
  908. NativeSymbol *native_symbols);
  909. /* See wasm_export.h for description */
  910. WASM_RUNTIME_API_EXTERN void *
  911. wasm_runtime_create_context_key(void (*dtor)(WASMModuleInstanceCommon *inst,
  912. void *ctx));
  913. /* See wasm_export.h for description */
  914. WASM_RUNTIME_API_EXTERN void
  915. wasm_runtime_destroy_context_key(void *key);
  916. /* See wasm_export.h for description */
  917. WASM_RUNTIME_API_EXTERN void
  918. wasm_runtime_set_context(WASMModuleInstanceCommon *inst, void *key, void *ctx);
  919. /* See wasm_export.h for description */
  920. WASM_RUNTIME_API_EXTERN void
  921. wasm_runtime_set_context_spread(WASMModuleInstanceCommon *inst, void *key,
  922. void *ctx);
  923. /* See wasm_export.h for description */
  924. WASM_RUNTIME_API_EXTERN void *
  925. wasm_runtime_get_context(WASMModuleInstanceCommon *inst, void *key);
  926. bool
  927. wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
  928. const WASMFuncType *func_type, const char *signature,
  929. void *attachment, uint32 *argv, uint32 argc,
  930. uint32 *ret);
  931. bool
  932. wasm_runtime_invoke_native_raw(WASMExecEnv *exec_env, void *func_ptr,
  933. const WASMFuncType *func_type,
  934. const char *signature, void *attachment,
  935. uint32 *argv, uint32 argc, uint32 *ret);
  936. void
  937. wasm_runtime_read_v128(const uint8 *bytes, uint64 *ret1, uint64 *ret2);
  938. void
  939. wasm_runtime_dump_module_mem_consumption(const WASMModuleCommon *module);
  940. void
  941. wasm_runtime_dump_module_inst_mem_consumption(
  942. const WASMModuleInstanceCommon *module_inst);
  943. void
  944. wasm_runtime_dump_exec_env_mem_consumption(const WASMExecEnv *exec_env);
  945. bool
  946. wasm_runtime_get_table_elem_type(const WASMModuleCommon *module_comm,
  947. uint32 table_idx, uint8 *out_elem_type,
  948. #if WASM_ENABLE_GC != 0
  949. WASMRefType **out_ref_type,
  950. #endif
  951. uint32 *out_min_size, uint32 *out_max_size);
  952. bool
  953. wasm_runtime_get_table_inst_elem_type(
  954. const WASMModuleInstanceCommon *module_inst_comm, uint32 table_idx,
  955. uint8 *out_elem_type,
  956. #if WASM_ENABLE_GC != 0
  957. WASMRefType **out_ref_type,
  958. #endif
  959. uint32 *out_min_size, uint32 *out_max_size);
  960. bool
  961. wasm_runtime_get_export_func_type(const WASMModuleCommon *module_comm,
  962. const WASMExport *export_,
  963. WASMFuncType **out);
  964. bool
  965. wasm_runtime_get_export_global_type(const WASMModuleCommon *module_comm,
  966. const WASMExport *export_,
  967. uint8 *out_val_type, bool *out_mutability);
  968. bool
  969. wasm_runtime_get_export_memory_type(const WASMModuleCommon *module_comm,
  970. const WASMExport *export_,
  971. uint32 *out_min_page, uint32 *out_max_page);
  972. bool
  973. wasm_runtime_get_export_table_type(const WASMModuleCommon *module_comm,
  974. const WASMExport *export_,
  975. uint8 *out_elem_type,
  976. #if WASM_ENABLE_GC != 0
  977. WASMRefType **out_ref_type,
  978. #endif
  979. uint32 *out_min_size, uint32 *out_max_size);
  980. bool
  981. wasm_runtime_invoke_c_api_native(WASMModuleInstanceCommon *module_inst,
  982. void *func_ptr, WASMFuncType *func_type,
  983. uint32 argc, uint32 *argv, bool with_env,
  984. void *wasm_c_api_env);
  985. struct CApiFuncImport;
  986. /* A quick version of wasm_runtime_invoke_c_api_native to directly invoke
  987. wasm-c-api import function from jitted code to improve performance */
  988. bool
  989. wasm_runtime_quick_invoke_c_api_native(WASMModuleInstanceCommon *module_inst,
  990. struct CApiFuncImport *c_api_import,
  991. wasm_val_t *params, uint32 param_count,
  992. wasm_val_t *results,
  993. uint32 result_count);
  994. void
  995. wasm_runtime_show_app_heap_corrupted_prompt(void);
  996. #if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
  997. void
  998. wasm_runtime_destroy_custom_sections(WASMCustomSection *section_list);
  999. #endif
  1000. WASM_RUNTIME_API_EXTERN bool
  1001. wasm_runtime_is_import_func_linked(const char *module_name,
  1002. const char *func_name);
  1003. WASM_RUNTIME_API_EXTERN bool
  1004. wasm_runtime_is_import_global_linked(const char *module_name,
  1005. const char *global_name);
  1006. WASM_RUNTIME_API_EXTERN bool
  1007. wasm_runtime_begin_blocking_op(WASMExecEnv *exec_env);
  1008. WASM_RUNTIME_API_EXTERN void
  1009. wasm_runtime_end_blocking_op(WASMExecEnv *exec_env);
  1010. void
  1011. wasm_runtime_interrupt_blocking_op(WASMExecEnv *exec_env);
  1012. WASM_RUNTIME_API_EXTERN bool
  1013. wasm_runtime_detect_native_stack_overflow(WASMExecEnv *exec_env);
  1014. WASM_RUNTIME_API_EXTERN bool
  1015. wasm_runtime_detect_native_stack_overflow_size(WASMExecEnv *exec_env,
  1016. uint32 requested_size);
  1017. WASM_RUNTIME_API_EXTERN bool
  1018. wasm_runtime_is_underlying_binary_freeable(WASMModuleCommon *const module);
  1019. #if WASM_ENABLE_LINUX_PERF != 0
  1020. bool
  1021. wasm_runtime_get_linux_perf(void);
  1022. void
  1023. wasm_runtime_set_linux_perf(bool flag);
  1024. #endif
  1025. #ifdef __cplusplus
  1026. }
  1027. #endif
  1028. #endif /* end of _WASM_COMMON_H */