wasm_runtime_common.h 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  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. typedef struct WASMModuleCommon {
  335. /* Module type, for module loaded from WASM bytecode binary,
  336. this field is Wasm_Module_Bytecode, and this structure should
  337. be treated as WASMModule structure;
  338. for module loaded from AOT binary, this field is
  339. Wasm_Module_AoT, and this structure should be treated as
  340. AOTModule structure. */
  341. uint32 module_type;
  342. /* The following uint8[1] member is a dummy just to indicate
  343. some module_type dependent members follow.
  344. Typically, it should be accessed by casting to the corresponding
  345. actual module_type dependent structure, not via this member. */
  346. uint8 module_data[1];
  347. } WASMModuleCommon;
  348. typedef struct WASMModuleInstanceCommon {
  349. /* Module instance type, for module instance loaded from WASM
  350. bytecode binary, this field is Wasm_Module_Bytecode, and this
  351. structure should be treated as WASMModuleInstance structure;
  352. for module instance loaded from AOT binary, this field is
  353. Wasm_Module_AoT, and this structure should be treated as
  354. AOTModuleInstance structure. */
  355. uint32 module_type;
  356. /* The following uint8[1] member is a dummy just to indicate
  357. some module_type dependent members follow.
  358. Typically, it should be accessed by casting to the corresponding
  359. actual module_type dependent structure, not via this member. */
  360. uint8 module_inst_data[1];
  361. } WASMModuleInstanceCommon;
  362. typedef struct WASMModuleMemConsumption {
  363. uint32 total_size;
  364. uint32 module_struct_size;
  365. uint32 types_size;
  366. uint32 imports_size;
  367. uint32 functions_size;
  368. uint32 tables_size;
  369. uint32 memories_size;
  370. uint32 globals_size;
  371. uint32 exports_size;
  372. uint32 table_segs_size;
  373. uint32 data_segs_size;
  374. uint32 const_strs_size;
  375. #if WASM_ENABLE_AOT != 0
  376. uint32 aot_code_size;
  377. #endif
  378. } WASMModuleMemConsumption;
  379. typedef struct WASMModuleInstMemConsumption {
  380. uint64 total_size;
  381. uint32 module_inst_struct_size;
  382. uint32 app_heap_size;
  383. uint64 memories_size;
  384. uint32 tables_size;
  385. uint32 globals_size;
  386. uint32 functions_size;
  387. uint32 exports_size;
  388. } WASMModuleInstMemConsumption;
  389. #if WASM_ENABLE_LIBC_WASI != 0
  390. #if WASM_ENABLE_UVWASI == 0
  391. typedef struct WASIContext {
  392. struct fd_table *curfds;
  393. struct fd_prestats *prestats;
  394. struct argv_environ_values *argv_environ;
  395. struct addr_pool *addr_pool;
  396. char *ns_lookup_buf;
  397. char **ns_lookup_list;
  398. char *argv_buf;
  399. char **argv_list;
  400. char *env_buf;
  401. char **env_list;
  402. uint32_t exit_code;
  403. } WASIContext;
  404. #else
  405. typedef struct WASIContext {
  406. uvwasi_t uvwasi;
  407. uint32_t exit_code;
  408. } WASIContext;
  409. #endif
  410. #endif
  411. #if WASM_ENABLE_MULTI_MODULE != 0
  412. typedef struct WASMRegisteredModule {
  413. bh_list_link l;
  414. /* point to a string pool */
  415. const char *module_name;
  416. WASMModuleCommon *module;
  417. /* to store the original module file buffer address */
  418. uint8 *orig_file_buf;
  419. uint32 orig_file_buf_size;
  420. } WASMRegisteredModule;
  421. #endif
  422. typedef package_type_t PackageType;
  423. typedef wasm_section_t WASMSection, AOTSection;
  424. typedef struct wasm_frame_t {
  425. /* wasm_instance_t */
  426. void *instance;
  427. uint32 module_offset;
  428. uint32 func_index;
  429. uint32 func_offset;
  430. const char *func_name_wp;
  431. uint32 *sp;
  432. uint8 *frame_ref;
  433. uint32 *lp;
  434. } WASMCApiFrame;
  435. #if WASM_ENABLE_JIT != 0
  436. typedef struct LLVMJITOptions {
  437. uint32 opt_level;
  438. uint32 size_level;
  439. uint32 segue_flags;
  440. bool quick_invoke_c_api_import;
  441. } LLVMJITOptions;
  442. #endif
  443. #ifdef OS_ENABLE_HW_BOUND_CHECK
  444. /* Signal info passing to interp/aot signal handler */
  445. typedef struct WASMSignalInfo {
  446. WASMExecEnv *exec_env_tls;
  447. #ifndef BH_PLATFORM_WINDOWS
  448. void *sig_addr;
  449. #else
  450. EXCEPTION_POINTERS *exce_info;
  451. #endif
  452. } WASMSignalInfo;
  453. /* Set exec_env of thread local storage */
  454. void
  455. wasm_runtime_set_exec_env_tls(WASMExecEnv *exec_env);
  456. /* Get exec_env of thread local storage */
  457. WASMExecEnv *
  458. wasm_runtime_get_exec_env_tls(void);
  459. #endif
  460. /* See wasm_export.h for description */
  461. WASM_RUNTIME_API_EXTERN bool
  462. wasm_runtime_init(void);
  463. /* Internal API */
  464. RunningMode
  465. wasm_runtime_get_default_running_mode(void);
  466. #if WASM_ENABLE_JIT != 0
  467. /* Internal API */
  468. LLVMJITOptions *
  469. wasm_runtime_get_llvm_jit_options(void);
  470. #endif
  471. #if WASM_ENABLE_GC != 0
  472. /* Internal API */
  473. uint32
  474. wasm_runtime_get_gc_heap_size_default(void);
  475. #endif
  476. /* See wasm_export.h for description */
  477. WASM_RUNTIME_API_EXTERN bool
  478. wasm_runtime_full_init(RuntimeInitArgs *init_args);
  479. /* See wasm_export.h for description */
  480. WASM_RUNTIME_API_EXTERN bool
  481. wasm_runtime_is_running_mode_supported(RunningMode running_mode);
  482. /* See wasm_export.h for description */
  483. WASM_RUNTIME_API_EXTERN bool
  484. wasm_runtime_set_default_running_mode(RunningMode running_mode);
  485. /* See wasm_export.h for description */
  486. WASM_RUNTIME_API_EXTERN void
  487. wasm_runtime_destroy(void);
  488. /* See wasm_export.h for description */
  489. WASM_RUNTIME_API_EXTERN PackageType
  490. get_package_type(const uint8 *buf, uint32 size);
  491. /* See wasm_export.h for description */
  492. WASM_RUNTIME_API_EXTERN bool
  493. wasm_runtime_is_xip_file(const uint8 *buf, uint32 size);
  494. /* See wasm_export.h for description */
  495. WASM_RUNTIME_API_EXTERN WASMModuleCommon *
  496. wasm_runtime_load(uint8 *buf, uint32 size, char *error_buf,
  497. uint32 error_buf_size);
  498. /* See wasm_export.h for description */
  499. WASM_RUNTIME_API_EXTERN WASMModuleCommon *
  500. wasm_runtime_load_from_sections(WASMSection *section_list, bool is_aot,
  501. char *error_buf, uint32 error_buf_size);
  502. /* See wasm_export.h for description */
  503. WASM_RUNTIME_API_EXTERN void
  504. wasm_runtime_unload(WASMModuleCommon *module);
  505. /* Internal API */
  506. uint32
  507. wasm_runtime_get_max_mem(uint32 max_memory_pages, uint32 module_init_page_count,
  508. uint32 module_max_page_count);
  509. /* Internal API */
  510. WASMModuleInstanceCommon *
  511. wasm_runtime_instantiate_internal(WASMModuleCommon *module,
  512. WASMModuleInstanceCommon *parent,
  513. WASMExecEnv *exec_env_main, uint32 stack_size,
  514. uint32 heap_size, uint32 max_memory_pages,
  515. char *error_buf, uint32 error_buf_size);
  516. /* Internal API */
  517. void
  518. wasm_runtime_deinstantiate_internal(WASMModuleInstanceCommon *module_inst,
  519. bool is_sub_inst);
  520. /* See wasm_export.h for description */
  521. WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
  522. wasm_runtime_instantiate(WASMModuleCommon *module, uint32 default_stack_size,
  523. uint32 host_managed_heap_size, char *error_buf,
  524. uint32 error_buf_size);
  525. /* See wasm_export.h for description */
  526. WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
  527. wasm_runtime_instantiate_ex(WASMModuleCommon *module,
  528. const InstantiationArgs *args, char *error_buf,
  529. uint32 error_buf_size);
  530. /* See wasm_export.h for description */
  531. WASM_RUNTIME_API_EXTERN bool
  532. wasm_runtime_set_running_mode(wasm_module_inst_t module_inst,
  533. RunningMode running_mode);
  534. /* See wasm_export.h for description */
  535. WASM_RUNTIME_API_EXTERN RunningMode
  536. wasm_runtime_get_running_mode(wasm_module_inst_t module_inst);
  537. /* See wasm_export.h for description */
  538. WASM_RUNTIME_API_EXTERN void
  539. wasm_runtime_deinstantiate(WASMModuleInstanceCommon *module_inst);
  540. /* See wasm_export.h for description */
  541. WASM_RUNTIME_API_EXTERN WASMModuleCommon *
  542. wasm_runtime_get_module(WASMModuleInstanceCommon *module_inst);
  543. /* See wasm_export.h for description */
  544. WASM_RUNTIME_API_EXTERN WASMFunctionInstanceCommon *
  545. wasm_runtime_lookup_function(WASMModuleInstanceCommon *const module_inst,
  546. const char *name);
  547. /* Internal API */
  548. WASMFuncType *
  549. wasm_runtime_get_function_type(const WASMFunctionInstanceCommon *function,
  550. uint32 module_type);
  551. /* See wasm_export.h for description */
  552. WASM_RUNTIME_API_EXTERN uint32
  553. wasm_func_get_param_count(WASMFunctionInstanceCommon *const func_inst,
  554. WASMModuleInstanceCommon *const module_inst);
  555. /* See wasm_export.h for description */
  556. WASM_RUNTIME_API_EXTERN uint32
  557. wasm_func_get_result_count(WASMFunctionInstanceCommon *const func_inst,
  558. WASMModuleInstanceCommon *const module_inst);
  559. /* See wasm_export.h for description */
  560. WASM_RUNTIME_API_EXTERN void
  561. wasm_func_get_param_types(WASMFunctionInstanceCommon *const func_inst,
  562. WASMModuleInstanceCommon *const module_inst,
  563. wasm_valkind_t *param_types);
  564. /* See wasm_export.h for description */
  565. WASM_RUNTIME_API_EXTERN void
  566. wasm_func_get_result_types(WASMFunctionInstanceCommon *const func_inst,
  567. WASMModuleInstanceCommon *const module_inst,
  568. wasm_valkind_t *result_types);
  569. /* See wasm_export.h for description */
  570. WASM_RUNTIME_API_EXTERN WASMExecEnv *
  571. wasm_runtime_create_exec_env(WASMModuleInstanceCommon *module_inst,
  572. uint32 stack_size);
  573. /* See wasm_export.h for description */
  574. WASM_RUNTIME_API_EXTERN void
  575. wasm_runtime_destroy_exec_env(WASMExecEnv *exec_env);
  576. /* See wasm_export.h for description */
  577. WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
  578. wasm_runtime_get_module_inst(WASMExecEnv *exec_env);
  579. /* See wasm_export.h for description */
  580. WASM_RUNTIME_API_EXTERN void
  581. wasm_runtime_set_module_inst(WASMExecEnv *exec_env,
  582. WASMModuleInstanceCommon *const module_inst);
  583. /* See wasm_export.h for description */
  584. WASM_RUNTIME_API_EXTERN void *
  585. wasm_runtime_get_function_attachment(WASMExecEnv *exec_env);
  586. /* See wasm_export.h for description */
  587. WASM_RUNTIME_API_EXTERN void
  588. wasm_runtime_set_user_data(WASMExecEnv *exec_env, void *user_data);
  589. /* See wasm_export.h for description */
  590. WASM_RUNTIME_API_EXTERN void *
  591. wasm_runtime_get_user_data(WASMExecEnv *exec_env);
  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();
  737. module_destroyer
  738. wasm_runtime_get_module_destroyer();
  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();
  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();
  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. #if WASM_ENABLE_LINUX_PERF != 0
  1018. bool
  1019. wasm_runtime_get_linux_perf(void);
  1020. void
  1021. wasm_runtime_set_linux_perf(bool flag);
  1022. #endif
  1023. #ifdef __cplusplus
  1024. }
  1025. #endif
  1026. #endif /* end of _WASM_COMMON_H */