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