wasm_export.h 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. /**
  6. * @file wasm_export.h
  7. *
  8. * @brief This file defines the exported common runtime APIs
  9. */
  10. #ifndef _WASM_EXPORT_H
  11. #define _WASM_EXPORT_H
  12. #include <stdint.h>
  13. #include <stdbool.h>
  14. #include "lib_export.h"
  15. #ifndef WASM_RUNTIME_API_EXTERN
  16. #if defined(_MSC_BUILD)
  17. #if defined(COMPILING_WASM_RUNTIME_API)
  18. #define WASM_RUNTIME_API_EXTERN __declspec(dllexport)
  19. #else
  20. #define WASM_RUNTIME_API_EXTERN __declspec(dllimport)
  21. #endif
  22. #elif defined(__GNUC__) || defined(__clang__)
  23. #define WASM_RUNTIME_API_EXTERN __attribute__((visibility("default")))
  24. #else
  25. #define WASM_RUNTIME_API_EXTERN
  26. #endif
  27. #endif
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #define get_module_inst(exec_env) wasm_runtime_get_module_inst(exec_env)
  32. #define validate_app_addr(offset, size) \
  33. wasm_runtime_validate_app_addr(module_inst, offset, size)
  34. #define validate_app_str_addr(offset) \
  35. wasm_runtime_validate_app_str_addr(module_inst, offset)
  36. #define addr_app_to_native(offset) \
  37. wasm_runtime_addr_app_to_native(module_inst, offset)
  38. #define addr_native_to_app(ptr) \
  39. wasm_runtime_addr_native_to_app(module_inst, ptr)
  40. #define module_malloc(size, p_native_addr) \
  41. wasm_runtime_module_malloc(module_inst, size, p_native_addr)
  42. #define module_free(offset) wasm_runtime_module_free(module_inst, offset)
  43. #define native_raw_return_type(type, args) type *raw_ret = (type *)(args)
  44. #define native_raw_get_arg(type, name, args) type name = *((type *)(args++))
  45. #define native_raw_set_return(val) *raw_ret = (val)
  46. #ifndef WASM_MODULE_T_DEFINED
  47. #define WASM_MODULE_T_DEFINED
  48. /* Uninstantiated WASM module loaded from WASM binary file
  49. or AoT binary file*/
  50. struct WASMModuleCommon;
  51. typedef struct WASMModuleCommon *wasm_module_t;
  52. #endif
  53. typedef enum {
  54. WASM_IMPORT_EXPORT_KIND_FUNC,
  55. WASM_IMPORT_EXPORT_KIND_TABLE,
  56. WASM_IMPORT_EXPORT_KIND_MEMORY,
  57. WASM_IMPORT_EXPORT_KIND_GLOBAL
  58. } wasm_import_export_kind_t;
  59. struct WASMFuncType;
  60. typedef struct WASMFuncType *wasm_func_type_t;
  61. struct WASMTableType;
  62. typedef struct WASMTableType *wasm_table_type_t;
  63. struct WASMGlobalType;
  64. typedef struct WASMGlobalType *wasm_global_type_t;
  65. #ifndef WASM_MEMORY_T_DEFINED
  66. #define WASM_MEMORY_T_DEFINED
  67. struct WASMMemory;
  68. typedef struct WASMMemory WASMMemoryType;
  69. #endif
  70. typedef WASMMemoryType *wasm_memory_type_t;
  71. typedef struct wasm_import_t {
  72. const char *module_name;
  73. const char *name;
  74. wasm_import_export_kind_t kind;
  75. bool linked;
  76. union {
  77. wasm_func_type_t func_type;
  78. wasm_table_type_t table_type;
  79. wasm_global_type_t global_type;
  80. wasm_memory_type_t memory_type;
  81. } u;
  82. } wasm_import_t;
  83. typedef struct wasm_export_t {
  84. const char *name;
  85. wasm_import_export_kind_t kind;
  86. union {
  87. wasm_func_type_t func_type;
  88. wasm_table_type_t table_type;
  89. wasm_global_type_t global_type;
  90. wasm_memory_type_t memory_type;
  91. } u;
  92. } wasm_export_t;
  93. /* Instantiated WASM module */
  94. struct WASMModuleInstanceCommon;
  95. typedef struct WASMModuleInstanceCommon *wasm_module_inst_t;
  96. /* Function instance */
  97. typedef void WASMFunctionInstanceCommon;
  98. typedef WASMFunctionInstanceCommon *wasm_function_inst_t;
  99. /* Memory instance */
  100. struct WASMMemoryInstance;
  101. typedef struct WASMMemoryInstance *wasm_memory_inst_t;
  102. typedef struct wasm_frame_t {
  103. /* wasm_instance_t */
  104. void *instance;
  105. uint32_t module_offset;
  106. uint32_t func_index;
  107. uint32_t func_offset;
  108. const char *func_name_wp;
  109. uint32_t *sp;
  110. uint8_t *frame_ref;
  111. uint32_t *lp;
  112. } WASMCApiFrame;
  113. /* WASM section */
  114. typedef struct wasm_section_t {
  115. struct wasm_section_t *next;
  116. /* section type */
  117. int section_type;
  118. /* section body, not include type and size */
  119. uint8_t *section_body;
  120. /* section body size */
  121. uint32_t section_body_size;
  122. } wasm_section_t, aot_section_t, *wasm_section_list_t, *aot_section_list_t;
  123. /* Execution environment, e.g. stack info */
  124. struct WASMExecEnv;
  125. typedef struct WASMExecEnv *wasm_exec_env_t;
  126. struct WASMSharedHeap;
  127. typedef struct WASMSharedHeap *wasm_shared_heap_t;
  128. /* Package Type */
  129. typedef enum {
  130. Wasm_Module_Bytecode = 0,
  131. Wasm_Module_AoT,
  132. Package_Type_Unknown = 0xFFFF
  133. } package_type_t;
  134. #ifndef MEM_ALLOC_OPTION_DEFINED
  135. #define MEM_ALLOC_OPTION_DEFINED
  136. /* Memory allocator type */
  137. typedef enum {
  138. /* pool mode, allocate memory from user defined heap buffer */
  139. Alloc_With_Pool = 0,
  140. /* user allocator mode, allocate memory from user defined
  141. malloc function */
  142. Alloc_With_Allocator,
  143. /* system allocator mode, allocate memory from system allocator,
  144. or, platform's os_malloc function */
  145. Alloc_With_System_Allocator,
  146. } mem_alloc_type_t;
  147. typedef enum { Alloc_For_Runtime, Alloc_For_LinearMemory } mem_alloc_usage_t;
  148. /* Memory allocator option */
  149. typedef union MemAllocOption {
  150. struct {
  151. void *heap_buf;
  152. uint32_t heap_size;
  153. } pool;
  154. struct {
  155. /* the function signature is varied when
  156. WASM_MEM_ALLOC_WITH_USER_DATA and
  157. WASM_MEM_ALLOC_WITH_USAGE are defined */
  158. void *malloc_func;
  159. void *realloc_func;
  160. void *free_func;
  161. /* allocator user data, only used when
  162. WASM_MEM_ALLOC_WITH_USER_DATA is defined */
  163. void *user_data;
  164. } allocator;
  165. } MemAllocOption;
  166. #endif
  167. /* Memory pool info */
  168. typedef struct mem_alloc_info_t {
  169. uint32_t total_size;
  170. uint32_t total_free_size;
  171. uint32_t highmark_size;
  172. } mem_alloc_info_t;
  173. /* Running mode of runtime and module instance*/
  174. typedef enum RunningMode {
  175. Mode_Interp = 1,
  176. Mode_Fast_JIT,
  177. Mode_LLVM_JIT,
  178. Mode_Multi_Tier_JIT,
  179. } RunningMode;
  180. /* WASM runtime initialize arguments */
  181. typedef struct RuntimeInitArgs {
  182. mem_alloc_type_t mem_alloc_type;
  183. MemAllocOption mem_alloc_option;
  184. const char *native_module_name;
  185. NativeSymbol *native_symbols;
  186. uint32_t n_native_symbols;
  187. /* maximum thread number, only used when
  188. WASM_ENABLE_THREAD_MGR is defined */
  189. uint32_t max_thread_num;
  190. /* Debug settings, only used when
  191. WASM_ENABLE_DEBUG_INTERP != 0 */
  192. char ip_addr[128];
  193. int unused; /* was platform_port */
  194. int instance_port;
  195. /* Fast JIT code cache size */
  196. uint32_t fast_jit_code_cache_size;
  197. /* Default GC heap size */
  198. uint32_t gc_heap_size;
  199. /* Default running mode of the runtime */
  200. RunningMode running_mode;
  201. /* LLVM JIT opt and size level */
  202. uint32_t llvm_jit_opt_level;
  203. uint32_t llvm_jit_size_level;
  204. /* Segue optimization flags for LLVM JIT */
  205. uint32_t segue_flags;
  206. /**
  207. * If enabled
  208. * - llvm-jit will output a jitdump file for `perf inject`
  209. * - aot will output a perf-${pid}.map for `perf record`
  210. * - fast-jit. TBD
  211. * - multi-tier-jit. TBD
  212. * - interpreter. TBD
  213. */
  214. bool enable_linux_perf;
  215. } RuntimeInitArgs;
  216. #ifndef LOAD_ARGS_OPTION_DEFINED
  217. #define LOAD_ARGS_OPTION_DEFINED
  218. typedef struct LoadArgs {
  219. char *name;
  220. /* This option is only used by the Wasm C API (see wasm_c_api.h) */
  221. bool clone_wasm_binary;
  222. /* False by default, used by AOT/wasm loader only.
  223. If true, the AOT/wasm loader creates a copy of some module fields (e.g.
  224. const strings), making it possible to free the wasm binary buffer after
  225. loading. */
  226. bool wasm_binary_freeable;
  227. /* false by default, if true, don't resolve the symbols yet. The
  228. wasm_runtime_load_ex has to be followed by a wasm_runtime_resolve_symbols
  229. call */
  230. bool no_resolve;
  231. /* TODO: more fields? */
  232. } LoadArgs;
  233. #endif /* LOAD_ARGS_OPTION_DEFINED */
  234. #ifndef INSTANTIATION_ARGS_OPTION_DEFINED
  235. #define INSTANTIATION_ARGS_OPTION_DEFINED
  236. /* WASM module instantiation arguments */
  237. typedef struct InstantiationArgs {
  238. uint32_t default_stack_size;
  239. uint32_t host_managed_heap_size;
  240. uint32_t max_memory_pages;
  241. } InstantiationArgs;
  242. #endif /* INSTANTIATION_ARGS_OPTION_DEFINED */
  243. #ifndef WASM_VALKIND_T_DEFINED
  244. #define WASM_VALKIND_T_DEFINED
  245. typedef uint8_t wasm_valkind_t;
  246. enum wasm_valkind_enum {
  247. WASM_I32,
  248. WASM_I64,
  249. WASM_F32,
  250. WASM_F64,
  251. WASM_V128,
  252. WASM_EXTERNREF = 128,
  253. WASM_FUNCREF,
  254. };
  255. #endif
  256. #ifndef WASM_VAL_T_DEFINED
  257. #define WASM_VAL_T_DEFINED
  258. struct wasm_ref_t;
  259. typedef struct wasm_val_t {
  260. wasm_valkind_t kind;
  261. uint8_t _paddings[7];
  262. union {
  263. /* also represent a function index */
  264. int32_t i32;
  265. int64_t i64;
  266. float f32;
  267. double f64;
  268. /* represent a foreign object, aka externref in .wat */
  269. uintptr_t foreign;
  270. struct wasm_ref_t *ref;
  271. } of;
  272. } wasm_val_t;
  273. #endif
  274. /* Global instance*/
  275. typedef struct wasm_global_inst_t {
  276. wasm_valkind_t kind;
  277. bool is_mutable;
  278. void *global_data;
  279. } wasm_global_inst_t;
  280. /* Table instance*/
  281. typedef struct wasm_table_inst_t {
  282. wasm_valkind_t elem_kind;
  283. uint32_t cur_size;
  284. uint32_t max_size;
  285. /* represents the elements of the table, for internal use only */
  286. void *elems;
  287. } wasm_table_inst_t;
  288. typedef enum {
  289. WASM_LOG_LEVEL_FATAL = 0,
  290. WASM_LOG_LEVEL_ERROR = 1,
  291. WASM_LOG_LEVEL_WARNING = 2,
  292. WASM_LOG_LEVEL_DEBUG = 3,
  293. WASM_LOG_LEVEL_VERBOSE = 4
  294. } log_level_t;
  295. typedef struct SharedHeapInitArgs {
  296. uint32_t size;
  297. void *pre_allocated_addr;
  298. } SharedHeapInitArgs;
  299. /**
  300. * Initialize the WASM runtime environment, and also initialize
  301. * the memory allocator with system allocator, which calls os_malloc
  302. * to allocate memory
  303. *
  304. * @return true if success, false otherwise
  305. */
  306. WASM_RUNTIME_API_EXTERN bool
  307. wasm_runtime_init(void);
  308. /**
  309. * Initialize the WASM runtime environment, WASM running mode,
  310. * and also initialize the memory allocator and register native symbols,
  311. * which are specified with init arguments
  312. *
  313. * @param init_args specifies the init arguments
  314. *
  315. * @return return true if success, false otherwise
  316. */
  317. WASM_RUNTIME_API_EXTERN bool
  318. wasm_runtime_full_init(RuntimeInitArgs *init_args);
  319. /**
  320. * Set the log level. To be called after the runtime is initialized.
  321. *
  322. * @param level the log level to set
  323. */
  324. WASM_RUNTIME_API_EXTERN void
  325. wasm_runtime_set_log_level(log_level_t level);
  326. /**
  327. * Query whether a certain running mode is supported for the runtime
  328. *
  329. * @param running_mode the running mode to query
  330. *
  331. * @return true if this running mode is supported, false otherwise
  332. */
  333. WASM_RUNTIME_API_EXTERN bool
  334. wasm_runtime_is_running_mode_supported(RunningMode running_mode);
  335. /**
  336. * Set the default running mode for the runtime. It is inherited
  337. * to set the running mode of a module instance when it is instantiated,
  338. * and can be changed by calling wasm_runtime_set_running_mode
  339. *
  340. * @param running_mode the running mode to set
  341. *
  342. * @return true if success, false otherwise
  343. */
  344. WASM_RUNTIME_API_EXTERN bool
  345. wasm_runtime_set_default_running_mode(RunningMode running_mode);
  346. /**
  347. * Destroy the WASM runtime environment.
  348. */
  349. WASM_RUNTIME_API_EXTERN void
  350. wasm_runtime_destroy(void);
  351. /**
  352. * Allocate memory from runtime memory environment.
  353. *
  354. * @param size bytes need to allocate
  355. *
  356. * @return the pointer to memory allocated
  357. */
  358. WASM_RUNTIME_API_EXTERN void *
  359. wasm_runtime_malloc(unsigned int size);
  360. /**
  361. * Reallocate memory from runtime memory environment
  362. *
  363. * @param ptr the original memory
  364. * @param size bytes need to reallocate
  365. *
  366. * @return the pointer to memory reallocated
  367. */
  368. WASM_RUNTIME_API_EXTERN void *
  369. wasm_runtime_realloc(void *ptr, unsigned int size);
  370. /*
  371. * Free memory to runtime memory environment.
  372. */
  373. WASM_RUNTIME_API_EXTERN void
  374. wasm_runtime_free(void *ptr);
  375. /*
  376. * Get memory info, only pool mode is supported now.
  377. */
  378. WASM_RUNTIME_API_EXTERN bool
  379. wasm_runtime_get_mem_alloc_info(mem_alloc_info_t *mem_alloc_info);
  380. /**
  381. * Get the package type of a buffer.
  382. *
  383. * @param buf the package buffer
  384. * @param size the package buffer size
  385. *
  386. * @return the package type, return Package_Type_Unknown if the type is unknown
  387. */
  388. WASM_RUNTIME_API_EXTERN package_type_t
  389. get_package_type(const uint8_t *buf, uint32_t size);
  390. /**
  391. * Get the package type of a buffer (same as get_package_type).
  392. *
  393. * @param buf the package buffer
  394. * @param size the package buffer size
  395. *
  396. * @return the package type, return Package_Type_Unknown if the type is unknown
  397. */
  398. WASM_RUNTIME_API_EXTERN package_type_t
  399. wasm_runtime_get_file_package_type(const uint8_t *buf, uint32_t size);
  400. /**
  401. * Get the package type of a module.
  402. *
  403. * @param module the module
  404. *
  405. * @return the package type, return Package_Type_Unknown if the type is
  406. * unknown
  407. */
  408. WASM_RUNTIME_API_EXTERN package_type_t
  409. wasm_runtime_get_module_package_type(const wasm_module_t module);
  410. /**
  411. * Get the package version of a buffer.
  412. *
  413. * @param buf the package buffer
  414. * @param size the package buffer size
  415. *
  416. * @return the package version, return zero if the version is unknown
  417. */
  418. WASM_RUNTIME_API_EXTERN uint32_t
  419. wasm_runtime_get_file_package_version(const uint8_t *buf, uint32_t size);
  420. /**
  421. * Get the package version of a module
  422. *
  423. * @param module the module
  424. *
  425. * @return the package version, or zero if version is unknown
  426. */
  427. WASM_RUNTIME_API_EXTERN uint32_t
  428. wasm_runtime_get_module_package_version(const wasm_module_t module);
  429. /**
  430. * Get the currently supported version of the package type
  431. *
  432. * @param package_type the package type
  433. *
  434. * @return the currently supported version, or zero if package type is unknown
  435. */
  436. WASM_RUNTIME_API_EXTERN uint32_t
  437. wasm_runtime_get_current_package_version(package_type_t package_type);
  438. /**
  439. * Check whether a file is an AOT XIP (Execution In Place) file
  440. *
  441. * @param buf the package buffer
  442. * @param size the package buffer size
  443. *
  444. * @return true if success, false otherwise
  445. */
  446. WASM_RUNTIME_API_EXTERN bool
  447. wasm_runtime_is_xip_file(const uint8_t *buf, uint32_t size);
  448. /**
  449. * Callback to load a module file into a buffer in multi-module feature
  450. */
  451. typedef bool (*module_reader)(package_type_t module_type,
  452. const char *module_name, uint8_t **p_buffer,
  453. uint32_t *p_size);
  454. /**
  455. * Callback to release the buffer loaded by module_reader callback
  456. */
  457. typedef void (*module_destroyer)(uint8_t *buffer, uint32_t size);
  458. /**
  459. * Setup callbacks for reading and releasing a buffer about a module file
  460. *
  461. * @param reader a callback to read a module file into a buffer
  462. * @param destroyer a callback to release above buffer
  463. */
  464. WASM_RUNTIME_API_EXTERN void
  465. wasm_runtime_set_module_reader(const module_reader reader,
  466. const module_destroyer destroyer);
  467. /**
  468. * Give the "module" a name "module_name".
  469. * Can not assign a new name to a module if it already has a name
  470. *
  471. * @param module_name indicate a name
  472. * @param module the target module
  473. * @param error_buf output of the exception info
  474. * @param error_buf_size the size of the exception string
  475. *
  476. * @return true means success, false means failed
  477. */
  478. WASM_RUNTIME_API_EXTERN bool
  479. wasm_runtime_register_module(const char *module_name, wasm_module_t module,
  480. char *error_buf, uint32_t error_buf_size);
  481. /**
  482. * Check if there is already a loaded module named module_name in the
  483. * runtime. Repeatedly loading a module with the same name is not allowed.
  484. *
  485. * @param module_name indicate a name
  486. *
  487. * @return return WASM module loaded, NULL if failed
  488. */
  489. WASM_RUNTIME_API_EXTERN wasm_module_t
  490. wasm_runtime_find_module_registered(const char *module_name);
  491. /**
  492. * Load a WASM module from a specified byte buffer. The byte buffer can be
  493. * WASM binary data when interpreter or JIT is enabled, or AOT binary data
  494. * when AOT is enabled. If it is AOT binary data, it must be 4-byte aligned.
  495. *
  496. * Note: In case of AOT XIP modules, the runtime doesn't make modifications
  497. * to the buffer. (Except the "Known issues" mentioned in doc/xip.md.)
  498. * Otherwise, the runtime can make modifications to the buffer for its
  499. * internal purposes. Thus, in general, it isn't safe to create multiple
  500. * modules from a single buffer.
  501. *
  502. * @param buf the byte buffer which contains the WASM/AOT binary data,
  503. * note that the byte buffer must be writable since runtime may
  504. * change its content for footprint and performance purpose, and
  505. * it must be referenceable until wasm_runtime_unload is called
  506. * @param size the size of the buffer
  507. * @param error_buf output of the exception info
  508. * @param error_buf_size the size of the exception string
  509. *
  510. * @return return WASM module loaded, NULL if failed
  511. */
  512. WASM_RUNTIME_API_EXTERN wasm_module_t
  513. wasm_runtime_load(uint8_t *buf, uint32_t size, char *error_buf,
  514. uint32_t error_buf_size);
  515. /**
  516. * Load a WASM module with specified load argument.
  517. */
  518. WASM_RUNTIME_API_EXTERN wasm_module_t
  519. wasm_runtime_load_ex(uint8_t *buf, uint32_t size, const LoadArgs *args,
  520. char *error_buf, uint32_t error_buf_size);
  521. /**
  522. * Resolve symbols for a previously loaded WASM module. Only useful when the
  523. * module was loaded with LoadArgs::no_resolve set to true
  524. */
  525. WASM_RUNTIME_API_EXTERN bool
  526. wasm_runtime_resolve_symbols(wasm_module_t module);
  527. /**
  528. * Load a WASM module from a specified WASM or AOT section list.
  529. *
  530. * @param section_list the section list which contains each section data
  531. * @param is_aot whether the section list is AOT section list
  532. * @param error_buf output of the exception info
  533. * @param error_buf_size the size of the exception string
  534. *
  535. * @return return WASM module loaded, NULL if failed
  536. */
  537. WASM_RUNTIME_API_EXTERN wasm_module_t
  538. wasm_runtime_load_from_sections(wasm_section_list_t section_list, bool is_aot,
  539. char *error_buf, uint32_t error_buf_size);
  540. /**
  541. * Unload a WASM module.
  542. *
  543. * @param module the module to be unloaded
  544. */
  545. WASM_RUNTIME_API_EXTERN void
  546. wasm_runtime_unload(wasm_module_t module);
  547. /**
  548. * Get the module hash of a WASM module, currently only available on
  549. * linux-sgx platform when the remote attestation feature is enabled
  550. *
  551. * @param module the WASM module to retrieve
  552. *
  553. * @return the module hash of the WASM module
  554. */
  555. char *
  556. wasm_runtime_get_module_hash(wasm_module_t module);
  557. /**
  558. * Set WASI parameters.
  559. *
  560. * While this API operates on a module, these parameters will be used
  561. * only when the module is instantiated. That is, you can consider these
  562. * as extra parameters for wasm_runtime_instantiate().
  563. *
  564. * @param module The module to set WASI parameters.
  565. * @param dir_list The list of directories to preopen. (real path)
  566. * @param dir_count The number of elements in dir_list.
  567. * @param map_dir_list The list of directories to preopen. (mapped path)
  568. * Format for each map entry: <guest-path>::<host-path>
  569. * @param map_dir_count The number of elements in map_dir_list.
  570. * If map_dir_count is smaller than dir_count,
  571. * mapped path is assumed to be same as the
  572. * corresponding real path for the rest of entries.
  573. * @param env The list of environment variables.
  574. * @param env_count The number of elements in env.
  575. * @param argv The list of command line arguments.
  576. * @param argc The number of elements in argv.
  577. * @param stdin_handle The raw host handle to back WASI STDIN_FILENO.
  578. * If an invalid handle is specified (e.g. -1 on POSIX,
  579. * INVALID_HANDLE_VALUE on Windows), the platform default
  580. * for STDIN is used.
  581. * @param stdoutfd The raw host handle to back WASI STDOUT_FILENO.
  582. * If an invalid handle is specified (e.g. -1 on POSIX,
  583. * INVALID_HANDLE_VALUE on Windows), the platform default
  584. * for STDOUT is used.
  585. * @param stderrfd The raw host handle to back WASI STDERR_FILENO.
  586. * If an invalid handle is specified (e.g. -1 on POSIX,
  587. * INVALID_HANDLE_VALUE on Windows), the platform default
  588. * for STDERR is used.
  589. */
  590. WASM_RUNTIME_API_EXTERN void
  591. wasm_runtime_set_wasi_args_ex(wasm_module_t module, const char *dir_list[],
  592. uint32_t dir_count, const char *map_dir_list[],
  593. uint32_t map_dir_count, const char *env[],
  594. uint32_t env_count, char *argv[], int argc,
  595. int64_t stdinfd, int64_t stdoutfd,
  596. int64_t stderrfd);
  597. /**
  598. * Set WASI parameters.
  599. *
  600. * Same as wasm_runtime_set_wasi_args_ex but with default stdio handles
  601. */
  602. WASM_RUNTIME_API_EXTERN void
  603. wasm_runtime_set_wasi_args(wasm_module_t module, const char *dir_list[],
  604. uint32_t dir_count, const char *map_dir_list[],
  605. uint32_t map_dir_count, const char *env[],
  606. uint32_t env_count, char *argv[], int argc);
  607. WASM_RUNTIME_API_EXTERN void
  608. wasm_runtime_set_wasi_addr_pool(wasm_module_t module, const char *addr_pool[],
  609. uint32_t addr_pool_size);
  610. WASM_RUNTIME_API_EXTERN void
  611. wasm_runtime_set_wasi_ns_lookup_pool(wasm_module_t module,
  612. const char *ns_lookup_pool[],
  613. uint32_t ns_lookup_pool_size);
  614. /**
  615. * Instantiate a WASM module.
  616. *
  617. * @param module the WASM module to instantiate
  618. * @param default_stack_size the default stack size of the module instance when
  619. * the exec env's operation stack isn't created by user, e.g. API
  620. * wasm_application_execute_main() and wasm_application_execute_func()
  621. * create the operation stack internally with the stack size specified
  622. * here. And API wasm_runtime_create_exec_env() creates the operation
  623. * stack with stack size specified by its parameter, the stack size
  624. * specified here is ignored.
  625. * @param host_managed_heap_size the default heap size of the module instance,
  626. * a heap will be created besides the app memory space. Both wasm app
  627. * and native function can allocate memory from the heap.
  628. * @param error_buf buffer to output the error info if failed
  629. * @param error_buf_size the size of the error buffer
  630. *
  631. * @return return the instantiated WASM module instance, NULL if failed
  632. */
  633. WASM_RUNTIME_API_EXTERN wasm_module_inst_t
  634. wasm_runtime_instantiate(const wasm_module_t module,
  635. uint32_t default_stack_size,
  636. uint32_t host_managed_heap_size, char *error_buf,
  637. uint32_t error_buf_size);
  638. /**
  639. * Instantiate a WASM module, with specified instantiation arguments
  640. *
  641. * Same as wasm_runtime_instantiate, but it also allows overwriting maximum
  642. * memory
  643. */
  644. WASM_RUNTIME_API_EXTERN wasm_module_inst_t
  645. wasm_runtime_instantiate_ex(const wasm_module_t module,
  646. const InstantiationArgs *args, char *error_buf,
  647. uint32_t error_buf_size);
  648. /**
  649. * Set the running mode of a WASM module instance, override the
  650. * default running mode of the runtime. Note that it only makes sense when
  651. * the input is a wasm bytecode file: for the AOT file, runtime always runs
  652. * it with AOT engine, and this function always returns true.
  653. *
  654. * @param module_inst the WASM module instance to set running mode
  655. * @param running_mode the running mode to set
  656. *
  657. * @return true if success, false otherwise
  658. */
  659. WASM_RUNTIME_API_EXTERN bool
  660. wasm_runtime_set_running_mode(wasm_module_inst_t module_inst,
  661. RunningMode running_mode);
  662. /**
  663. * Get the running mode of a WASM module instance, if no running mode
  664. * is explicitly set the default running mode of runtime will
  665. * be used and returned. Note that it only makes sense when the input is a
  666. * wasm bytecode file: for the AOT file, this function always returns 0.
  667. *
  668. * @param module_inst the WASM module instance to query for running mode
  669. *
  670. * @return the running mode this module instance currently use
  671. */
  672. WASM_RUNTIME_API_EXTERN RunningMode
  673. wasm_runtime_get_running_mode(wasm_module_inst_t module_inst);
  674. /**
  675. * Deinstantiate a WASM module instance, destroy the resources.
  676. *
  677. * @param module_inst the WASM module instance to destroy
  678. */
  679. WASM_RUNTIME_API_EXTERN void
  680. wasm_runtime_deinstantiate(wasm_module_inst_t module_inst);
  681. /**
  682. * Get WASM module from WASM module instance
  683. *
  684. * @param module_inst the WASM module instance to retrieve
  685. *
  686. * @return the WASM module
  687. */
  688. WASM_RUNTIME_API_EXTERN wasm_module_t
  689. wasm_runtime_get_module(wasm_module_inst_t module_inst);
  690. WASM_RUNTIME_API_EXTERN bool
  691. wasm_runtime_is_wasi_mode(wasm_module_inst_t module_inst);
  692. WASM_RUNTIME_API_EXTERN wasm_function_inst_t
  693. wasm_runtime_lookup_wasi_start_function(wasm_module_inst_t module_inst);
  694. /**
  695. * Get WASI exit code.
  696. *
  697. * After a WASI command completed its execution, an embedder can
  698. * call this function to get its exit code. (that is, the value given
  699. * to proc_exit.)
  700. *
  701. * @param module_inst the module instance
  702. */
  703. WASM_RUNTIME_API_EXTERN uint32_t
  704. wasm_runtime_get_wasi_exit_code(wasm_module_inst_t module_inst);
  705. /**
  706. * Lookup an exported function in the WASM module instance.
  707. *
  708. * @param module_inst the module instance
  709. * @param name the name of the function
  710. *
  711. * @return the function instance found, NULL if not found
  712. */
  713. WASM_RUNTIME_API_EXTERN wasm_function_inst_t
  714. wasm_runtime_lookup_function(const wasm_module_inst_t module_inst,
  715. const char *name);
  716. /**
  717. * Get parameter count of the function instance
  718. *
  719. * @param func_inst the function instance
  720. * @param module_inst the module instance the function instance belongs to
  721. *
  722. * @return the parameter count of the function instance
  723. */
  724. WASM_RUNTIME_API_EXTERN uint32_t
  725. wasm_func_get_param_count(const wasm_function_inst_t func_inst,
  726. const wasm_module_inst_t module_inst);
  727. /**
  728. * Get result count of the function instance
  729. *
  730. * @param func_inst the function instance
  731. * @param module_inst the module instance the function instance belongs to
  732. *
  733. * @return the result count of the function instance
  734. */
  735. WASM_RUNTIME_API_EXTERN uint32_t
  736. wasm_func_get_result_count(const wasm_function_inst_t func_inst,
  737. const wasm_module_inst_t module_inst);
  738. /**
  739. * Get parameter types of the function instance
  740. *
  741. * @param func_inst the function instance
  742. * @param module_inst the module instance the function instance belongs to
  743. * @param param_types the parameter types returned
  744. */
  745. WASM_RUNTIME_API_EXTERN void
  746. wasm_func_get_param_types(const wasm_function_inst_t func_inst,
  747. const wasm_module_inst_t module_inst,
  748. wasm_valkind_t *param_types);
  749. /**
  750. * Get result types of the function instance
  751. *
  752. * @param func_inst the function instance
  753. * @param module_inst the module instance the function instance belongs to
  754. * @param result_types the result types returned
  755. */
  756. WASM_RUNTIME_API_EXTERN void
  757. wasm_func_get_result_types(const wasm_function_inst_t func_inst,
  758. const wasm_module_inst_t module_inst,
  759. wasm_valkind_t *result_types);
  760. /**
  761. * Create execution environment for a WASM module instance.
  762. *
  763. * @param module_inst the module instance
  764. * @param stack_size the stack size to execute a WASM function
  765. *
  766. * @return the execution environment, NULL if failed, e.g. invalid
  767. * stack size is passed
  768. */
  769. WASM_RUNTIME_API_EXTERN wasm_exec_env_t
  770. wasm_runtime_create_exec_env(wasm_module_inst_t module_inst,
  771. uint32_t stack_size);
  772. /**
  773. * Destroy the execution environment.
  774. *
  775. * @param exec_env the execution environment to destroy
  776. */
  777. WASM_RUNTIME_API_EXTERN void
  778. wasm_runtime_destroy_exec_env(wasm_exec_env_t exec_env);
  779. /**
  780. * @brief Copy callstack frames.
  781. *
  782. * Caution: This is not a thread-safe function. Ensure the exec_env
  783. * is suspended before calling it from another thread.
  784. *
  785. * Usage: In the callback to read frames fields use APIs
  786. * for wasm_frame_t from wasm_c_api.h
  787. *
  788. * Note: The function is async-signal-safe if called with verified arguments.
  789. * Meaning it's safe to call it from a signal handler even on a signal
  790. * interruption from another thread if next variables hold valid pointers
  791. * - exec_env
  792. * - exec_env->module_inst
  793. * - exec_env->module_inst->module
  794. *
  795. * @param exec_env the execution environment that containes frames
  796. * @param buffer the buffer of size equal length * sizeof(wasm_frame_t) to copy
  797. * frames to
  798. * @param length the number of frames to copy
  799. * @param skip_n the number of frames to skip from the top of the stack
  800. *
  801. * @return number of copied frames
  802. */
  803. WASM_RUNTIME_API_EXTERN uint32_t
  804. wasm_copy_callstack(const wasm_exec_env_t exec_env, WASMCApiFrame *buffer,
  805. const uint32_t length, const uint32_t skip_n,
  806. char *error_buf, uint32_t error_buf_size);
  807. /**
  808. * Get the singleton execution environment for the instance.
  809. *
  810. * Note: The singleton execution environment is the execution
  811. * environment used internally by the runtime for the API functions
  812. * like wasm_application_execute_main, which don't take explicit
  813. * execution environment. It's associated to the corresponding
  814. * module instance and managed by the runtime. The API user should
  815. * not destroy it with wasm_runtime_destroy_exec_env.
  816. *
  817. * @param module_inst the module instance
  818. *
  819. * @return exec_env the execution environment to destroy
  820. */
  821. WASM_RUNTIME_API_EXTERN wasm_exec_env_t
  822. wasm_runtime_get_exec_env_singleton(wasm_module_inst_t module_inst);
  823. /**
  824. * Start debug instance based on given execution environment.
  825. * Note:
  826. * The debug instance will be destroyed during destroying the
  827. * execution environment, developers don't need to destroy it
  828. * manually.
  829. * If the cluster of this execution environment has already
  830. * been bound to a debug instance, this function will return true
  831. * directly.
  832. * If developer spawns some exec_env by wasm_runtime_spawn_exec_env,
  833. * don't need to call this function for every spawned exec_env as
  834. * they are sharing the same cluster with the main exec_env.
  835. *
  836. * @param exec_env the execution environment to start debug instance
  837. * @param port the port for the debug server to listen on.
  838. * 0 means automatic assignment.
  839. * -1 means to use the global setting in RuntimeInitArgs.
  840. *
  841. * @return debug port if success, 0 otherwise.
  842. */
  843. WASM_RUNTIME_API_EXTERN uint32_t
  844. wasm_runtime_start_debug_instance_with_port(wasm_exec_env_t exec_env,
  845. int32_t port);
  846. /**
  847. * Same as wasm_runtime_start_debug_instance_with_port(env, -1).
  848. */
  849. WASM_RUNTIME_API_EXTERN uint32_t
  850. wasm_runtime_start_debug_instance(wasm_exec_env_t exec_env);
  851. /**
  852. * Initialize the thread environment.
  853. * Note:
  854. * If developer creates a child thread by himself to call the
  855. * the wasm function in that thread, he should call this API
  856. * firstly before calling the wasm function and then call
  857. * wasm_runtime_destroy_thread_env() after calling the wasm
  858. * function. If the thread is created from the runtime API,
  859. * it is unnecessary to call these two APIs.
  860. *
  861. * @return true if success, false otherwise
  862. */
  863. WASM_RUNTIME_API_EXTERN bool
  864. wasm_runtime_init_thread_env(void);
  865. /**
  866. * Destroy the thread environment
  867. */
  868. WASM_RUNTIME_API_EXTERN void
  869. wasm_runtime_destroy_thread_env(void);
  870. /**
  871. * Whether the thread environment is initialized
  872. */
  873. WASM_RUNTIME_API_EXTERN bool
  874. wasm_runtime_thread_env_inited(void);
  875. /**
  876. * Get WASM module instance from execution environment
  877. *
  878. * @param exec_env the execution environment to retrieve
  879. *
  880. * @return the WASM module instance
  881. */
  882. WASM_RUNTIME_API_EXTERN wasm_module_inst_t
  883. wasm_runtime_get_module_inst(wasm_exec_env_t exec_env);
  884. /**
  885. * Set WASM module instance of execution environment
  886. * Caution:
  887. * normally the module instance is bound with the execution
  888. * environment one by one, if multiple module instances want
  889. * to share to the same execution environment, developer should
  890. * be responsible for the backup and restore of module instance
  891. *
  892. * @param exec_env the execution environment
  893. * @param module_inst the WASM module instance to set
  894. */
  895. WASM_RUNTIME_API_EXTERN void
  896. wasm_runtime_set_module_inst(wasm_exec_env_t exec_env,
  897. const wasm_module_inst_t module_inst);
  898. /**
  899. * @brief Lookup a memory instance by name
  900. *
  901. * @param module_inst The module instance
  902. * @param name The name of the memory instance
  903. *
  904. * @return The memory instance if found, NULL otherwise
  905. */
  906. WASM_RUNTIME_API_EXTERN wasm_memory_inst_t
  907. wasm_runtime_lookup_memory(const wasm_module_inst_t module_inst,
  908. const char *name);
  909. /**
  910. * @brief Get the default memory instance
  911. *
  912. * @param module_inst The module instance
  913. *
  914. * @return The memory instance if found, NULL otherwise
  915. */
  916. WASM_RUNTIME_API_EXTERN wasm_memory_inst_t
  917. wasm_runtime_get_default_memory(const wasm_module_inst_t module_inst);
  918. /**
  919. * @brief Get a memory instance by index
  920. *
  921. * @param module_inst The module instance
  922. * @param index The index of the memory instance
  923. *
  924. * @return The memory instance if found, NULL otherwise
  925. */
  926. WASM_RUNTIME_API_EXTERN wasm_memory_inst_t
  927. wasm_runtime_get_memory(const wasm_module_inst_t module_inst, uint32_t index);
  928. /**
  929. * @brief Get the current number of pages for a memory instance
  930. *
  931. * @param memory_inst The memory instance
  932. *
  933. * @return The current number of pages
  934. */
  935. WASM_RUNTIME_API_EXTERN uint64_t
  936. wasm_memory_get_cur_page_count(const wasm_memory_inst_t memory_inst);
  937. /**
  938. * @brief Get the maximum number of pages for a memory instance
  939. *
  940. * @param memory_inst The memory instance
  941. *
  942. * @return The maximum number of pages
  943. */
  944. WASM_RUNTIME_API_EXTERN uint64_t
  945. wasm_memory_get_max_page_count(const wasm_memory_inst_t memory_inst);
  946. /**
  947. * @brief Get the number of bytes per page for a memory instance
  948. *
  949. * @param memory_inst The memory instance
  950. *
  951. * @return The number of bytes per page
  952. */
  953. WASM_RUNTIME_API_EXTERN uint64_t
  954. wasm_memory_get_bytes_per_page(const wasm_memory_inst_t memory_inst);
  955. /**
  956. * @brief Get the shared status for a memory instance
  957. *
  958. * @param memory_inst The memory instance
  959. *
  960. * @return True if shared, false otherwise
  961. */
  962. WASM_RUNTIME_API_EXTERN bool
  963. wasm_memory_get_shared(const wasm_memory_inst_t memory_inst);
  964. /**
  965. * @brief Get the base address for a memory instance
  966. *
  967. * @param memory_inst The memory instance
  968. *
  969. * @return The base address on success, false otherwise
  970. */
  971. WASM_RUNTIME_API_EXTERN void *
  972. wasm_memory_get_base_address(const wasm_memory_inst_t memory_inst);
  973. /**
  974. * @brief Enlarge a memory instance by a number of pages
  975. *
  976. * @param memory_inst The memory instance
  977. * @param inc_page_count The number of pages to add
  978. *
  979. * @return True if successful, false otherwise
  980. */
  981. WASM_RUNTIME_API_EXTERN bool
  982. wasm_memory_enlarge(wasm_memory_inst_t memory_inst, uint64_t inc_page_count);
  983. /**
  984. * Call the given WASM function of a WASM module instance with
  985. * arguments (bytecode and AoT).
  986. *
  987. * @param exec_env the execution environment to call the function,
  988. * which must be created from wasm_create_exec_env()
  989. * @param function the function to call
  990. * @param argc total cell number that the function parameters occupy,
  991. * a cell is a slot of the uint32 array argv[], e.g. i32/f32 argument
  992. * occupies one cell, i64/f64 argument occupies two cells, note that
  993. * it might be different from the parameter number of the function
  994. * @param argv the arguments. If the function has return value,
  995. * the first (or first two in case 64-bit return value) element of
  996. * argv stores the return value of the called WASM function after this
  997. * function returns.
  998. *
  999. * @return true if success, false otherwise and exception will be thrown,
  1000. * the caller can call wasm_runtime_get_exception to get the exception
  1001. * info.
  1002. */
  1003. WASM_RUNTIME_API_EXTERN bool
  1004. wasm_runtime_call_wasm(wasm_exec_env_t exec_env, wasm_function_inst_t function,
  1005. uint32_t argc, uint32_t argv[]);
  1006. /**
  1007. * Call the given WASM function of a WASM module instance with
  1008. * provided results space and arguments (bytecode and AoT).
  1009. *
  1010. * @param exec_env the execution environment to call the function,
  1011. * which must be created from wasm_create_exec_env()
  1012. * @param function the function to call
  1013. * @param num_results the number of results
  1014. * @param results the pre-alloced pointer to get the results
  1015. * @param num_args the number of arguments
  1016. * @param args the arguments
  1017. *
  1018. * @return true if success, false otherwise and exception will be thrown,
  1019. * the caller can call wasm_runtime_get_exception to get the exception
  1020. * info.
  1021. */
  1022. WASM_RUNTIME_API_EXTERN bool
  1023. wasm_runtime_call_wasm_a(wasm_exec_env_t exec_env,
  1024. wasm_function_inst_t function, uint32_t num_results,
  1025. wasm_val_t results[], uint32_t num_args,
  1026. wasm_val_t *args);
  1027. /**
  1028. * Call the given WASM function of a WASM module instance with
  1029. * provided results space and variant arguments (bytecode and AoT).
  1030. *
  1031. * @param exec_env the execution environment to call the function,
  1032. * which must be created from wasm_create_exec_env()
  1033. * @param function the function to call
  1034. * @param num_results the number of results
  1035. * @param results the pre-alloced pointer to get the results
  1036. * @param num_args the number of arguments
  1037. * @param ... the variant arguments
  1038. *
  1039. * @return true if success, false otherwise and exception will be thrown,
  1040. * the caller can call wasm_runtime_get_exception to get the exception
  1041. * info.
  1042. */
  1043. WASM_RUNTIME_API_EXTERN bool
  1044. wasm_runtime_call_wasm_v(wasm_exec_env_t exec_env,
  1045. wasm_function_inst_t function, uint32_t num_results,
  1046. wasm_val_t results[], uint32_t num_args, ...);
  1047. /**
  1048. * Call a function reference of a given WASM runtime instance with
  1049. * arguments.
  1050. *
  1051. * Note: this can be used to call a function which is not exported
  1052. * by the module explicitly. You might consider it as an abstraction
  1053. * violation.
  1054. *
  1055. * @param exec_env the execution environment to call the function
  1056. * which must be created from wasm_create_exec_env()
  1057. * @param element_index the function reference index, usually
  1058. * provided by the caller of a registered native function
  1059. * @param argc the number of arguments
  1060. * @param argv the arguments. If the function method has return value,
  1061. * the first (or first two in case 64-bit return value) element of
  1062. * argv stores the return value of the called WASM function after this
  1063. * function returns.
  1064. *
  1065. * @return true if success, false otherwise and exception will be thrown,
  1066. * the caller can call wasm_runtime_get_exception to get exception info.
  1067. */
  1068. WASM_RUNTIME_API_EXTERN bool
  1069. wasm_runtime_call_indirect(wasm_exec_env_t exec_env, uint32_t element_index,
  1070. uint32_t argc, uint32_t argv[]);
  1071. /**
  1072. * Find the unique main function from a WASM module instance
  1073. * and execute that function.
  1074. *
  1075. * @param module_inst the WASM module instance
  1076. * @param argc the number of arguments
  1077. * @param argv the arguments array, if the main function has return value,
  1078. * *(int*)argv stores the return value of the called main function after
  1079. * this function returns.
  1080. *
  1081. * @return true if the main function is called, false otherwise and exception
  1082. * will be thrown, the caller can call wasm_runtime_get_exception to get
  1083. * the exception info.
  1084. */
  1085. WASM_RUNTIME_API_EXTERN bool
  1086. wasm_application_execute_main(wasm_module_inst_t module_inst, int32_t argc,
  1087. char *argv[]);
  1088. /**
  1089. * Find the specified function from a WASM module instance and execute
  1090. * that function.
  1091. *
  1092. * @param module_inst the WASM module instance
  1093. * @param name the name of the function to execute.
  1094. * to indicate the module name via: $module_name$function_name
  1095. * or just a function name: function_name
  1096. * @param argc the number of arguments
  1097. * @param argv the arguments array
  1098. *
  1099. * @return true if the specified function is called, false otherwise and
  1100. * exception will be thrown, the caller can call wasm_runtime_get_exception
  1101. * to get the exception info.
  1102. */
  1103. WASM_RUNTIME_API_EXTERN bool
  1104. wasm_application_execute_func(wasm_module_inst_t module_inst, const char *name,
  1105. int32_t argc, char *argv[]);
  1106. /**
  1107. * Get exception info of the WASM module instance.
  1108. *
  1109. * @param module_inst the WASM module instance
  1110. *
  1111. * @return the exception string
  1112. */
  1113. WASM_RUNTIME_API_EXTERN const char *
  1114. wasm_runtime_get_exception(wasm_module_inst_t module_inst);
  1115. /**
  1116. * Set exception info of the WASM module instance.
  1117. *
  1118. * @param module_inst the WASM module instance
  1119. *
  1120. * @param exception the exception string
  1121. */
  1122. WASM_RUNTIME_API_EXTERN void
  1123. wasm_runtime_set_exception(wasm_module_inst_t module_inst,
  1124. const char *exception);
  1125. /**
  1126. * Clear exception info of the WASM module instance.
  1127. *
  1128. * @param module_inst the WASM module instance
  1129. */
  1130. WASM_RUNTIME_API_EXTERN void
  1131. wasm_runtime_clear_exception(wasm_module_inst_t module_inst);
  1132. /**
  1133. * Terminate the WASM module instance.
  1134. *
  1135. * This function causes the module instance fail as if it raised a trap.
  1136. *
  1137. * This is intended to be used in situations like:
  1138. *
  1139. * - A thread is executing the WASM module instance
  1140. * (eg. it's in the middle of `wasm_application_execute_main`)
  1141. *
  1142. * - Another thread has a copy of `wasm_module_inst_t` of
  1143. * the module instance and wants to terminate it asynchronously.
  1144. *
  1145. * @param module_inst the WASM module instance
  1146. */
  1147. WASM_RUNTIME_API_EXTERN void
  1148. wasm_runtime_terminate(wasm_module_inst_t module_inst);
  1149. /**
  1150. * Set custom data to WASM module instance.
  1151. * Note:
  1152. * If WAMR_BUILD_LIB_PTHREAD is enabled, this API
  1153. * will spread the custom data to all threads
  1154. *
  1155. * @param module_inst the WASM module instance
  1156. * @param custom_data the custom data to be set
  1157. */
  1158. WASM_RUNTIME_API_EXTERN void
  1159. wasm_runtime_set_custom_data(wasm_module_inst_t module_inst, void *custom_data);
  1160. /**
  1161. * Get the custom data within a WASM module instance.
  1162. *
  1163. * @param module_inst the WASM module instance
  1164. *
  1165. * @return the custom data (NULL if not set yet)
  1166. */
  1167. WASM_RUNTIME_API_EXTERN void *
  1168. wasm_runtime_get_custom_data(wasm_module_inst_t module_inst);
  1169. /**
  1170. * Set the memory bounds checks flag of a WASM module instance.
  1171. *
  1172. * @param module_inst the WASM module instance
  1173. * @param enable the flag to enable/disable the memory bounds checks
  1174. */
  1175. WASM_RUNTIME_API_EXTERN void
  1176. wasm_runtime_set_bounds_checks(wasm_module_inst_t module_inst, bool enable);
  1177. /**
  1178. * Check if the memory bounds checks flag is enabled for a WASM module instance.
  1179. *
  1180. * @param module_inst the WASM module instance
  1181. * @return true if the memory bounds checks flag is enabled, false otherwise
  1182. */
  1183. WASM_RUNTIME_API_EXTERN bool
  1184. wasm_runtime_is_bounds_checks_enabled(wasm_module_inst_t module_inst);
  1185. /**
  1186. * Allocate memory from the heap of WASM module instance
  1187. *
  1188. * Note: wasm_runtime_module_malloc can call heap functions inside
  1189. * the module instance and thus cause a memory growth.
  1190. * This API needs to be used very carefully when you have a native
  1191. * pointers to the module instance memory obtained with
  1192. * wasm_runtime_addr_app_to_native or similar APIs.
  1193. *
  1194. * @param module_inst the WASM module instance which contains heap
  1195. * @param size the size bytes to allocate
  1196. * @param p_native_addr return native address of the allocated memory
  1197. * if it is not NULL, and return NULL if memory malloc failed
  1198. *
  1199. * @return the allocated memory address, which is a relative offset to the
  1200. * base address of the module instance's memory space. Note that
  1201. * it is not an absolute address.
  1202. * Return non-zero if success, zero if failed.
  1203. */
  1204. WASM_RUNTIME_API_EXTERN uint64_t
  1205. wasm_runtime_module_malloc(wasm_module_inst_t module_inst, uint64_t size,
  1206. void **p_native_addr);
  1207. /**
  1208. * Free memory to the heap of WASM module instance
  1209. *
  1210. * @param module_inst the WASM module instance which contains heap
  1211. * @param ptr the pointer to free
  1212. */
  1213. WASM_RUNTIME_API_EXTERN void
  1214. wasm_runtime_module_free(wasm_module_inst_t module_inst, uint64_t ptr);
  1215. /**
  1216. * Allocate memory from the heap of WASM module instance and initialize
  1217. * the memory with src
  1218. *
  1219. * @param module_inst the WASM module instance which contains heap
  1220. * @param src the source data to copy
  1221. * @param size the size of the source data
  1222. *
  1223. * @return the allocated memory address, which is a relative offset to the
  1224. * base address of the module instance's memory space. Note that
  1225. * it is not an absolute address.
  1226. * Return non-zero if success, zero if failed.
  1227. */
  1228. WASM_RUNTIME_API_EXTERN uint64_t
  1229. wasm_runtime_module_dup_data(wasm_module_inst_t module_inst, const char *src,
  1230. uint64_t size);
  1231. /**
  1232. * Validate the app address, check whether it belongs to WASM module
  1233. * instance's address space, or in its heap space or memory space.
  1234. *
  1235. * @param module_inst the WASM module instance
  1236. * @param app_offset the app address to validate, which is a relative address
  1237. * @param size the size bytes of the app address
  1238. *
  1239. * @return true if success, false otherwise. If failed, an exception will
  1240. * be thrown.
  1241. */
  1242. WASM_RUNTIME_API_EXTERN bool
  1243. wasm_runtime_validate_app_addr(wasm_module_inst_t module_inst,
  1244. uint64_t app_offset, uint64_t size);
  1245. /**
  1246. * Similar to wasm_runtime_validate_app_addr(), except that the size parameter
  1247. * is not provided. This function validates the app string address, check
  1248. * whether it belongs to WASM module instance's address space, or in its heap
  1249. * space or memory space. Moreover, it checks whether it is the offset of a
  1250. * string that is end with '\0'.
  1251. *
  1252. * Note: The validation result, especially the NUL termination check,
  1253. * is not reliable for a module instance with multiple threads because
  1254. * other threads can modify the heap behind us.
  1255. *
  1256. * @param module_inst the WASM module instance
  1257. * @param app_str_offset the app address of the string to validate, which is a
  1258. * relative address
  1259. *
  1260. * @return true if success, false otherwise. If failed, an exception will
  1261. * be thrown.
  1262. */
  1263. WASM_RUNTIME_API_EXTERN bool
  1264. wasm_runtime_validate_app_str_addr(wasm_module_inst_t module_inst,
  1265. uint64_t app_str_offset);
  1266. /**
  1267. * Validate the native address, check whether it belongs to WASM module
  1268. * instance's address space, or in its heap space or memory space.
  1269. *
  1270. * @param module_inst the WASM module instance
  1271. * @param native_ptr the native address to validate, which is an absolute
  1272. * address
  1273. * @param size the size bytes of the app address
  1274. *
  1275. * @return true if success, false otherwise. If failed, an exception will
  1276. * be thrown.
  1277. */
  1278. WASM_RUNTIME_API_EXTERN bool
  1279. wasm_runtime_validate_native_addr(wasm_module_inst_t module_inst,
  1280. void *native_ptr, uint64_t size);
  1281. /**
  1282. * Convert app address (relative address) to native address (absolute address)
  1283. *
  1284. * Note that native addresses to module instance memory can be invalidated
  1285. * on a memory growth. (Except shared memory, whose native addresses are
  1286. * stable.)
  1287. *
  1288. * @param module_inst the WASM module instance
  1289. * @param app_offset the app address
  1290. *
  1291. * @return the native address converted
  1292. */
  1293. WASM_RUNTIME_API_EXTERN void *
  1294. wasm_runtime_addr_app_to_native(wasm_module_inst_t module_inst,
  1295. uint64_t app_offset);
  1296. /**
  1297. * Convert native address (absolute address) to app address (relative address)
  1298. *
  1299. * @param module_inst the WASM module instance
  1300. * @param native_ptr the native address
  1301. *
  1302. * @return the app address converted
  1303. */
  1304. WASM_RUNTIME_API_EXTERN uint64_t
  1305. wasm_runtime_addr_native_to_app(wasm_module_inst_t module_inst,
  1306. void *native_ptr);
  1307. /**
  1308. * Get the app address range (relative address) that a app address belongs to
  1309. *
  1310. * @param module_inst the WASM module instance
  1311. * @param app_offset the app address to retrieve
  1312. * @param p_app_start_offset buffer to output the app start offset if not NULL
  1313. * @param p_app_end_offset buffer to output the app end offset if not NULL
  1314. *
  1315. * @return true if success, false otherwise.
  1316. */
  1317. WASM_RUNTIME_API_EXTERN bool
  1318. wasm_runtime_get_app_addr_range(wasm_module_inst_t module_inst,
  1319. uint64_t app_offset,
  1320. uint64_t *p_app_start_offset,
  1321. uint64_t *p_app_end_offset);
  1322. /**
  1323. * Get the native address range (absolute address) that a native address
  1324. * belongs to
  1325. *
  1326. * @param module_inst the WASM module instance
  1327. * @param native_ptr the native address to retrieve
  1328. * @param p_native_start_addr buffer to output the native start address
  1329. * if not NULL
  1330. * @param p_native_end_addr buffer to output the native end address
  1331. * if not NULL
  1332. *
  1333. * @return true if success, false otherwise.
  1334. */
  1335. WASM_RUNTIME_API_EXTERN bool
  1336. wasm_runtime_get_native_addr_range(wasm_module_inst_t module_inst,
  1337. uint8_t *native_ptr,
  1338. uint8_t **p_native_start_addr,
  1339. uint8_t **p_native_end_addr);
  1340. /**
  1341. * Get the number of import items for a WASM module
  1342. *
  1343. * @param module the WASM module
  1344. *
  1345. * @return the number of imports (zero for none), or -1 for failure
  1346. */
  1347. WASM_RUNTIME_API_EXTERN int32_t
  1348. wasm_runtime_get_import_count(const wasm_module_t module);
  1349. /**
  1350. * Get information about a specific WASM module import
  1351. *
  1352. * @param module the WASM module
  1353. * @param import_index the desired import index
  1354. * @param import_type the location to store information about the import
  1355. */
  1356. WASM_RUNTIME_API_EXTERN void
  1357. wasm_runtime_get_import_type(const wasm_module_t module, int32_t import_index,
  1358. wasm_import_t *import_type);
  1359. /**
  1360. * Get the number of export items for a WASM module
  1361. *
  1362. * @param module the WASM module
  1363. *
  1364. * @return the number of exports (zero for none), or -1 for failure
  1365. */
  1366. WASM_RUNTIME_API_EXTERN int32_t
  1367. wasm_runtime_get_export_count(const wasm_module_t module);
  1368. /**
  1369. * Get information about a specific WASM module export
  1370. *
  1371. * @param module the WASM module
  1372. * @param export_index the desired export index
  1373. * @param export_type the location to store information about the export
  1374. */
  1375. WASM_RUNTIME_API_EXTERN void
  1376. wasm_runtime_get_export_type(const wasm_module_t module, int32_t export_index,
  1377. wasm_export_t *export_type);
  1378. /**
  1379. * Get the number of parameters for a function type
  1380. *
  1381. * @param func_type the function type
  1382. *
  1383. * @return the number of parameters for the function type
  1384. */
  1385. WASM_RUNTIME_API_EXTERN uint32_t
  1386. wasm_func_type_get_param_count(const wasm_func_type_t func_type);
  1387. /**
  1388. * Get the kind of a parameter for a function type
  1389. *
  1390. * @param func_type the function type
  1391. * @param param_index the index of the parameter to get
  1392. *
  1393. * @return the kind of the parameter if successful, -1 otherwise
  1394. */
  1395. WASM_RUNTIME_API_EXTERN wasm_valkind_t
  1396. wasm_func_type_get_param_valkind(const wasm_func_type_t func_type,
  1397. uint32_t param_index);
  1398. /**
  1399. * Get the number of results for a function type
  1400. *
  1401. * @param func_type the function type
  1402. *
  1403. * @return the number of results for the function type
  1404. */
  1405. WASM_RUNTIME_API_EXTERN uint32_t
  1406. wasm_func_type_get_result_count(const wasm_func_type_t func_type);
  1407. /**
  1408. * Get the kind of a result for a function type
  1409. *
  1410. * @param func_type the function type
  1411. * @param result_index the index of the result to get
  1412. *
  1413. * @return the kind of the result if successful, -1 otherwise
  1414. */
  1415. WASM_RUNTIME_API_EXTERN wasm_valkind_t
  1416. wasm_func_type_get_result_valkind(const wasm_func_type_t func_type,
  1417. uint32_t result_index);
  1418. /**
  1419. * Get the kind for a global type
  1420. *
  1421. * @param global_type the global type
  1422. *
  1423. * @return the kind of the global
  1424. */
  1425. WASM_RUNTIME_API_EXTERN wasm_valkind_t
  1426. wasm_global_type_get_valkind(const wasm_global_type_t global_type);
  1427. /**
  1428. * Get the mutability for a global type
  1429. *
  1430. * @param global_type the global type
  1431. *
  1432. * @return true if mutable, false otherwise
  1433. */
  1434. WASM_RUNTIME_API_EXTERN bool
  1435. wasm_global_type_get_mutable(const wasm_global_type_t global_type);
  1436. /**
  1437. * Get the shared setting for a memory type
  1438. *
  1439. * @param memory_type the memory type
  1440. *
  1441. * @return true if shared, false otherwise
  1442. */
  1443. WASM_RUNTIME_API_EXTERN bool
  1444. wasm_memory_type_get_shared(const wasm_memory_type_t memory_type);
  1445. /**
  1446. * Get the initial page count for a memory type
  1447. *
  1448. * @param memory_type the memory type
  1449. *
  1450. * @return the initial memory page count
  1451. */
  1452. WASM_RUNTIME_API_EXTERN uint32_t
  1453. wasm_memory_type_get_init_page_count(const wasm_memory_type_t memory_type);
  1454. /**
  1455. * Get the maximum page count for a memory type
  1456. *
  1457. * @param memory_type the memory type
  1458. *
  1459. * @return the maximum memory page count
  1460. */
  1461. WASM_RUNTIME_API_EXTERN uint32_t
  1462. wasm_memory_type_get_max_page_count(const wasm_memory_type_t memory_type);
  1463. /**
  1464. * Get the element kind for a table type
  1465. *
  1466. * @param table_type the table type
  1467. *
  1468. * @return the element kind
  1469. */
  1470. WASM_RUNTIME_API_EXTERN wasm_valkind_t
  1471. wasm_table_type_get_elem_kind(const wasm_table_type_t table_type);
  1472. /**
  1473. * Get the sharing setting for a table type
  1474. *
  1475. * @param table_type the table type
  1476. *
  1477. * @return true if shared, false otherwise
  1478. */
  1479. WASM_RUNTIME_API_EXTERN bool
  1480. wasm_table_type_get_shared(const wasm_table_type_t table_type);
  1481. /**
  1482. * Get the initial size for a table type
  1483. *
  1484. * @param table_type the table type
  1485. *
  1486. * @return the initial table size
  1487. */
  1488. WASM_RUNTIME_API_EXTERN uint32_t
  1489. wasm_table_type_get_init_size(const wasm_table_type_t table_type);
  1490. /**
  1491. * Get the maximum size for a table type
  1492. *
  1493. * @param table_type the table type
  1494. *
  1495. * @return the maximum table size
  1496. */
  1497. WASM_RUNTIME_API_EXTERN uint32_t
  1498. wasm_table_type_get_max_size(const wasm_table_type_t table_type);
  1499. /**
  1500. * Register native functions with same module name
  1501. *
  1502. * Note: The array `native_symbols` should not be read-only because the
  1503. * library can modify it in-place.
  1504. *
  1505. * Note: After successful call of this function, the array `native_symbols`
  1506. * is owned by the library.
  1507. *
  1508. * @param module_name the module name of the native functions
  1509. * @param native_symbols specifies an array of NativeSymbol structures which
  1510. * contain the names, function pointers and signatures
  1511. * Note: WASM runtime will not allocate memory to clone the data, so
  1512. * user must ensure the array can be used forever
  1513. * Meanings of letters in function signature:
  1514. * 'i': the parameter is i32 type
  1515. * 'I': the parameter is i64 type
  1516. * 'f': the parameter is f32 type
  1517. * 'F': the parameter is f64 type
  1518. * 'r': the parameter is externref type, it should be a uintptr_t
  1519. * in host
  1520. * '*': the parameter is a pointer (i32 in WASM), and runtime will
  1521. * auto check its boundary before calling the native function.
  1522. * If it is followed by '~', the checked length of the pointer
  1523. * is gotten from the following parameter, if not, the checked
  1524. * length of the pointer is 1.
  1525. * '~': the parameter is the pointer's length with i32 type, and must
  1526. * follow after '*'
  1527. * '$': the parameter is a string (i32 in WASM), and runtime will
  1528. * auto check its boundary before calling the native function
  1529. * @param n_native_symbols specifies the number of native symbols in the array
  1530. *
  1531. * @return true if success, false otherwise
  1532. */
  1533. WASM_RUNTIME_API_EXTERN bool
  1534. wasm_runtime_register_natives(const char *module_name,
  1535. NativeSymbol *native_symbols,
  1536. uint32_t n_native_symbols);
  1537. /**
  1538. * Register native functions with same module name, similar to
  1539. * wasm_runtime_register_natives, the difference is that runtime passes raw
  1540. * arguments to native API, which means that the native API should be defined as
  1541. * void foo(wasm_exec_env_t exec_env, uint64 *args);
  1542. * and native API should extract arguments one by one from args array with macro
  1543. * native_raw_get_arg
  1544. * and write the return value back to args[0] with macro
  1545. * native_raw_return_type and native_raw_set_return
  1546. */
  1547. WASM_RUNTIME_API_EXTERN bool
  1548. wasm_runtime_register_natives_raw(const char *module_name,
  1549. NativeSymbol *native_symbols,
  1550. uint32_t n_native_symbols);
  1551. /**
  1552. * Undo wasm_runtime_register_natives or wasm_runtime_register_natives_raw
  1553. *
  1554. * @param module_name Should be the same as the corresponding
  1555. * wasm_runtime_register_natives.
  1556. * (Same in term of strcmp.)
  1557. *
  1558. * @param native_symbols Should be the same as the corresponding
  1559. * wasm_runtime_register_natives.
  1560. * (Same in term of pointer comparison.)
  1561. *
  1562. * @return true if success, false otherwise
  1563. */
  1564. WASM_RUNTIME_API_EXTERN bool
  1565. wasm_runtime_unregister_natives(const char *module_name,
  1566. NativeSymbol *native_symbols);
  1567. /**
  1568. * Get an export global instance
  1569. *
  1570. * @param module_inst the module instance
  1571. * @param name the export global name
  1572. * @param global_inst location to store the global instance
  1573. *
  1574. * @return true if success, false otherwise
  1575. *
  1576. */
  1577. WASM_RUNTIME_API_EXTERN bool
  1578. wasm_runtime_get_export_global_inst(const wasm_module_inst_t module_inst,
  1579. const char *name,
  1580. wasm_global_inst_t *global_inst);
  1581. /**
  1582. * Get an export table instance
  1583. *
  1584. * @param module_inst the module instance
  1585. * @param name the export table name
  1586. * @param table_inst location to store the table instance
  1587. *
  1588. * @return true if success, false otherwise
  1589. *
  1590. */
  1591. WASM_RUNTIME_API_EXTERN bool
  1592. wasm_runtime_get_export_table_inst(const wasm_module_inst_t module_inst,
  1593. const char *name,
  1594. wasm_table_inst_t *table_inst);
  1595. /**
  1596. * Get a function instance from a table.
  1597. *
  1598. * @param module_inst the module instance
  1599. * @param table_inst the table instance
  1600. * @param idx the index in the table
  1601. *
  1602. * @return the function instance if successful, NULL otherwise
  1603. */
  1604. WASM_RUNTIME_API_EXTERN wasm_function_inst_t
  1605. wasm_table_get_func_inst(const wasm_module_inst_t module_inst,
  1606. const wasm_table_inst_t *table_inst, uint32_t idx);
  1607. /**
  1608. * Get attachment of native function from execution environment
  1609. *
  1610. * @param exec_env the execution environment to retrieve
  1611. *
  1612. * @return the attachment of native function
  1613. */
  1614. WASM_RUNTIME_API_EXTERN void *
  1615. wasm_runtime_get_function_attachment(wasm_exec_env_t exec_env);
  1616. /**
  1617. * Set user data to execution environment.
  1618. *
  1619. * @param exec_env the execution environment
  1620. * @param user_data the user data to be set
  1621. */
  1622. WASM_RUNTIME_API_EXTERN void
  1623. wasm_runtime_set_user_data(wasm_exec_env_t exec_env, void *user_data);
  1624. /**
  1625. * Get the user data within execution environment.
  1626. *
  1627. * @param exec_env the execution environment
  1628. *
  1629. * @return the user data (NULL if not set yet)
  1630. */
  1631. WASM_RUNTIME_API_EXTERN void *
  1632. wasm_runtime_get_user_data(wasm_exec_env_t exec_env);
  1633. /**
  1634. * Set native stack boundary to execution environment, if it is set,
  1635. * it will be used instead of getting the boundary with the platform
  1636. * layer API when calling wasm functions. This is useful for some
  1637. * fiber cases.
  1638. *
  1639. * Note: unlike setting the boundary by runtime, this API doesn't add
  1640. * the WASM_STACK_GUARD_SIZE(see comments in core/config.h) to the
  1641. * exec_env's native_stack_boundary to reserve bytes to the native
  1642. * thread stack boundary, which is used to throw native stack overflow
  1643. * exception if the guard boundary is reached. Developer should ensure
  1644. * that enough guard bytes are kept.
  1645. *
  1646. * @param exec_env the execution environment
  1647. * @param native_stack_boundary the user data to be set
  1648. */
  1649. WASM_RUNTIME_API_EXTERN void
  1650. wasm_runtime_set_native_stack_boundary(wasm_exec_env_t exec_env,
  1651. uint8_t *native_stack_boundary);
  1652. /**
  1653. * Set the instruction count limit to the execution environment.
  1654. * By default the instruction count limit is -1, which means no limit.
  1655. * However, if the instruction count limit is set to a positive value,
  1656. * the execution will be terminated when the instruction count reaches
  1657. * the limit.
  1658. *
  1659. * @param exec_env the execution environment
  1660. * @param instruction_count the instruction count limit
  1661. */
  1662. WASM_RUNTIME_API_EXTERN void
  1663. wasm_runtime_set_instruction_count_limit(wasm_exec_env_t exec_env,
  1664. int instruction_count);
  1665. /**
  1666. * Dump runtime memory consumption, including:
  1667. * Exec env memory consumption
  1668. * WASM module memory consumption
  1669. * WASM module instance memory consumption
  1670. * stack and app heap used info
  1671. *
  1672. * @param exec_env the execution environment
  1673. */
  1674. WASM_RUNTIME_API_EXTERN void
  1675. wasm_runtime_dump_mem_consumption(wasm_exec_env_t exec_env);
  1676. /**
  1677. * Dump runtime performance profiler data of each function
  1678. *
  1679. * @param module_inst the WASM module instance to profile
  1680. */
  1681. WASM_RUNTIME_API_EXTERN void
  1682. wasm_runtime_dump_perf_profiling(wasm_module_inst_t module_inst);
  1683. /**
  1684. * Return total wasm functions' execution time in ms
  1685. *
  1686. * @param module_inst the WASM module instance to profile
  1687. */
  1688. WASM_RUNTIME_API_EXTERN double
  1689. wasm_runtime_sum_wasm_exec_time(wasm_module_inst_t module_inst);
  1690. /**
  1691. * Return execution time in ms of a given wasm function with
  1692. * func_name. If the function is not found, return 0.
  1693. *
  1694. * @param module_inst the WASM module instance to profile
  1695. * @param func_name could be an export name or a name in the
  1696. * name section
  1697. */
  1698. WASM_RUNTIME_API_EXTERN double
  1699. wasm_runtime_get_wasm_func_exec_time(wasm_module_inst_t inst,
  1700. const char *func_name);
  1701. /* wasm thread callback function type */
  1702. typedef void *(*wasm_thread_callback_t)(wasm_exec_env_t, void *);
  1703. /* wasm thread type */
  1704. typedef uintptr_t wasm_thread_t;
  1705. /**
  1706. * Set the max thread num per cluster.
  1707. *
  1708. * @param num maximum thread num
  1709. */
  1710. WASM_RUNTIME_API_EXTERN void
  1711. wasm_runtime_set_max_thread_num(uint32_t num);
  1712. /**
  1713. * Spawn a new exec_env, the spawned exec_env
  1714. * can be used in other threads
  1715. *
  1716. * @param num the original exec_env
  1717. *
  1718. * @return the spawned exec_env if success, NULL otherwise
  1719. */
  1720. WASM_RUNTIME_API_EXTERN wasm_exec_env_t
  1721. wasm_runtime_spawn_exec_env(wasm_exec_env_t exec_env);
  1722. /**
  1723. * Destroy the spawned exec_env
  1724. *
  1725. * @param exec_env the spawned exec_env
  1726. */
  1727. WASM_RUNTIME_API_EXTERN void
  1728. wasm_runtime_destroy_spawned_exec_env(wasm_exec_env_t exec_env);
  1729. /**
  1730. * Spawn a thread from the given exec_env
  1731. *
  1732. * @param exec_env the original exec_env
  1733. * @param tid thread id to be returned to the caller
  1734. * @param callback the callback function provided by the user
  1735. * @param arg the arguments passed to the callback
  1736. *
  1737. * @return 0 if success, -1 otherwise
  1738. */
  1739. WASM_RUNTIME_API_EXTERN int32_t
  1740. wasm_runtime_spawn_thread(wasm_exec_env_t exec_env, wasm_thread_t *tid,
  1741. wasm_thread_callback_t callback, void *arg);
  1742. /**
  1743. * Wait a spawned thread to terminate
  1744. *
  1745. * @param tid thread id
  1746. * @param retval if not NULL, output the return value of the thread
  1747. *
  1748. * @return 0 if success, error number otherwise
  1749. */
  1750. WASM_RUNTIME_API_EXTERN int32_t
  1751. wasm_runtime_join_thread(wasm_thread_t tid, void **retval);
  1752. /**
  1753. * Map external object to an internal externref index: if the index
  1754. * has been created, return it, otherwise create the index.
  1755. *
  1756. * @param module_inst the WASM module instance that the extern object
  1757. * belongs to
  1758. * @param extern_obj the external object to be mapped
  1759. * @param p_externref_idx return externref index of the external object
  1760. *
  1761. * @return true if success, false otherwise
  1762. */
  1763. WASM_RUNTIME_API_EXTERN bool
  1764. wasm_externref_obj2ref(wasm_module_inst_t module_inst, void *extern_obj,
  1765. uint32_t *p_externref_idx);
  1766. /**
  1767. * Delete external object registered by `wasm_externref_obj2ref`.
  1768. *
  1769. * @param module_inst the WASM module instance that the extern object
  1770. * belongs to
  1771. * @param extern_obj the external object to be deleted
  1772. *
  1773. * @return true if success, false otherwise
  1774. */
  1775. WASM_RUNTIME_API_EXTERN bool
  1776. wasm_externref_objdel(wasm_module_inst_t module_inst, void *extern_obj);
  1777. /**
  1778. * Set cleanup callback to release external object.
  1779. *
  1780. * @param module_inst the WASM module instance that the extern object
  1781. * belongs to
  1782. * @param extern_obj the external object to which to set the
  1783. * `extern_obj_cleanup` cleanup callback.
  1784. * @param extern_obj_cleanup a callback to release `extern_obj`
  1785. *
  1786. * @return true if success, false otherwise
  1787. */
  1788. WASM_RUNTIME_API_EXTERN bool
  1789. wasm_externref_set_cleanup(wasm_module_inst_t module_inst, void *extern_obj,
  1790. void (*extern_obj_cleanup)(void *));
  1791. /**
  1792. * Retrieve the external object from an internal externref index
  1793. *
  1794. * @param externref_idx the externref index to retrieve
  1795. * @param p_extern_obj return the mapped external object of
  1796. * the externref index
  1797. *
  1798. * @return true if success, false otherwise
  1799. */
  1800. WASM_RUNTIME_API_EXTERN bool
  1801. wasm_externref_ref2obj(uint32_t externref_idx, void **p_extern_obj);
  1802. /**
  1803. * Retain an extern object which is mapped to the internal externref
  1804. * so that the object won't be cleaned during extern object reclaim
  1805. * if it isn't used.
  1806. *
  1807. * @param externref_idx the externref index of an external object
  1808. * to retain
  1809. * @return true if success, false otherwise
  1810. */
  1811. WASM_RUNTIME_API_EXTERN bool
  1812. wasm_externref_retain(uint32_t externref_idx);
  1813. /**
  1814. * Dump the call stack to stdout
  1815. *
  1816. * @param exec_env the execution environment
  1817. */
  1818. WASM_RUNTIME_API_EXTERN void
  1819. wasm_runtime_dump_call_stack(wasm_exec_env_t exec_env);
  1820. /**
  1821. * Get the size required to store the call stack contents, including
  1822. * the space for terminating null byte ('\0')
  1823. *
  1824. * @param exec_env the execution environment
  1825. *
  1826. * @return size required to store the contents, 0 means error
  1827. */
  1828. WASM_RUNTIME_API_EXTERN uint32_t
  1829. wasm_runtime_get_call_stack_buf_size(wasm_exec_env_t exec_env);
  1830. /**
  1831. * Dump the call stack to buffer.
  1832. *
  1833. * @note this function is not thread-safe, please only use this API
  1834. * when the exec_env is not executing
  1835. *
  1836. * @param exec_env the execution environment
  1837. * @param buf buffer to store the dumped content
  1838. * @param len length of the buffer
  1839. *
  1840. * @return bytes dumped to the buffer, including the terminating null
  1841. * byte ('\0'), 0 means error and data in buf may be invalid
  1842. */
  1843. WASM_RUNTIME_API_EXTERN uint32_t
  1844. wasm_runtime_dump_call_stack_to_buf(wasm_exec_env_t exec_env, char *buf,
  1845. uint32_t len);
  1846. /**
  1847. * Get the size required to store the LLVM PGO profile data
  1848. *
  1849. * @param module_inst the WASM module instance
  1850. *
  1851. * @return size required to store the contents, 0 means error
  1852. */
  1853. WASM_RUNTIME_API_EXTERN uint32_t
  1854. wasm_runtime_get_pgo_prof_data_size(wasm_module_inst_t module_inst);
  1855. /**
  1856. * Dump the LLVM PGO profile data to buffer
  1857. *
  1858. * @param module_inst the WASM module instance
  1859. * @param buf buffer to store the dumped content
  1860. * @param len length of the buffer
  1861. *
  1862. * @return bytes dumped to the buffer, 0 means error and data in buf
  1863. * may be invalid
  1864. */
  1865. WASM_RUNTIME_API_EXTERN uint32_t
  1866. wasm_runtime_dump_pgo_prof_data_to_buf(wasm_module_inst_t module_inst,
  1867. char *buf, uint32_t len);
  1868. /**
  1869. * Get a custom section by name
  1870. *
  1871. * @param module_comm the module to find
  1872. * @param name name of the custom section
  1873. * @param len return the length of the content if found
  1874. *
  1875. * @return Custom section content (not including the name length
  1876. * and name string) if found, NULL otherwise
  1877. */
  1878. WASM_RUNTIME_API_EXTERN const uint8_t *
  1879. wasm_runtime_get_custom_section(const wasm_module_t module_comm,
  1880. const char *name, uint32_t *len);
  1881. /**
  1882. * Get WAMR semantic version
  1883. */
  1884. WASM_RUNTIME_API_EXTERN void
  1885. wasm_runtime_get_version(uint32_t *major, uint32_t *minor, uint32_t *patch);
  1886. /**
  1887. * Check whether an import func `(import <module_name> <func_name> (func ...))`
  1888. * is linked or not with runtime registered native functions
  1889. */
  1890. WASM_RUNTIME_API_EXTERN bool
  1891. wasm_runtime_is_import_func_linked(const char *module_name,
  1892. const char *func_name);
  1893. /**
  1894. * Check whether an import global `(import <module_name> <global_name>
  1895. * (global ...))` is linked or not with runtime registered native globals
  1896. */
  1897. WASM_RUNTIME_API_EXTERN bool
  1898. wasm_runtime_is_import_global_linked(const char *module_name,
  1899. const char *global_name);
  1900. /**
  1901. * Enlarge the memory region for a module instance
  1902. *
  1903. * @param module_inst the module instance
  1904. * @param inc_page_count the number of pages to add
  1905. *
  1906. * @return true if success, false otherwise
  1907. */
  1908. WASM_RUNTIME_API_EXTERN bool
  1909. wasm_runtime_enlarge_memory(wasm_module_inst_t module_inst,
  1910. uint64_t inc_page_count);
  1911. typedef enum {
  1912. INTERNAL_ERROR,
  1913. MAX_SIZE_REACHED,
  1914. } enlarge_memory_error_reason_t;
  1915. typedef void (*enlarge_memory_error_callback_t)(
  1916. uint32_t inc_page_count, uint64_t current_memory_size,
  1917. uint32_t memory_index, enlarge_memory_error_reason_t failure_reason,
  1918. wasm_module_inst_t instance, wasm_exec_env_t exec_env, void *user_data);
  1919. /**
  1920. * Setup callback invoked when memory.grow fails
  1921. */
  1922. WASM_RUNTIME_API_EXTERN void
  1923. wasm_runtime_set_enlarge_mem_error_callback(
  1924. const enlarge_memory_error_callback_t callback, void *user_data);
  1925. /*
  1926. * module instance context APIs
  1927. * wasm_runtime_create_context_key
  1928. * wasm_runtime_destroy_context_key
  1929. * wasm_runtime_set_context
  1930. * wasm_runtime_set_context_spread
  1931. * wasm_runtime_get_context
  1932. *
  1933. * This set of APIs is intended to be used by an embedder which provides
  1934. * extra sets of native functions, which need per module instance state
  1935. * and are maintained outside of the WAMR tree.
  1936. *
  1937. * It's modelled after the pthread specific API.
  1938. *
  1939. * wasm_runtime_set_context_spread is similar to
  1940. * wasm_runtime_set_context, except that
  1941. * wasm_runtime_set_context_spread applies the change
  1942. * to all threads in the cluster.
  1943. * It's an undefined behavior if multiple threads in a cluster call
  1944. * wasm_runtime_set_context_spread on the same key
  1945. * simultaneously. It's a caller's responsibility to perform necessary
  1946. * serialization if necessary. For example:
  1947. *
  1948. * if (wasm_runtime_get_context(inst, key) == NULL) {
  1949. * newctx = alloc_and_init(...);
  1950. * lock(some_lock);
  1951. * if (wasm_runtime_get_context(inst, key) == NULL) {
  1952. * // this thread won the race
  1953. * wasm_runtime_set_context_spread(inst, key, newctx);
  1954. * newctx = NULL;
  1955. * }
  1956. * unlock(some_lock);
  1957. * if (newctx != NULL) {
  1958. * // this thread lost the race, free it
  1959. * cleanup_and_free(newctx);
  1960. * }
  1961. * }
  1962. *
  1963. * Note: dynamic key create/destroy while instances are live is not
  1964. * implemented as of writing this.
  1965. * it's caller's responsibility to ensure destroying all module instances
  1966. * before calling wasm_runtime_create_context_key or
  1967. * wasm_runtime_destroy_context_key.
  1968. * otherwise, it's an undefined behavior.
  1969. *
  1970. * Note about threads:
  1971. * - When spawning a thread, the contexts (the pointers given to
  1972. * wasm_runtime_set_context) are copied from the parent
  1973. * instance.
  1974. * - The destructor is called only on the main instance.
  1975. */
  1976. WASM_RUNTIME_API_EXTERN void *
  1977. wasm_runtime_create_context_key(void (*dtor)(wasm_module_inst_t inst,
  1978. void *ctx));
  1979. WASM_RUNTIME_API_EXTERN void
  1980. wasm_runtime_destroy_context_key(void *key);
  1981. WASM_RUNTIME_API_EXTERN void
  1982. wasm_runtime_set_context(wasm_module_inst_t inst, void *key, void *ctx);
  1983. WASM_RUNTIME_API_EXTERN void
  1984. wasm_runtime_set_context_spread(wasm_module_inst_t inst, void *key, void *ctx);
  1985. WASM_RUNTIME_API_EXTERN void *
  1986. wasm_runtime_get_context(wasm_module_inst_t inst, void *key);
  1987. /*
  1988. * wasm_runtime_begin_blocking_op/wasm_runtime_end_blocking_op
  1989. *
  1990. * These APIs are intended to be used by the implementations of
  1991. * host functions. It wraps an operation which possibly blocks for long
  1992. * to prepare for async termination.
  1993. *
  1994. * For simplicity, we recommend to wrap only the very minimum piece of
  1995. * the code with this. Ideally, just a single system call.
  1996. *
  1997. * eg.
  1998. *
  1999. * if (!wasm_runtime_begin_blocking_op(exec_env)) {
  2000. * return EINTR;
  2001. * }
  2002. * ret = possibly_blocking_op();
  2003. * wasm_runtime_end_blocking_op(exec_env);
  2004. * return ret;
  2005. *
  2006. * If threading support (WASM_ENABLE_THREAD_MGR) is not enabled,
  2007. * these functions are no-op.
  2008. *
  2009. * If the underlying platform support (OS_ENABLE_WAKEUP_BLOCKING_OP) is
  2010. * not available, these functions are no-op. In that case, the runtime
  2011. * might not terminate a blocking thread in a timely manner.
  2012. *
  2013. * If the underlying platform support is available, it's used to wake up
  2014. * the thread for async termination. The expectation here is that a
  2015. * `os_wakeup_blocking_op` call makes the blocking operation
  2016. * (`possibly_blocking_op` in the above example) return in a timely manner.
  2017. *
  2018. * The actual wake up mechanism used by `os_wakeup_blocking_op` is
  2019. * platform-dependent. It might impose some platform-dependent restrictions
  2020. * on the implementation of the blocking operation.
  2021. *
  2022. * For example, on POSIX-like platforms, a signal (by default SIGUSR1) is
  2023. * used. The signal delivery configurations (eg. signal handler, signal mask,
  2024. * etc) for the signal are set up by the runtime. You can change the signal
  2025. * to use for this purpose by calling os_set_signal_number_for_blocking_op
  2026. * before the runtime initialization.
  2027. */
  2028. WASM_RUNTIME_API_EXTERN bool
  2029. wasm_runtime_begin_blocking_op(wasm_exec_env_t exec_env);
  2030. WASM_RUNTIME_API_EXTERN void
  2031. wasm_runtime_end_blocking_op(wasm_exec_env_t exec_env);
  2032. WASM_RUNTIME_API_EXTERN bool
  2033. wasm_runtime_set_module_name(wasm_module_t module, const char *name,
  2034. char *error_buf, uint32_t error_buf_size);
  2035. /* return the most recently set module name or "" if never set before */
  2036. WASM_RUNTIME_API_EXTERN const char *
  2037. wasm_runtime_get_module_name(wasm_module_t module);
  2038. /*
  2039. * wasm_runtime_detect_native_stack_overflow
  2040. *
  2041. * Detect native stack shortage.
  2042. * Ensure that the calling thread still has a reasonable amount of
  2043. * native stack (WASM_STACK_GUARD_SIZE bytes) available.
  2044. *
  2045. * If enough stack is left, this function returns true.
  2046. * Otherwise, this function raises a "native stack overflow" trap and
  2047. * returns false.
  2048. *
  2049. * Note: please do not expect a very strict detection. it's a good idea
  2050. * to give some margins. wasm_runtime_detect_native_stack_overflow itself
  2051. * requires a small amount of stack to run.
  2052. */
  2053. WASM_RUNTIME_API_EXTERN bool
  2054. wasm_runtime_detect_native_stack_overflow(wasm_exec_env_t exec_env);
  2055. /*
  2056. * wasm_runtime_detect_native_stack_overflow_size
  2057. *
  2058. * Similar to wasm_runtime_detect_native_stack_overflow,
  2059. * but use the caller-specified size instead of WASM_STACK_GUARD_SIZE.
  2060. *
  2061. * An expected usage:
  2062. * ```c
  2063. * __attribute__((noinline)) // inlining can break the stack check
  2064. * void stack_hog(void)
  2065. * {
  2066. * // consume a lot of stack here
  2067. * }
  2068. *
  2069. * void
  2070. * stack_hog_wrapper(exec_env) {
  2071. * // the amount of stack stack_hog would consume,
  2072. * // plus a small margin
  2073. * uint32_t size = 10000000;
  2074. *
  2075. * if (!wasm_runtime_detect_native_stack_overflow_size(exec_env, size)) {
  2076. * // wasm_runtime_detect_native_stack_overflow_size has raised
  2077. * // a trap.
  2078. * return;
  2079. * }
  2080. * stack_hog();
  2081. * }
  2082. * ```
  2083. */
  2084. WASM_RUNTIME_API_EXTERN bool
  2085. wasm_runtime_detect_native_stack_overflow_size(wasm_exec_env_t exec_env,
  2086. uint32_t required_size);
  2087. /**
  2088. * Query whether the wasm binary buffer used to create the module can be freed
  2089. *
  2090. * @param module the target module
  2091. * @return true if the wasm binary buffer can be freed
  2092. */
  2093. WASM_RUNTIME_API_EXTERN bool
  2094. wasm_runtime_is_underlying_binary_freeable(const wasm_module_t module);
  2095. /**
  2096. * Create a shared heap
  2097. *
  2098. * @param init_args the initialization arguments
  2099. * @return the shared heap created
  2100. */
  2101. WASM_RUNTIME_API_EXTERN wasm_shared_heap_t
  2102. wasm_runtime_create_shared_heap(SharedHeapInitArgs *init_args);
  2103. /**
  2104. * This function links two shared heap(lists), `head` and `body` in to a single
  2105. * shared heap list, where `head` becomes the new shared heap list head. The
  2106. * shared heap list remains one continuous shared heap in wasm app's point of
  2107. * view. At most one shared heap in shared heap list can be dynamically
  2108. * allocated, the rest have to be the pre-allocated shared heap. *
  2109. *
  2110. * @param head The head of the shared heap chain.
  2111. * @param body The body of the shared heap chain to be appended.
  2112. * @return The new head of the shared heap chain. NULL if failed.
  2113. */
  2114. WASM_RUNTIME_API_EXTERN wasm_shared_heap_t
  2115. wasm_runtime_chain_shared_heaps(wasm_shared_heap_t head,
  2116. wasm_shared_heap_t body);
  2117. /**
  2118. * This function unchains the shared heaps from the given head. If
  2119. * `entire_chain` is true, it will unchain the entire chain of shared heaps.
  2120. * Otherwise, it will unchain only the first shared heap in the chain.
  2121. *
  2122. * @param head The head of the shared heap chain.
  2123. * @param entire_chain A boolean flag indicating whether to unchain the entire
  2124. * chain.
  2125. * @return The new head of the shared heap chain. Or the last shared heap in the
  2126. * chain if `entire_chain` is true.
  2127. */
  2128. wasm_shared_heap_t
  2129. wasm_runtime_unchain_shared_heaps(wasm_shared_heap_t head, bool entire_chain);
  2130. /**
  2131. * Attach a shared heap, it can be the head of shared heap chain, in that case,
  2132. * attach the shared heap chain, to a module instance
  2133. *
  2134. * @param module_inst the module instance
  2135. * @param shared_heap the shared heap
  2136. * @return true if success, false if failed
  2137. */
  2138. WASM_RUNTIME_API_EXTERN bool
  2139. wasm_runtime_attach_shared_heap(wasm_module_inst_t module_inst,
  2140. wasm_shared_heap_t shared_heap);
  2141. /**
  2142. * Detach a shared heap from a module instance
  2143. *
  2144. * @param module_inst the module instance
  2145. */
  2146. WASM_RUNTIME_API_EXTERN void
  2147. wasm_runtime_detach_shared_heap(wasm_module_inst_t module_inst);
  2148. /**
  2149. * Allocate memory from a shared heap, or the non-preallocated shared heap from
  2150. * the shared heap chain
  2151. *
  2152. * @param module_inst the module instance
  2153. * @param size required memory size
  2154. * @param p_native_addr native address of allocated memory
  2155. *
  2156. * @return return the allocated memory address, which reuses part of the wasm
  2157. * address space and is in the range of [UINT32 - shared_heap_size + 1, UINT32]
  2158. * (when the wasm memory is 32-bit) or [UINT64 - shared_heap_size + 1, UINT64]
  2159. * (when the wasm memory is 64-bit). Note that it is not an absolute address.
  2160. * Return non-zero if success, zero if failed.
  2161. */
  2162. WASM_RUNTIME_API_EXTERN uint64_t
  2163. wasm_runtime_shared_heap_malloc(wasm_module_inst_t module_inst, uint64_t size,
  2164. void **p_native_addr);
  2165. /**
  2166. * Free the memory allocated from shared heap, or the non-preallocated shared
  2167. * heap from the shared heap chain
  2168. *
  2169. * @param module_inst the module instance
  2170. * @param ptr the offset in wasm app
  2171. */
  2172. WASM_RUNTIME_API_EXTERN void
  2173. wasm_runtime_shared_heap_free(wasm_module_inst_t module_inst, uint64_t ptr);
  2174. #ifdef __cplusplus
  2175. }
  2176. #endif
  2177. #endif /* end of _WASM_EXPORT_H */