wasm_runtime_common.h 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _WASM_COMMON_H
  6. #define _WASM_COMMON_H
  7. #include "bh_platform.h"
  8. #include "bh_common.h"
  9. #include "wasm_exec_env.h"
  10. #include "wasm_native.h"
  11. #include "../include/wasm_export.h"
  12. #include "../interpreter/wasm.h"
  13. #if WASM_ENABLE_GC != 0
  14. #include "gc/gc_object.h"
  15. #endif
  16. #if WASM_ENABLE_LIBC_WASI != 0
  17. #if WASM_ENABLE_UVWASI == 0
  18. #include "posix.h"
  19. #else
  20. #include "uvwasi.h"
  21. #endif
  22. #endif
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* Internal use for setting default running mode */
  27. #define Mode_Default 0
  28. #if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
  29. #define PUT_I64_TO_ADDR(addr, value) \
  30. do { \
  31. *(int64 *)(addr) = (int64)(value); \
  32. } while (0)
  33. #define PUT_F64_TO_ADDR(addr, value) \
  34. do { \
  35. *(float64 *)(addr) = (float64)(value); \
  36. } while (0)
  37. #define PUT_REF_TO_ADDR(addr, value) \
  38. do { \
  39. *(void **)(addr) = (void *)(value); \
  40. } while (0)
  41. #define GET_I64_FROM_ADDR(addr) (*(int64 *)(addr))
  42. #define GET_F64_FROM_ADDR(addr) (*(float64 *)(addr))
  43. #define GET_REF_FROM_ADDR(addr) (*(void **)(addr))
  44. /* For STORE opcodes */
  45. #define STORE_I64 PUT_I64_TO_ADDR
  46. static inline void
  47. STORE_U32(void *addr, uint32_t value)
  48. {
  49. *(uint32_t *)(addr) = (uint32_t)(value);
  50. }
  51. static inline void
  52. STORE_U16(void *addr, uint16_t value)
  53. {
  54. *(uint16_t *)(addr) = (uint16_t)(value);
  55. }
  56. static inline void
  57. STORE_U8(void *addr, uint8_t value)
  58. {
  59. *(uint8 *)addr = value;
  60. }
  61. /* For LOAD opcodes */
  62. #define LOAD_I64(addr) (*(int64 *)(addr))
  63. #define LOAD_F64(addr) (*(float64 *)(addr))
  64. #define LOAD_I32(addr) (*(int32 *)(addr))
  65. #define LOAD_U32(addr) (*(uint32 *)(addr))
  66. #define LOAD_I16(addr) (*(int16 *)(addr))
  67. #define LOAD_U16(addr) (*(uint16 *)(addr))
  68. #define STORE_PTR(addr, ptr) \
  69. do { \
  70. *(void **)addr = (void *)ptr; \
  71. } while (0)
  72. #else /* WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 */
  73. #define PUT_I64_TO_ADDR(addr, value) \
  74. do { \
  75. uint32 *addr_u32 = (uint32 *)(addr); \
  76. union { \
  77. int64 val; \
  78. uint32 parts[2]; \
  79. } u; \
  80. u.val = (int64)(value); \
  81. addr_u32[0] = u.parts[0]; \
  82. addr_u32[1] = u.parts[1]; \
  83. } while (0)
  84. #define PUT_F64_TO_ADDR(addr, value) \
  85. do { \
  86. uint32 *addr_u32 = (uint32 *)(addr); \
  87. union { \
  88. float64 val; \
  89. uint32 parts[2]; \
  90. } u; \
  91. u.val = (value); \
  92. addr_u32[0] = u.parts[0]; \
  93. addr_u32[1] = u.parts[1]; \
  94. } while (0)
  95. #if UINTPTR_MAX == UINT64_MAX
  96. #define PUT_REF_TO_ADDR(addr, value) \
  97. do { \
  98. uint32 *addr_u32 = (uint32 *)(addr); \
  99. union { \
  100. void *val; \
  101. uint32 parts[2]; \
  102. } u; \
  103. u.val = (void *)(value); \
  104. addr_u32[0] = u.parts[0]; \
  105. addr_u32[1] = u.parts[1]; \
  106. } while (0)
  107. #else
  108. #define PUT_REF_TO_ADDR(addr, value) \
  109. do { \
  110. *(void **)(addr) = (void *)(value); \
  111. } while (0)
  112. #endif
  113. static inline int64
  114. GET_I64_FROM_ADDR(uint32 *addr)
  115. {
  116. union {
  117. int64 val;
  118. uint32 parts[2];
  119. } u;
  120. u.parts[0] = addr[0];
  121. u.parts[1] = addr[1];
  122. return u.val;
  123. }
  124. static inline float64
  125. GET_F64_FROM_ADDR(uint32 *addr)
  126. {
  127. union {
  128. float64 val;
  129. uint32 parts[2];
  130. } u;
  131. u.parts[0] = addr[0];
  132. u.parts[1] = addr[1];
  133. return u.val;
  134. }
  135. #if UINTPTR_MAX == UINT64_MAX
  136. static inline void *
  137. GET_REF_FROM_ADDR(uint32 *addr)
  138. {
  139. union {
  140. void *val;
  141. uint32 parts[2];
  142. } u;
  143. u.parts[0] = addr[0];
  144. u.parts[1] = addr[1];
  145. return u.val;
  146. }
  147. #else
  148. #define GET_REF_FROM_ADDR(addr) (*(void **)(addr))
  149. #endif
  150. /* For STORE opcodes */
  151. #define STORE_I64(addr, value) \
  152. do { \
  153. uintptr_t addr_ = (uintptr_t)(addr); \
  154. union { \
  155. int64 val; \
  156. uint32 u32[2]; \
  157. uint16 u16[4]; \
  158. uint8 u8[8]; \
  159. } u; \
  160. if ((addr_ & (uintptr_t)7) == 0) \
  161. *(int64 *)(addr) = (int64)(value); \
  162. else { \
  163. u.val = (int64)(value); \
  164. if ((addr_ & (uintptr_t)3) == 0) { \
  165. ((uint32 *)(addr))[0] = u.u32[0]; \
  166. ((uint32 *)(addr))[1] = u.u32[1]; \
  167. } \
  168. else if ((addr_ & (uintptr_t)1) == 0) { \
  169. ((uint16 *)(addr))[0] = u.u16[0]; \
  170. ((uint16 *)(addr))[1] = u.u16[1]; \
  171. ((uint16 *)(addr))[2] = u.u16[2]; \
  172. ((uint16 *)(addr))[3] = u.u16[3]; \
  173. } \
  174. else { \
  175. int32 t; \
  176. for (t = 0; t < 8; t++) \
  177. ((uint8 *)(addr))[t] = u.u8[t]; \
  178. } \
  179. } \
  180. } while (0)
  181. static inline void
  182. STORE_U32(void *addr, uint32_t value)
  183. {
  184. uintptr_t addr_ = (uintptr_t)(addr);
  185. union {
  186. uint32_t val;
  187. uint16_t u16[2];
  188. uint8_t u8[4];
  189. } u;
  190. if ((addr_ & (uintptr_t)3) == 0)
  191. *(uint32_t *)(addr) = (uint32_t)(value);
  192. else {
  193. u.val = (uint32_t)(value);
  194. if ((addr_ & (uintptr_t)1) == 0) {
  195. ((uint16_t *)(addr))[0] = u.u16[0];
  196. ((uint16_t *)(addr))[1] = u.u16[1];
  197. }
  198. else {
  199. ((uint8_t *)(addr))[0] = u.u8[0];
  200. ((uint8_t *)(addr))[1] = u.u8[1];
  201. ((uint8_t *)(addr))[2] = u.u8[2];
  202. ((uint8_t *)(addr))[3] = u.u8[3];
  203. }
  204. }
  205. }
  206. static inline void
  207. STORE_U8(void *addr, uint8_t value)
  208. {
  209. *(uint8 *)addr = value;
  210. }
  211. static inline void
  212. STORE_U16(void *addr, uint16_t value)
  213. {
  214. union {
  215. uint16_t val;
  216. uint8_t u8[2];
  217. } u;
  218. u.val = (uint16_t)(value);
  219. ((uint8_t *)(addr))[0] = u.u8[0];
  220. ((uint8_t *)(addr))[1] = u.u8[1];
  221. }
  222. /* For LOAD opcodes */
  223. static inline int64
  224. LOAD_I64(void *addr)
  225. {
  226. uintptr_t addr1 = (uintptr_t)addr;
  227. union {
  228. int64 val;
  229. uint32 u32[2];
  230. uint16 u16[4];
  231. uint8 u8[8];
  232. } u;
  233. if ((addr1 & (uintptr_t)7) == 0)
  234. return *(int64 *)addr;
  235. if ((addr1 & (uintptr_t)3) == 0) {
  236. u.u32[0] = ((uint32 *)addr)[0];
  237. u.u32[1] = ((uint32 *)addr)[1];
  238. }
  239. else if ((addr1 & (uintptr_t)1) == 0) {
  240. u.u16[0] = ((uint16 *)addr)[0];
  241. u.u16[1] = ((uint16 *)addr)[1];
  242. u.u16[2] = ((uint16 *)addr)[2];
  243. u.u16[3] = ((uint16 *)addr)[3];
  244. }
  245. else {
  246. int32 t;
  247. for (t = 0; t < 8; t++)
  248. u.u8[t] = ((uint8 *)addr)[t];
  249. }
  250. return u.val;
  251. }
  252. static inline float64
  253. LOAD_F64(void *addr)
  254. {
  255. uintptr_t addr1 = (uintptr_t)addr;
  256. union {
  257. float64 val;
  258. uint32 u32[2];
  259. uint16 u16[4];
  260. uint8 u8[8];
  261. } u;
  262. if ((addr1 & (uintptr_t)7) == 0)
  263. return *(float64 *)addr;
  264. if ((addr1 & (uintptr_t)3) == 0) {
  265. u.u32[0] = ((uint32 *)addr)[0];
  266. u.u32[1] = ((uint32 *)addr)[1];
  267. }
  268. else if ((addr1 & (uintptr_t)1) == 0) {
  269. u.u16[0] = ((uint16 *)addr)[0];
  270. u.u16[1] = ((uint16 *)addr)[1];
  271. u.u16[2] = ((uint16 *)addr)[2];
  272. u.u16[3] = ((uint16 *)addr)[3];
  273. }
  274. else {
  275. int32 t;
  276. for (t = 0; t < 8; t++)
  277. u.u8[t] = ((uint8 *)addr)[t];
  278. }
  279. return u.val;
  280. }
  281. static inline int32
  282. LOAD_I32(void *addr)
  283. {
  284. uintptr_t addr1 = (uintptr_t)addr;
  285. union {
  286. int32 val;
  287. uint16 u16[2];
  288. uint8 u8[4];
  289. } u;
  290. if ((addr1 & (uintptr_t)3) == 0)
  291. return *(int32 *)addr;
  292. if ((addr1 & (uintptr_t)1) == 0) {
  293. u.u16[0] = ((uint16 *)addr)[0];
  294. u.u16[1] = ((uint16 *)addr)[1];
  295. }
  296. else {
  297. u.u8[0] = ((uint8 *)addr)[0];
  298. u.u8[1] = ((uint8 *)addr)[1];
  299. u.u8[2] = ((uint8 *)addr)[2];
  300. u.u8[3] = ((uint8 *)addr)[3];
  301. }
  302. return u.val;
  303. }
  304. static inline int16
  305. LOAD_I16(void *addr)
  306. {
  307. uintptr_t addr1 = (uintptr_t)addr;
  308. union {
  309. int16 val;
  310. uint8 u8[2];
  311. } u;
  312. if ((addr1 & (uintptr_t)1)) {
  313. u.u8[0] = ((uint8 *)addr)[0];
  314. u.u8[1] = ((uint8 *)addr)[1];
  315. return u.val;
  316. }
  317. return *(int16 *)addr;
  318. }
  319. #define LOAD_U32(addr) ((uint32)LOAD_I32(addr))
  320. #define LOAD_U16(addr) ((uint16)LOAD_I16(addr))
  321. #if UINTPTR_MAX == UINT32_MAX
  322. #define STORE_PTR(addr, ptr) STORE_U32(addr, (uintptr_t)ptr)
  323. #elif UINTPTR_MAX == UINT64_MAX
  324. #define STORE_PTR(addr, ptr) STORE_I64(addr, (uintptr_t)ptr)
  325. #endif
  326. #endif /* WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0 */
  327. #if WASM_ENABLE_SHARED_MEMORY != 0
  328. #define SHARED_MEMORY_LOCK(memory) shared_memory_lock(memory)
  329. #define SHARED_MEMORY_UNLOCK(memory) shared_memory_unlock(memory)
  330. #else
  331. #define SHARED_MEMORY_LOCK(memory) (void)0
  332. #define SHARED_MEMORY_UNLOCK(memory) (void)0
  333. #endif
  334. #define CLAMP_U64_TO_U32(value) \
  335. ((value) > UINT32_MAX ? UINT32_MAX : (uint32)(value))
  336. typedef struct WASMModuleCommon {
  337. /* Module type, for module loaded from WASM bytecode binary,
  338. this field is Wasm_Module_Bytecode, and this structure should
  339. be treated as WASMModule structure;
  340. for module loaded from AOT binary, this field is
  341. Wasm_Module_AoT, and this structure should be treated as
  342. AOTModule structure. */
  343. uint32 module_type;
  344. /* The following uint8[1] member is a dummy just to indicate
  345. some module_type dependent members follow.
  346. Typically, it should be accessed by casting to the corresponding
  347. actual module_type dependent structure, not via this member. */
  348. uint8 module_data[1];
  349. } WASMModuleCommon;
  350. typedef struct WASMModuleInstanceCommon {
  351. /* Module instance type, for module instance loaded from WASM
  352. bytecode binary, this field is Wasm_Module_Bytecode, and this
  353. structure should be treated as WASMModuleInstance structure;
  354. for module instance loaded from AOT binary, this field is
  355. Wasm_Module_AoT, and this structure should be treated as
  356. AOTModuleInstance structure. */
  357. uint32 module_type;
  358. /* The following uint8[1] member is a dummy just to indicate
  359. some module_type dependent members follow.
  360. Typically, it should be accessed by casting to the corresponding
  361. actual module_type dependent structure, not via this member. */
  362. uint8 module_inst_data[1];
  363. } WASMModuleInstanceCommon;
  364. typedef struct WASMModuleMemConsumption {
  365. uint32 total_size;
  366. uint32 module_struct_size;
  367. uint32 types_size;
  368. uint32 imports_size;
  369. uint32 functions_size;
  370. uint32 tables_size;
  371. uint32 memories_size;
  372. uint32 globals_size;
  373. uint32 exports_size;
  374. uint32 table_segs_size;
  375. uint32 data_segs_size;
  376. uint32 const_strs_size;
  377. #if WASM_ENABLE_AOT != 0
  378. uint32 aot_code_size;
  379. #endif
  380. } WASMModuleMemConsumption;
  381. typedef struct WASMModuleInstMemConsumption {
  382. uint64 total_size;
  383. uint32 module_inst_struct_size;
  384. uint32 app_heap_size;
  385. uint64 memories_size;
  386. uint32 tables_size;
  387. uint32 globals_size;
  388. uint32 functions_size;
  389. uint32 exports_size;
  390. } WASMModuleInstMemConsumption;
  391. #if WASM_ENABLE_LIBC_WASI != 0
  392. #if WASM_ENABLE_UVWASI == 0
  393. typedef struct WASIContext {
  394. struct fd_table *curfds;
  395. struct fd_prestats *prestats;
  396. struct argv_environ_values *argv_environ;
  397. struct addr_pool *addr_pool;
  398. char *ns_lookup_buf;
  399. char **ns_lookup_list;
  400. char *argv_buf;
  401. char **argv_list;
  402. char *env_buf;
  403. char **env_list;
  404. uint32_t exit_code;
  405. } WASIContext;
  406. #else
  407. typedef struct WASIContext {
  408. uvwasi_t uvwasi;
  409. uint32_t exit_code;
  410. } WASIContext;
  411. #endif
  412. #endif
  413. #if WASM_ENABLE_MULTI_MODULE != 0
  414. typedef struct WASMRegisteredModule {
  415. bh_list_link l;
  416. /* point to a string pool */
  417. const char *module_name;
  418. WASMModuleCommon *module;
  419. /* to store the original module file buffer address */
  420. uint8 *orig_file_buf;
  421. uint32 orig_file_buf_size;
  422. } WASMRegisteredModule;
  423. #endif
  424. typedef package_type_t PackageType;
  425. typedef wasm_section_t WASMSection, AOTSection;
  426. typedef struct wasm_frame_t {
  427. /* wasm_instance_t */
  428. void *instance;
  429. uint32 module_offset;
  430. uint32 func_index;
  431. uint32 func_offset;
  432. const char *func_name_wp;
  433. uint32 *sp;
  434. uint8 *frame_ref;
  435. uint32 *lp;
  436. } WASMCApiFrame;
  437. #if WASM_ENABLE_JIT != 0
  438. typedef struct LLVMJITOptions {
  439. uint32 opt_level;
  440. uint32 size_level;
  441. uint32 segue_flags;
  442. bool quick_invoke_c_api_import;
  443. } LLVMJITOptions;
  444. #endif
  445. #ifdef OS_ENABLE_HW_BOUND_CHECK
  446. /* Signal info passing to interp/aot signal handler */
  447. typedef struct WASMSignalInfo {
  448. WASMExecEnv *exec_env_tls;
  449. #ifndef BH_PLATFORM_WINDOWS
  450. void *sig_addr;
  451. #else
  452. EXCEPTION_POINTERS *exce_info;
  453. #endif
  454. } WASMSignalInfo;
  455. /* Set exec_env of thread local storage */
  456. void
  457. wasm_runtime_set_exec_env_tls(WASMExecEnv *exec_env);
  458. /* Get exec_env of thread local storage */
  459. WASMExecEnv *
  460. wasm_runtime_get_exec_env_tls(void);
  461. #endif
  462. /* See wasm_export.h for description */
  463. WASM_RUNTIME_API_EXTERN bool
  464. wasm_runtime_init(void);
  465. /* Internal API */
  466. RunningMode
  467. wasm_runtime_get_default_running_mode(void);
  468. #if WASM_ENABLE_JIT != 0
  469. /* Internal API */
  470. LLVMJITOptions *
  471. wasm_runtime_get_llvm_jit_options(void);
  472. #endif
  473. #if WASM_ENABLE_GC != 0
  474. /* Internal API */
  475. uint32
  476. wasm_runtime_get_gc_heap_size_default(void);
  477. #endif
  478. /* See wasm_export.h for description */
  479. WASM_RUNTIME_API_EXTERN bool
  480. wasm_runtime_full_init(RuntimeInitArgs *init_args);
  481. /* See wasm_export.h for description */
  482. WASM_RUNTIME_API_EXTERN bool
  483. wasm_runtime_is_running_mode_supported(RunningMode running_mode);
  484. /* See wasm_export.h for description */
  485. WASM_RUNTIME_API_EXTERN bool
  486. wasm_runtime_set_default_running_mode(RunningMode running_mode);
  487. /* See wasm_export.h for description */
  488. WASM_RUNTIME_API_EXTERN void
  489. wasm_runtime_destroy(void);
  490. /* See wasm_export.h for description */
  491. WASM_RUNTIME_API_EXTERN PackageType
  492. get_package_type(const uint8 *buf, uint32 size);
  493. /* See wasm_export.h for description */
  494. WASM_RUNTIME_API_EXTERN bool
  495. wasm_runtime_is_xip_file(const uint8 *buf, uint32 size);
  496. /* See wasm_export.h for description */
  497. WASM_RUNTIME_API_EXTERN WASMModuleCommon *
  498. wasm_runtime_load(uint8 *buf, uint32 size, char *error_buf,
  499. uint32 error_buf_size);
  500. /* See wasm_export.h for description */
  501. WASM_RUNTIME_API_EXTERN WASMModuleCommon *
  502. wasm_runtime_load_from_sections(WASMSection *section_list, bool is_aot,
  503. char *error_buf, uint32 error_buf_size);
  504. /* See wasm_export.h for description */
  505. WASM_RUNTIME_API_EXTERN void
  506. wasm_runtime_unload(WASMModuleCommon *module);
  507. /* Internal API */
  508. uint32
  509. wasm_runtime_get_max_mem(uint32 max_memory_pages, uint32 module_init_page_count,
  510. uint32 module_max_page_count);
  511. /* Internal API */
  512. WASMModuleInstanceCommon *
  513. wasm_runtime_instantiate_internal(WASMModuleCommon *module,
  514. WASMModuleInstanceCommon *parent,
  515. WASMExecEnv *exec_env_main, uint32 stack_size,
  516. uint32 heap_size, uint32 max_memory_pages,
  517. char *error_buf, uint32 error_buf_size);
  518. /* Internal API */
  519. void
  520. wasm_runtime_deinstantiate_internal(WASMModuleInstanceCommon *module_inst,
  521. bool is_sub_inst);
  522. /* See wasm_export.h for description */
  523. WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
  524. wasm_runtime_instantiate(WASMModuleCommon *module, uint32 default_stack_size,
  525. uint32 host_managed_heap_size, char *error_buf,
  526. uint32 error_buf_size);
  527. /* See wasm_export.h for description */
  528. WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
  529. wasm_runtime_instantiate_ex(WASMModuleCommon *module,
  530. const InstantiationArgs *args, char *error_buf,
  531. uint32 error_buf_size);
  532. /* See wasm_export.h for description */
  533. WASM_RUNTIME_API_EXTERN bool
  534. wasm_runtime_set_running_mode(wasm_module_inst_t module_inst,
  535. RunningMode running_mode);
  536. /* See wasm_export.h for description */
  537. WASM_RUNTIME_API_EXTERN RunningMode
  538. wasm_runtime_get_running_mode(wasm_module_inst_t module_inst);
  539. /* See wasm_export.h for description */
  540. WASM_RUNTIME_API_EXTERN void
  541. wasm_runtime_deinstantiate(WASMModuleInstanceCommon *module_inst);
  542. /* See wasm_export.h for description */
  543. WASM_RUNTIME_API_EXTERN WASMModuleCommon *
  544. wasm_runtime_get_module(WASMModuleInstanceCommon *module_inst);
  545. /* See wasm_export.h for description */
  546. WASM_RUNTIME_API_EXTERN WASMFunctionInstanceCommon *
  547. wasm_runtime_lookup_function(WASMModuleInstanceCommon *const module_inst,
  548. const char *name);
  549. /* Internal API */
  550. WASMFuncType *
  551. wasm_runtime_get_function_type(const WASMFunctionInstanceCommon *function,
  552. uint32 module_type);
  553. /* See wasm_export.h for description */
  554. WASM_RUNTIME_API_EXTERN uint32
  555. wasm_func_get_param_count(WASMFunctionInstanceCommon *const func_inst,
  556. WASMModuleInstanceCommon *const module_inst);
  557. /* See wasm_export.h for description */
  558. WASM_RUNTIME_API_EXTERN uint32
  559. wasm_func_get_result_count(WASMFunctionInstanceCommon *const func_inst,
  560. WASMModuleInstanceCommon *const module_inst);
  561. /* See wasm_export.h for description */
  562. WASM_RUNTIME_API_EXTERN void
  563. wasm_func_get_param_types(WASMFunctionInstanceCommon *const func_inst,
  564. WASMModuleInstanceCommon *const module_inst,
  565. wasm_valkind_t *param_types);
  566. /* See wasm_export.h for description */
  567. WASM_RUNTIME_API_EXTERN void
  568. wasm_func_get_result_types(WASMFunctionInstanceCommon *const func_inst,
  569. WASMModuleInstanceCommon *const module_inst,
  570. wasm_valkind_t *result_types);
  571. /* See wasm_export.h for description */
  572. WASM_RUNTIME_API_EXTERN WASMExecEnv *
  573. wasm_runtime_create_exec_env(WASMModuleInstanceCommon *module_inst,
  574. uint32 stack_size);
  575. /* See wasm_export.h for description */
  576. WASM_RUNTIME_API_EXTERN void
  577. wasm_runtime_destroy_exec_env(WASMExecEnv *exec_env);
  578. /* See wasm_export.h for description */
  579. WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
  580. wasm_runtime_get_module_inst(WASMExecEnv *exec_env);
  581. /* See wasm_export.h for description */
  582. WASM_RUNTIME_API_EXTERN void
  583. wasm_runtime_set_module_inst(WASMExecEnv *exec_env,
  584. WASMModuleInstanceCommon *const module_inst);
  585. /* See wasm_export.h for description */
  586. WASM_RUNTIME_API_EXTERN void *
  587. wasm_runtime_get_function_attachment(WASMExecEnv *exec_env);
  588. /* See wasm_export.h for description */
  589. WASM_RUNTIME_API_EXTERN void
  590. wasm_runtime_set_user_data(WASMExecEnv *exec_env, void *user_data);
  591. /* See wasm_export.h for description */
  592. WASM_RUNTIME_API_EXTERN void *
  593. wasm_runtime_get_user_data(WASMExecEnv *exec_env);
  594. #if WASM_CONFIGURABLE_BOUNDS_CHECKS != 0
  595. /* See wasm_export.h for description */
  596. WASM_RUNTIME_API_EXTERN void
  597. wasm_runtime_set_bounds_checks(WASMModuleInstanceCommon *module_inst,
  598. bool enable);
  599. /* See wasm_export.h for description */
  600. WASM_RUNTIME_API_EXTERN bool
  601. wasm_runtime_is_bounds_checks_enabled(WASMModuleInstanceCommon *module_inst);
  602. #endif
  603. #ifdef OS_ENABLE_HW_BOUND_CHECK
  604. /* Access exception check guard page to trigger the signal handler */
  605. void
  606. wasm_runtime_access_exce_check_guard_page();
  607. #endif
  608. /* See wasm_export.h for description */
  609. WASM_RUNTIME_API_EXTERN bool
  610. wasm_runtime_call_wasm(WASMExecEnv *exec_env,
  611. WASMFunctionInstanceCommon *function, uint32 argc,
  612. uint32 argv[]);
  613. WASM_RUNTIME_API_EXTERN bool
  614. wasm_runtime_call_wasm_a(WASMExecEnv *exec_env,
  615. WASMFunctionInstanceCommon *function,
  616. uint32 num_results, wasm_val_t *results,
  617. uint32 num_args, wasm_val_t *args);
  618. WASM_RUNTIME_API_EXTERN bool
  619. wasm_runtime_call_wasm_v(WASMExecEnv *exec_env,
  620. WASMFunctionInstanceCommon *function,
  621. uint32 num_results, wasm_val_t *results,
  622. uint32 num_args, ...);
  623. /* See wasm_export.h for description */
  624. WASM_RUNTIME_API_EXTERN bool
  625. wasm_runtime_call_indirect(WASMExecEnv *exec_env, uint32 element_index,
  626. uint32 argc, uint32 argv[]);
  627. #if WASM_ENABLE_DEBUG_INTERP != 0
  628. /* See wasm_export.h for description */
  629. WASM_RUNTIME_API_EXTERN uint32
  630. wasm_runtime_start_debug_instance_with_port(WASMExecEnv *exec_env,
  631. int32_t port);
  632. /* See wasm_export.h for description */
  633. WASM_RUNTIME_API_EXTERN uint32
  634. wasm_runtime_start_debug_instance(WASMExecEnv *exec_env);
  635. #endif
  636. bool
  637. wasm_runtime_create_exec_env_singleton(WASMModuleInstanceCommon *module_inst);
  638. /* See wasm_export.h for description */
  639. WASM_RUNTIME_API_EXTERN WASMExecEnv *
  640. wasm_runtime_get_exec_env_singleton(WASMModuleInstanceCommon *module_inst);
  641. /* See wasm_export.h for description */
  642. WASM_RUNTIME_API_EXTERN bool
  643. wasm_application_execute_main(WASMModuleInstanceCommon *module_inst, int32 argc,
  644. char *argv[]);
  645. /* See wasm_export.h for description */
  646. WASM_RUNTIME_API_EXTERN bool
  647. wasm_application_execute_func(WASMModuleInstanceCommon *module_inst,
  648. const char *name, int32 argc, char *argv[]);
  649. /* See wasm_export.h for description */
  650. WASM_RUNTIME_API_EXTERN void
  651. wasm_runtime_set_exception(WASMModuleInstanceCommon *module,
  652. const char *exception);
  653. /* See wasm_export.h for description */
  654. WASM_RUNTIME_API_EXTERN const char *
  655. wasm_runtime_get_exception(WASMModuleInstanceCommon *module);
  656. /* See wasm_export.h for description */
  657. WASM_RUNTIME_API_EXTERN void
  658. wasm_runtime_clear_exception(WASMModuleInstanceCommon *module_inst);
  659. /* See wasm_export.h for description */
  660. WASM_RUNTIME_API_EXTERN void
  661. wasm_runtime_terminate(WASMModuleInstanceCommon *module);
  662. /* Internal API */
  663. void
  664. wasm_runtime_set_custom_data_internal(WASMModuleInstanceCommon *module_inst,
  665. void *custom_data);
  666. /* See wasm_export.h for description */
  667. WASM_RUNTIME_API_EXTERN void
  668. wasm_runtime_set_custom_data(WASMModuleInstanceCommon *module_inst,
  669. void *custom_data);
  670. /* See wasm_export.h for description */
  671. WASM_RUNTIME_API_EXTERN void *
  672. wasm_runtime_get_custom_data(WASMModuleInstanceCommon *module_inst);
  673. /* Internal API */
  674. uint64
  675. wasm_runtime_module_malloc_internal(WASMModuleInstanceCommon *module_inst,
  676. WASMExecEnv *exec_env, uint64 size,
  677. void **p_native_addr);
  678. /* Internal API */
  679. uint64
  680. wasm_runtime_module_realloc_internal(WASMModuleInstanceCommon *module_inst,
  681. WASMExecEnv *exec_env, uint64 ptr,
  682. uint64 size, void **p_native_addr);
  683. /* Internal API */
  684. void
  685. wasm_runtime_module_free_internal(WASMModuleInstanceCommon *module_inst,
  686. WASMExecEnv *exec_env, uint64 ptr);
  687. /* See wasm_export.h for description */
  688. WASM_RUNTIME_API_EXTERN uint64
  689. wasm_runtime_module_malloc(WASMModuleInstanceCommon *module_inst, uint64 size,
  690. void **p_native_addr);
  691. /* See wasm_export.h for description */
  692. WASM_RUNTIME_API_EXTERN void
  693. wasm_runtime_module_free(WASMModuleInstanceCommon *module_inst, uint64 ptr);
  694. /* See wasm_export.h for description */
  695. WASM_RUNTIME_API_EXTERN uint64
  696. wasm_runtime_module_dup_data(WASMModuleInstanceCommon *module_inst,
  697. const char *src, uint64 size);
  698. /* See wasm_export.h for description */
  699. WASM_RUNTIME_API_EXTERN bool
  700. wasm_runtime_validate_app_addr(WASMModuleInstanceCommon *module_inst,
  701. uint64 app_offset, uint64 size);
  702. /* See wasm_export.h for description */
  703. WASM_RUNTIME_API_EXTERN bool
  704. wasm_runtime_validate_app_str_addr(WASMModuleInstanceCommon *module_inst,
  705. uint64 app_str_offset);
  706. /* See wasm_export.h for description */
  707. WASM_RUNTIME_API_EXTERN bool
  708. wasm_runtime_validate_native_addr(WASMModuleInstanceCommon *module_inst,
  709. void *native_ptr, uint64 size);
  710. /* See wasm_export.h for description */
  711. WASM_RUNTIME_API_EXTERN void *
  712. wasm_runtime_addr_app_to_native(WASMModuleInstanceCommon *module_inst,
  713. uint64 app_offset);
  714. /* See wasm_export.h for description */
  715. WASM_RUNTIME_API_EXTERN uint64
  716. wasm_runtime_addr_native_to_app(WASMModuleInstanceCommon *module_inst,
  717. void *native_ptr);
  718. /* See wasm_export.h for description */
  719. WASM_RUNTIME_API_EXTERN bool
  720. wasm_runtime_get_app_addr_range(WASMModuleInstanceCommon *module_inst,
  721. uint64 app_offset, uint64 *p_app_start_offset,
  722. uint64 *p_app_end_offset);
  723. /* See wasm_export.h for description */
  724. WASM_RUNTIME_API_EXTERN bool
  725. wasm_runtime_get_native_addr_range(WASMModuleInstanceCommon *module_inst,
  726. uint8 *native_ptr,
  727. uint8 **p_native_start_addr,
  728. uint8 **p_native_end_addr);
  729. /* See wasm_export.h for description */
  730. WASM_RUNTIME_API_EXTERN const uint8 *
  731. wasm_runtime_get_custom_section(WASMModuleCommon *const module_comm,
  732. const char *name, uint32 *len);
  733. #if WASM_ENABLE_MULTI_MODULE != 0
  734. WASM_RUNTIME_API_EXTERN void
  735. wasm_runtime_set_module_reader(const module_reader reader,
  736. const module_destroyer destroyer);
  737. module_reader
  738. wasm_runtime_get_module_reader(void);
  739. module_destroyer
  740. wasm_runtime_get_module_destroyer(void);
  741. bool
  742. wasm_runtime_register_module_internal(const char *module_name,
  743. WASMModuleCommon *module,
  744. uint8 *orig_file_buf,
  745. uint32 orig_file_buf_size,
  746. char *error_buf, uint32 error_buf_size);
  747. void
  748. wasm_runtime_unregister_module(const WASMModuleCommon *module);
  749. WASMModuleCommon *
  750. wasm_runtime_find_module_registered(const char *module_name);
  751. bool
  752. wasm_runtime_add_loading_module(const char *module_name, char *error_buf,
  753. uint32 error_buf_size);
  754. void
  755. wasm_runtime_delete_loading_module(const char *module_name);
  756. bool
  757. wasm_runtime_is_loading_module(const char *module_name);
  758. void
  759. wasm_runtime_destroy_loading_module_list(void);
  760. WASMModuleCommon *
  761. wasm_runtime_search_sub_module(const WASMModuleCommon *parent_module,
  762. const char *sub_module_name);
  763. bool
  764. wasm_runtime_register_sub_module(const WASMModuleCommon *parent_module,
  765. const char *sub_module_name,
  766. WASMModuleCommon *sub_module);
  767. WASMModuleCommon *
  768. wasm_runtime_load_depended_module(const WASMModuleCommon *parent_module,
  769. const char *sub_module_name, char *error_buf,
  770. uint32 error_buf_size);
  771. bool
  772. wasm_runtime_sub_module_instantiate(WASMModuleCommon *module,
  773. WASMModuleInstanceCommon *module_inst,
  774. uint32 stack_size, uint32 heap_size,
  775. uint32 max_memory_pages, char *error_buf,
  776. 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_ENABLE_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, uint64 *start_offset,
  791. uint32 *size);
  792. bool
  793. wasm_exec_env_set_aux_stack(WASMExecEnv *exec_env, uint64 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(void);
  998. #if WASM_ENABLE_LOAD_CUSTOM_SECTION != 0
  999. void
  1000. wasm_runtime_destroy_custom_sections(WASMCustomSection *section_list);
  1001. #endif
  1002. WASM_RUNTIME_API_EXTERN bool
  1003. wasm_runtime_is_import_func_linked(const char *module_name,
  1004. const char *func_name);
  1005. WASM_RUNTIME_API_EXTERN bool
  1006. wasm_runtime_is_import_global_linked(const char *module_name,
  1007. const char *global_name);
  1008. WASM_RUNTIME_API_EXTERN bool
  1009. wasm_runtime_begin_blocking_op(WASMExecEnv *exec_env);
  1010. WASM_RUNTIME_API_EXTERN void
  1011. wasm_runtime_end_blocking_op(WASMExecEnv *exec_env);
  1012. void
  1013. wasm_runtime_interrupt_blocking_op(WASMExecEnv *exec_env);
  1014. WASM_RUNTIME_API_EXTERN bool
  1015. wasm_runtime_detect_native_stack_overflow(WASMExecEnv *exec_env);
  1016. WASM_RUNTIME_API_EXTERN bool
  1017. wasm_runtime_detect_native_stack_overflow_size(WASMExecEnv *exec_env,
  1018. uint32 requested_size);
  1019. WASM_RUNTIME_API_EXTERN bool
  1020. wasm_runtime_is_underlying_binary_freeable(WASMModuleCommon *const module);
  1021. #if WASM_ENABLE_LINUX_PERF != 0
  1022. bool
  1023. wasm_runtime_get_linux_perf(void);
  1024. void
  1025. wasm_runtime_set_linux_perf(bool flag);
  1026. #endif
  1027. #ifdef __cplusplus
  1028. }
  1029. #endif
  1030. #endif /* end of _WASM_COMMON_H */