wasm_export.h 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _WASM_EXPORT_H
  6. #define _WASM_EXPORT_H
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include "lib_export.h"
  10. #ifndef WASM_RUNTIME_API_EXTERN
  11. #if defined(_MSC_BUILD)
  12. #if defined(COMPILING_WASM_RUNTIME_API)
  13. #define WASM_RUNTIME_API_EXTERN __declspec(dllexport)
  14. #else
  15. #define WASM_RUNTIME_API_EXTERN __declspec(dllimport)
  16. #endif
  17. #else
  18. #define WASM_RUNTIME_API_EXTERN
  19. #endif
  20. #endif
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* clang-format off */
  25. #define get_module_inst(exec_env) \
  26. wasm_runtime_get_module_inst(exec_env)
  27. #define validate_app_addr(offset, size) \
  28. wasm_runtime_validate_app_addr(module_inst, offset, size)
  29. #define validate_app_str_addr(offset) \
  30. wasm_runtime_validate_app_str_addr(module_inst, offset)
  31. #define addr_app_to_native(offset) \
  32. wasm_runtime_addr_app_to_native(module_inst, offset)
  33. #define addr_native_to_app(ptr) \
  34. wasm_runtime_addr_native_to_app(module_inst, ptr)
  35. #define module_malloc(size, p_native_addr) \
  36. wasm_runtime_module_malloc(module_inst, size, p_native_addr)
  37. #define module_free(offset) \
  38. wasm_runtime_module_free(module_inst, offset)
  39. #define native_raw_return_type(type, args) type *raw_ret = (type *)(args)
  40. #define native_raw_get_arg(type, name, args) type name = *((type *)(args++))
  41. #define native_raw_set_return(val) *raw_ret = (val)
  42. #ifndef WASM_MODULE_T_DEFINED
  43. #define WASM_MODULE_T_DEFINED
  44. /* Uninstantiated WASM module loaded from WASM binary file
  45. or AoT binary file*/
  46. struct WASMModuleCommon;
  47. typedef struct WASMModuleCommon *wasm_module_t;
  48. #endif
  49. /* Instantiated WASM module */
  50. struct WASMModuleInstanceCommon;
  51. typedef struct WASMModuleInstanceCommon *wasm_module_inst_t;
  52. /* Function instance */
  53. typedef void WASMFunctionInstanceCommon;
  54. typedef WASMFunctionInstanceCommon *wasm_function_inst_t;
  55. /* WASM section */
  56. typedef struct wasm_section_t {
  57. struct wasm_section_t *next;
  58. /* section type */
  59. int section_type;
  60. /* section body, not include type and size */
  61. uint8_t *section_body;
  62. /* section body size */
  63. uint32_t section_body_size;
  64. } wasm_section_t, aot_section_t, *wasm_section_list_t, *aot_section_list_t;
  65. /* Execution environment, e.g. stack info */
  66. struct WASMExecEnv;
  67. typedef struct WASMExecEnv *wasm_exec_env_t;
  68. /* Package Type */
  69. typedef enum {
  70. Wasm_Module_Bytecode = 0,
  71. Wasm_Module_AoT,
  72. Package_Type_Unknown = 0xFFFF
  73. } package_type_t;
  74. #ifndef MEM_ALLOC_OPTION_DEFINED
  75. #define MEM_ALLOC_OPTION_DEFINED
  76. /* Memory allocator type */
  77. typedef enum {
  78. /* pool mode, allocate memory from user defined heap buffer */
  79. Alloc_With_Pool = 0,
  80. /* user allocator mode, allocate memory from user defined
  81. malloc function */
  82. Alloc_With_Allocator,
  83. /* system allocator mode, allocate memory from system allocator,
  84. or, platform's os_malloc function */
  85. Alloc_With_System_Allocator,
  86. } mem_alloc_type_t;
  87. /* Memory allocator option */
  88. typedef union MemAllocOption {
  89. struct {
  90. void *heap_buf;
  91. uint32_t heap_size;
  92. } pool;
  93. struct {
  94. void *malloc_func;
  95. void *realloc_func;
  96. void *free_func;
  97. } allocator;
  98. } MemAllocOption;
  99. #endif
  100. /* Memory pool info */
  101. typedef struct mem_alloc_info_t {
  102. uint32_t total_size;
  103. uint32_t total_free_size;
  104. uint32_t highmark_size;
  105. } mem_alloc_info_t;
  106. /* WASM runtime initialize arguments */
  107. typedef struct RuntimeInitArgs {
  108. mem_alloc_type_t mem_alloc_type;
  109. MemAllocOption mem_alloc_option;
  110. const char *native_module_name;
  111. NativeSymbol *native_symbols;
  112. uint32_t n_native_symbols;
  113. /* maximum thread number, only used when
  114. WASM_ENABLE_THREAD_MGR is defined */
  115. uint32_t max_thread_num;
  116. /* Debug settings, only used when
  117. WASM_ENABLE_DEBUG_INTERP != 0 */
  118. char ip_addr[128];
  119. int unused; /* was platform_port */
  120. int instance_port;
  121. /* Fast JIT code cache size */
  122. uint32_t fast_jit_code_cache_size;
  123. } RuntimeInitArgs;
  124. #ifndef WASM_VALKIND_T_DEFINED
  125. #define WASM_VALKIND_T_DEFINED
  126. typedef uint8_t wasm_valkind_t;
  127. enum wasm_valkind_enum {
  128. WASM_I32,
  129. WASM_I64,
  130. WASM_F32,
  131. WASM_F64,
  132. WASM_ANYREF = 128,
  133. WASM_FUNCREF,
  134. };
  135. #endif
  136. #ifndef WASM_VAL_T_DEFINED
  137. #define WASM_VAL_T_DEFINED
  138. typedef struct wasm_val_t {
  139. wasm_valkind_t kind;
  140. union {
  141. /* also represent a function index */
  142. int32_t i32;
  143. int64_t i64;
  144. float f32;
  145. double f64;
  146. /* represent a foreign object, aka externref in .wat */
  147. uintptr_t foreign;
  148. } of;
  149. } wasm_val_t;
  150. #endif
  151. /**
  152. * Initialize the WASM runtime environment, and also initialize
  153. * the memory allocator with system allocator, which calls os_malloc
  154. * to allocate memory
  155. *
  156. * @return true if success, false otherwise
  157. */
  158. WASM_RUNTIME_API_EXTERN bool
  159. wasm_runtime_init(void);
  160. /**
  161. * Initialize the WASM runtime environment, and also initialize
  162. * the memory allocator and register native symbols, which are specified
  163. * with init arguments
  164. *
  165. * @param init_args specifies the init arguments
  166. *
  167. * @return return true if success, false otherwise
  168. */
  169. WASM_RUNTIME_API_EXTERN bool
  170. wasm_runtime_full_init(RuntimeInitArgs *init_args);
  171. /**
  172. * Destroy the WASM runtime environment.
  173. */
  174. WASM_RUNTIME_API_EXTERN void
  175. wasm_runtime_destroy(void);
  176. /**
  177. * Allocate memory from runtime memory environment.
  178. *
  179. * @param size bytes need to allocate
  180. *
  181. * @return the pointer to memory allocated
  182. */
  183. WASM_RUNTIME_API_EXTERN void *
  184. wasm_runtime_malloc(unsigned int size);
  185. /**
  186. * Reallocate memory from runtime memory environment
  187. *
  188. * @param ptr the original memory
  189. * @param size bytes need to reallocate
  190. *
  191. * @return the pointer to memory reallocated
  192. */
  193. WASM_RUNTIME_API_EXTERN void *
  194. wasm_runtime_realloc(void *ptr, unsigned int size);
  195. /*
  196. * Free memory to runtime memory environment.
  197. */
  198. WASM_RUNTIME_API_EXTERN void
  199. wasm_runtime_free(void *ptr);
  200. /*
  201. * Get memory info, only pool mode is supported now.
  202. */
  203. WASM_RUNTIME_API_EXTERN bool
  204. wasm_runtime_get_mem_alloc_info(mem_alloc_info_t *mem_alloc_info);
  205. /**
  206. * Get the package type of a buffer.
  207. *
  208. * @param buf the package buffer
  209. * @param size the package buffer size
  210. *
  211. * @return the package type, return Package_Type_Unknown if the type is unknown
  212. */
  213. WASM_RUNTIME_API_EXTERN package_type_t
  214. get_package_type(const uint8_t *buf, uint32_t size);
  215. /**
  216. * Check whether a file is an AOT XIP (Execution In Place) file
  217. *
  218. * @param buf the package buffer
  219. * @param size the package buffer size
  220. *
  221. * @return true if success, false otherwise
  222. */
  223. WASM_RUNTIME_API_EXTERN bool
  224. wasm_runtime_is_xip_file(const uint8_t *buf, uint32_t size);
  225. /**
  226. * Callback to load a module file into a buffer in multi-module feature
  227. */
  228. typedef bool (*module_reader)(const char *module_name,
  229. uint8_t **p_buffer, uint32_t *p_size);
  230. /**
  231. * Callback to release the buffer loaded by module_reader callback
  232. */
  233. typedef void (*module_destroyer)(uint8_t *buffer, uint32_t size);
  234. /**
  235. * Setup callbacks for reading and releasing a buffer about a module file
  236. *
  237. * @param reader a callback to read a module file into a buffer
  238. * @param destroyer a callback to release above buffer
  239. */
  240. WASM_RUNTIME_API_EXTERN void
  241. wasm_runtime_set_module_reader(const module_reader reader,
  242. const module_destroyer destroyer);
  243. /**
  244. * Give the "module" a name "module_name".
  245. * Can not assign a new name to a module if it already has a name
  246. *
  247. * @param module_name indicate a name
  248. * @param module the target module
  249. * @param error_buf output of the exception info
  250. * @param error_buf_size the size of the exception string
  251. *
  252. * @return true means success, false means failed
  253. */
  254. WASM_RUNTIME_API_EXTERN bool
  255. wasm_runtime_register_module(const char *module_name, wasm_module_t module,
  256. char *error_buf, uint32_t error_buf_size);
  257. /**
  258. * Check if there is already a loaded module named module_name in the
  259. * runtime. Repeately loading a module with the same name is not allowed.
  260. *
  261. * @param module_name indicate a name
  262. *
  263. * @return return WASM module loaded, NULL if failed
  264. */
  265. WASM_RUNTIME_API_EXTERN wasm_module_t
  266. wasm_runtime_find_module_registered(const char *module_name);
  267. /**
  268. * Load a WASM module from a specified byte buffer. The byte buffer can be
  269. * WASM binary data when interpreter or JIT is enabled, or AOT binary data
  270. * when AOT is enabled. If it is AOT binary data, it must be 4-byte aligned.
  271. *
  272. * Note: In case of AOT XIP modules, the runtime doesn't make modifications
  273. * to the buffer. (Except the "Known issues" mentioned in doc/xip.md.)
  274. * Otherwise, the runtime can make modifications to the buffer for its
  275. * internal purposes. Thus, in general, it isn't safe to create multiple
  276. * modules from a single buffer.
  277. *
  278. * @param buf the byte buffer which contains the WASM/AOT binary data,
  279. * note that the byte buffer must be writable since runtime may
  280. * change its content for footprint and performance purpose, and
  281. * it must be referencable until wasm_runtime_unload is called
  282. * @param size the size of the buffer
  283. * @param error_buf output of the exception info
  284. * @param error_buf_size the size of the exception string
  285. *
  286. * @return return WASM module loaded, NULL if failed
  287. */
  288. WASM_RUNTIME_API_EXTERN wasm_module_t
  289. wasm_runtime_load(uint8_t *buf, uint32_t size,
  290. char *error_buf, uint32_t error_buf_size);
  291. /**
  292. * Load a WASM module from a specified WASM or AOT section list.
  293. *
  294. * @param section_list the section list which contains each section data
  295. * @param is_aot whether the section list is AOT section list
  296. * @param error_buf output of the exception info
  297. * @param error_buf_size the size of the exception string
  298. *
  299. * @return return WASM module loaded, NULL if failed
  300. */
  301. WASM_RUNTIME_API_EXTERN wasm_module_t
  302. wasm_runtime_load_from_sections(wasm_section_list_t section_list, bool is_aot,
  303. char *error_buf, uint32_t error_buf_size);
  304. /**
  305. * Unload a WASM module.
  306. *
  307. * @param module the module to be unloaded
  308. */
  309. WASM_RUNTIME_API_EXTERN void
  310. wasm_runtime_unload(wasm_module_t module);
  311. /**
  312. * Get the module hash of a WASM module, currently only available on
  313. * linux-sgx platform when the remote attestation feature is enabled
  314. *
  315. * @param module the WASM module to retrieve
  316. *
  317. * @return the module hash of the WASM module
  318. */
  319. char *
  320. wasm_runtime_get_module_hash(wasm_module_t module);
  321. /**
  322. * Set WASI parameters.
  323. *
  324. * While this API operates on a module, these parameters will be used
  325. * only when the module is instantiated. That is, you can consider these
  326. * as extra parameters for wasm_runtime_instantiate().
  327. *
  328. * @param module The module to set WASI parameters.
  329. * @param dir_list The list of directories to preopen. (real path)
  330. * @param dir_count The number of elements in dir_list.
  331. * @param map_dir_list The list of directories to preopen. (mapped path)
  332. * @param map_dir_count The number of elements in map_dir_list.
  333. * If map_dir_count is smaller than dir_count,
  334. * mapped path is assumed to be same as the
  335. * corresponding real path for the rest of entries.
  336. * @param env The list of environment variables.
  337. * @param env_count The number of elements in env.
  338. * @param argv The list of command line arguments.
  339. * @param argc The number of elements in argv.
  340. * @param stdinfd The host file descriptor to back WASI STDIN_FILENO.
  341. * If -1 is specified, STDIN_FILENO is used.
  342. * @param stdoutfd The host file descriptor to back WASI STDOUT_FILENO.
  343. * If -1 is specified, STDOUT_FILENO is used.
  344. * @param stderrfd The host file descriptor to back WASI STDERR_FILENO.
  345. * If -1 is specified, STDERR_FILENO is used.
  346. */
  347. WASM_RUNTIME_API_EXTERN void
  348. wasm_runtime_set_wasi_args_ex(wasm_module_t module,
  349. const char *dir_list[], uint32_t dir_count,
  350. const char *map_dir_list[], uint32_t map_dir_count,
  351. const char *env[], uint32_t env_count,
  352. char *argv[], int argc,
  353. int stdinfd, int stdoutfd, int stderrfd);
  354. /**
  355. * Set WASI parameters.
  356. *
  357. * Same as wasm_runtime_set_wasi_args_ex with stdinfd = -1, stdoutfd = -1,
  358. * stderrfd = -1.
  359. */
  360. WASM_RUNTIME_API_EXTERN void
  361. wasm_runtime_set_wasi_args(wasm_module_t module,
  362. const char *dir_list[], uint32_t dir_count,
  363. const char *map_dir_list[], uint32_t map_dir_count,
  364. const char *env[], uint32_t env_count,
  365. char *argv[], int argc);
  366. WASM_RUNTIME_API_EXTERN void
  367. wasm_runtime_set_wasi_addr_pool(wasm_module_t module, const char *addr_pool[],
  368. uint32_t addr_pool_size);
  369. WASM_RUNTIME_API_EXTERN void
  370. wasm_runtime_set_wasi_ns_lookup_pool(wasm_module_t module, const char *ns_lookup_pool[],
  371. uint32_t ns_lookup_pool_size);
  372. /**
  373. * Instantiate a WASM module.
  374. *
  375. * @param module the WASM module to instantiate
  376. * @param stack_size the default stack size of the module instance when the
  377. * exec env's operation stack isn't created by user, e.g. API
  378. * wasm_application_execute_main() and wasm_application_execute_func()
  379. * create the operation stack internally with the stack size specified
  380. * here. And API wasm_runtime_create_exec_env() creates the operation
  381. * stack with stack size specified by its parameter, the stack size
  382. * specified here is ignored.
  383. * @param heap_size the default heap size of the module instance, a heap will
  384. * be created besides the app memory space. Both wasm app and native
  385. * function can allocate memory from the heap.
  386. * @param error_buf buffer to output the error info if failed
  387. * @param error_buf_size the size of the error buffer
  388. *
  389. * @return return the instantiated WASM module instance, NULL if failed
  390. */
  391. WASM_RUNTIME_API_EXTERN wasm_module_inst_t
  392. wasm_runtime_instantiate(const wasm_module_t module,
  393. uint32_t stack_size, uint32_t heap_size,
  394. char *error_buf, uint32_t error_buf_size);
  395. /**
  396. * Deinstantiate a WASM module instance, destroy the resources.
  397. *
  398. * @param module_inst the WASM module instance to destroy
  399. */
  400. WASM_RUNTIME_API_EXTERN void
  401. wasm_runtime_deinstantiate(wasm_module_inst_t module_inst);
  402. /**
  403. * Get WASM module from WASM module instance
  404. *
  405. * @param module_inst the WASM module instance to retrieve
  406. *
  407. * @return the WASM module
  408. */
  409. WASM_RUNTIME_API_EXTERN wasm_module_t
  410. wasm_runtime_get_module(wasm_module_inst_t module_inst);
  411. WASM_RUNTIME_API_EXTERN bool
  412. wasm_runtime_is_wasi_mode(wasm_module_inst_t module_inst);
  413. WASM_RUNTIME_API_EXTERN wasm_function_inst_t
  414. wasm_runtime_lookup_wasi_start_function(wasm_module_inst_t module_inst);
  415. /**
  416. * Get WASI exit code.
  417. *
  418. * After a WASI command completed its execution, an embedder can
  419. * call this function to get its exit code. (that is, the value given
  420. * to proc_exit.)
  421. *
  422. * @param module_inst the module instance
  423. */
  424. WASM_RUNTIME_API_EXTERN uint32_t
  425. wasm_runtime_get_wasi_exit_code(wasm_module_inst_t module_inst);
  426. /**
  427. * Lookup an exported function in the WASM module instance.
  428. *
  429. * @param module_inst the module instance
  430. * @param name the name of the function
  431. * @param signature the signature of the function, ignored currently
  432. *
  433. * @return the function instance found, NULL if not found
  434. */
  435. WASM_RUNTIME_API_EXTERN wasm_function_inst_t
  436. wasm_runtime_lookup_function(wasm_module_inst_t const module_inst,
  437. const char *name, const char *signature);
  438. /**
  439. * Get parameter count of the function instance
  440. *
  441. * @param func_inst the function instance
  442. * @param module_inst the module instance the function instance belongs to
  443. *
  444. * @return the parameter count of the function instance
  445. */
  446. WASM_RUNTIME_API_EXTERN uint32_t
  447. wasm_func_get_param_count(wasm_function_inst_t const func_inst,
  448. wasm_module_inst_t const module_inst);
  449. /**
  450. * Get result count of the function instance
  451. *
  452. * @param func_inst the function instance
  453. * @param module_inst the module instance the function instance belongs to
  454. *
  455. * @return the result count of the function instance
  456. */
  457. WASM_RUNTIME_API_EXTERN uint32_t
  458. wasm_func_get_result_count(wasm_function_inst_t const func_inst,
  459. wasm_module_inst_t const module_inst);
  460. /**
  461. * Get parameter types of the function instance
  462. *
  463. * @param func_inst the function instance
  464. * @param module_inst the module instance the function instance belongs to
  465. * @param param_types the parameter types returned
  466. */
  467. WASM_RUNTIME_API_EXTERN void
  468. wasm_func_get_param_types(wasm_function_inst_t const func_inst,
  469. wasm_module_inst_t const module_inst,
  470. wasm_valkind_t *param_types);
  471. /**
  472. * Get result types of the function instance
  473. *
  474. * @param func_inst the function instance
  475. * @param module_inst the module instance the function instance belongs to
  476. * @param result_types the result types returned
  477. */
  478. WASM_RUNTIME_API_EXTERN void
  479. wasm_func_get_result_types(wasm_function_inst_t const func_inst,
  480. wasm_module_inst_t const module_inst,
  481. wasm_valkind_t *result_types);
  482. /**
  483. * Create execution environment for a WASM module instance.
  484. *
  485. * @param module_inst the module instance
  486. * @param stack_size the stack size to execute a WASM function
  487. *
  488. * @return the execution environment, NULL if failed, e.g. invalid
  489. * stack size is passed
  490. */
  491. WASM_RUNTIME_API_EXTERN wasm_exec_env_t
  492. wasm_runtime_create_exec_env(wasm_module_inst_t module_inst,
  493. uint32_t stack_size);
  494. /**
  495. * Destroy the execution environment.
  496. *
  497. * @param exec_env the execution environment to destroy
  498. */
  499. WASM_RUNTIME_API_EXTERN void
  500. wasm_runtime_destroy_exec_env(wasm_exec_env_t exec_env);
  501. /**
  502. * Get the singleton execution environment for the instance.
  503. *
  504. * Note: The singleton execution environment is the execution
  505. * environment used internally by the runtime for the API functions
  506. * like wasm_application_execute_main, which don't take explicit
  507. * execution environment. It's associated to the corresponding
  508. * module instance and managed by the runtime. The API user should
  509. * not destroy it with wasm_runtime_destroy_exec_env.
  510. *
  511. * @param module_inst the module instance
  512. *
  513. * @return exec_env the execution environment to destroy
  514. */
  515. WASM_RUNTIME_API_EXTERN wasm_exec_env_t
  516. wasm_runtime_get_exec_env_singleton(wasm_module_inst_t module_inst);
  517. /**
  518. * Start debug instance based on given execution environment.
  519. * Note:
  520. * The debug instance will be destroyed during destroying the
  521. * execution environment, developers don't need to destroy it
  522. * manually.
  523. * If the cluster of this execution environment has already
  524. * been bound to a debug instance, this function will return true
  525. * directly.
  526. * If developer spawns some exec_env by wasm_runtime_spawn_exec_env,
  527. * don't need to call this function for every spawned exec_env as
  528. * they are sharing the same cluster with the main exec_env.
  529. *
  530. * @param exec_env the execution environment to start debug instance
  531. * @param port the port for the debug server to listen on.
  532. * 0 means automatic assignment.
  533. * -1 means to use the global setting in RuntimeInitArgs.
  534. *
  535. * @return debug port if success, 0 otherwise.
  536. */
  537. WASM_RUNTIME_API_EXTERN uint32_t
  538. wasm_runtime_start_debug_instance_with_port(wasm_exec_env_t exec_env, int32_t port);
  539. /**
  540. * Same as wasm_runtime_start_debug_instance_with_port(env, -1).
  541. */
  542. WASM_RUNTIME_API_EXTERN uint32_t
  543. wasm_runtime_start_debug_instance(wasm_exec_env_t exec_env);
  544. /**
  545. * Initialize the thread environment.
  546. * Note:
  547. * If developer creates a child thread by himself to call the
  548. * the wasm function in that thread, he should call this API
  549. * firstly before calling the wasm function and then call
  550. * wasm_runtime_destroy_thread_env() after calling the wasm
  551. * function. If the thread is created from the runtime API,
  552. * it is unnecessary to call these two APIs.
  553. *
  554. * @return true if success, false otherwise
  555. */
  556. WASM_RUNTIME_API_EXTERN bool
  557. wasm_runtime_init_thread_env(void);
  558. /**
  559. * Destroy the thread environment
  560. */
  561. WASM_RUNTIME_API_EXTERN void
  562. wasm_runtime_destroy_thread_env(void);
  563. /**
  564. * Whether the thread environment is initialized
  565. */
  566. WASM_RUNTIME_API_EXTERN bool
  567. wasm_runtime_thread_env_inited(void);
  568. /**
  569. * Get WASM module instance from execution environment
  570. *
  571. * @param exec_env the execution environment to retrieve
  572. *
  573. * @return the WASM module instance
  574. */
  575. WASM_RUNTIME_API_EXTERN wasm_module_inst_t
  576. wasm_runtime_get_module_inst(wasm_exec_env_t exec_env);
  577. /**
  578. * Set WASM module instance of execution environment
  579. * Caution:
  580. * normally the module instance is bound with the execution
  581. * environment one by one, if multiple module instances want
  582. * to share to the same execution environment, developer should
  583. * be responsible for the backup and restore of module instance
  584. *
  585. * @param exec_env the execution environment
  586. * @param module_inst the WASM module instance to set
  587. */
  588. WASM_RUNTIME_API_EXTERN void
  589. wasm_runtime_set_module_inst(wasm_exec_env_t exec_env,
  590. const wasm_module_inst_t module_inst);
  591. /**
  592. * Call the given WASM function of a WASM module instance with
  593. * arguments (bytecode and AoT).
  594. *
  595. * @param exec_env the execution environment to call the function,
  596. * which must be created from wasm_create_exec_env()
  597. * @param function the function to call
  598. * @param argc total cell number that the function parameters occupy,
  599. * a cell is a slot of the uint32 array argv[], e.g. i32/f32 argument
  600. * occupies one cell, i64/f64 argument occupies two cells, note that
  601. * it might be different from the parameter number of the function
  602. * @param argv the arguments. If the function has return value,
  603. * the first (or first two in case 64-bit return value) element of
  604. * argv stores the return value of the called WASM function after this
  605. * function returns.
  606. *
  607. * @return true if success, false otherwise and exception will be thrown,
  608. * the caller can call wasm_runtime_get_exception to get the exception
  609. * info.
  610. */
  611. WASM_RUNTIME_API_EXTERN bool
  612. wasm_runtime_call_wasm(wasm_exec_env_t exec_env,
  613. wasm_function_inst_t function,
  614. uint32_t argc, uint32_t argv[]);
  615. /**
  616. * Call the given WASM function of a WASM module instance with
  617. * provided results space and arguments (bytecode and AoT).
  618. *
  619. * @param exec_env the execution environment to call the function,
  620. * which must be created from wasm_create_exec_env()
  621. * @param function the function to call
  622. * @param num_results the number of results
  623. * @param results the pre-alloced pointer to get the results
  624. * @param num_args the number of arguments
  625. * @param args the arguments
  626. *
  627. * @return true if success, false otherwise and exception will be thrown,
  628. * the caller can call wasm_runtime_get_exception to get the exception
  629. * info.
  630. */
  631. WASM_RUNTIME_API_EXTERN bool
  632. wasm_runtime_call_wasm_a(wasm_exec_env_t exec_env,
  633. wasm_function_inst_t function,
  634. uint32_t num_results, wasm_val_t results[],
  635. uint32_t num_args, wasm_val_t *args);
  636. /**
  637. * Call the given WASM function of a WASM module instance with
  638. * provided results space and variant arguments (bytecode and AoT).
  639. *
  640. * @param exec_env the execution environment to call the function,
  641. * which must be created from wasm_create_exec_env()
  642. * @param function the function to call
  643. * @param num_results the number of results
  644. * @param results the pre-alloced pointer to get the results
  645. * @param num_args the number of arguments
  646. * @param ... the variant arguments
  647. *
  648. * @return true if success, false otherwise and exception will be thrown,
  649. * the caller can call wasm_runtime_get_exception to get the exception
  650. * info.
  651. */
  652. WASM_RUNTIME_API_EXTERN bool
  653. wasm_runtime_call_wasm_v(wasm_exec_env_t exec_env,
  654. wasm_function_inst_t function,
  655. uint32_t num_results, wasm_val_t results[],
  656. uint32_t num_args, ...);
  657. /**
  658. * Find the unique main function from a WASM module instance
  659. * and execute that function.
  660. *
  661. * @param module_inst the WASM module instance
  662. * @param argc the number of arguments
  663. * @param argv the arguments array, if the main function has return value,
  664. * *(int*)argv stores the return value of the called main function after
  665. * this function returns.
  666. *
  667. * @return true if the main function is called, false otherwise and exception
  668. * will be thrown, the caller can call wasm_runtime_get_exception to get
  669. * the exception info.
  670. */
  671. WASM_RUNTIME_API_EXTERN bool
  672. wasm_application_execute_main(wasm_module_inst_t module_inst,
  673. int32_t argc, char *argv[]);
  674. /**
  675. * Find the specified function in argv[0] from a WASM module instance
  676. * and execute that function.
  677. *
  678. * @param module_inst the WASM module instance
  679. * @param name the name of the function to execute.
  680. * to indicate the module name via: $module_name$function_name
  681. * or just a function name: function_name
  682. * @param argc the number of arguments
  683. * @param argv the arguments array
  684. *
  685. * @return true if the specified function is called, false otherwise and
  686. * exception will be thrown, the caller can call wasm_runtime_get_exception
  687. * to get the exception info.
  688. */
  689. WASM_RUNTIME_API_EXTERN bool
  690. wasm_application_execute_func(wasm_module_inst_t module_inst,
  691. const char *name, int32_t argc, char *argv[]);
  692. /**
  693. * Get exception info of the WASM module instance.
  694. *
  695. * @param module_inst the WASM module instance
  696. *
  697. * @return the exception string
  698. */
  699. WASM_RUNTIME_API_EXTERN const char *
  700. wasm_runtime_get_exception(wasm_module_inst_t module_inst);
  701. /**
  702. * Set exception info of the WASM module instance.
  703. *
  704. * @param module_inst the WASM module instance
  705. *
  706. * @param exception the exception string
  707. */
  708. WASM_RUNTIME_API_EXTERN void
  709. wasm_runtime_set_exception(wasm_module_inst_t module_inst,
  710. const char *exception);
  711. /**
  712. * Clear exception info of the WASM module instance.
  713. *
  714. * @param module_inst the WASM module instance
  715. */
  716. WASM_RUNTIME_API_EXTERN void
  717. wasm_runtime_clear_exception(wasm_module_inst_t module_inst);
  718. /**
  719. * Set custom data to WASM module instance.
  720. * Note:
  721. * If WAMR_BUILD_LIB_PTHREAD is enabled, this API
  722. * will spread the custom data to all threads
  723. *
  724. * @param module_inst the WASM module instance
  725. * @param custom_data the custom data to be set
  726. */
  727. WASM_RUNTIME_API_EXTERN void
  728. wasm_runtime_set_custom_data(wasm_module_inst_t module_inst,
  729. void *custom_data);
  730. /**
  731. * Get the custom data within a WASM module instance.
  732. *
  733. * @param module_inst the WASM module instance
  734. *
  735. * @return the custom data (NULL if not set yet)
  736. */
  737. WASM_RUNTIME_API_EXTERN void *
  738. wasm_runtime_get_custom_data(wasm_module_inst_t module_inst);
  739. /**
  740. * Allocate memory from the heap of WASM module instance
  741. *
  742. * Note: wasm_runtime_module_malloc can call heap functions inside
  743. * the module instance and thus cause a memory growth.
  744. * This API needs to be used very carefully when you have a native
  745. * pointers to the module instance memory obtained with
  746. * wasm_runtime_addr_app_to_native or similar APIs.
  747. *
  748. * @param module_inst the WASM module instance which contains heap
  749. * @param size the size bytes to allocate
  750. * @param p_native_addr return native address of the allocated memory
  751. * if it is not NULL, and return NULL if memory malloc failed
  752. *
  753. * @return the allocated memory address, which is a relative offset to the
  754. * base address of the module instance's memory space. Note that
  755. * it is not an absolute address.
  756. * Return non-zero if success, zero if failed.
  757. */
  758. WASM_RUNTIME_API_EXTERN uint32_t
  759. wasm_runtime_module_malloc(wasm_module_inst_t module_inst, uint32_t size,
  760. void **p_native_addr);
  761. /**
  762. * Free memory to the heap of WASM module instance
  763. *
  764. * @param module_inst the WASM module instance which contains heap
  765. * @param ptr the pointer to free
  766. */
  767. WASM_RUNTIME_API_EXTERN void
  768. wasm_runtime_module_free(wasm_module_inst_t module_inst, uint32_t ptr);
  769. /**
  770. * Allocate memory from the heap of WASM module instance and initialize
  771. * the memory with src
  772. *
  773. * @param module_inst the WASM module instance which contains heap
  774. * @param src the source data to copy
  775. * @param size the size of the source data
  776. *
  777. * @return the allocated memory address, which is a relative offset to the
  778. * base address of the module instance's memory space. Note that
  779. * it is not an absolute address.
  780. * Return non-zero if success, zero if failed.
  781. */
  782. WASM_RUNTIME_API_EXTERN uint32_t
  783. wasm_runtime_module_dup_data(wasm_module_inst_t module_inst,
  784. const char *src, uint32_t size);
  785. /**
  786. * Validate the app address, check whether it belongs to WASM module
  787. * instance's address space, or in its heap space or memory space.
  788. *
  789. * @param module_inst the WASM module instance
  790. * @param app_offset the app address to validate, which is a relative address
  791. * @param size the size bytes of the app address
  792. *
  793. * @return true if success, false otherwise. If failed, an exception will
  794. * be thrown.
  795. */
  796. WASM_RUNTIME_API_EXTERN bool
  797. wasm_runtime_validate_app_addr(wasm_module_inst_t module_inst,
  798. uint32_t app_offset, uint32_t size);
  799. /**
  800. * Similar to wasm_runtime_validate_app_addr(), except that the size parameter
  801. * is not provided. This function validates the app string address, check
  802. * whether it belongs to WASM module instance's address space, or in its heap
  803. * space or memory space. Moreover, it checks whether it is the offset of a
  804. * string that is end with '\0'.
  805. *
  806. * Note: The validation result, especially the NUL termination check,
  807. * is not reliable for a module instance with multiple threads because
  808. * other threads can modify the heap behind us.
  809. *
  810. * @param module_inst the WASM module instance
  811. * @param app_str_offset the app address of the string to validate, which is a
  812. * relative address
  813. *
  814. * @return true if success, false otherwise. If failed, an exception will
  815. * be thrown.
  816. */
  817. WASM_RUNTIME_API_EXTERN bool
  818. wasm_runtime_validate_app_str_addr(wasm_module_inst_t module_inst,
  819. uint32_t app_str_offset);
  820. /**
  821. * Validate the native address, check whether it belongs to WASM module
  822. * instance's address space, or in its heap space or memory space.
  823. *
  824. * @param module_inst the WASM module instance
  825. * @param native_ptr the native address to validate, which is an absolute
  826. * address
  827. * @param size the size bytes of the app address
  828. *
  829. * @return true if success, false otherwise. If failed, an exception will
  830. * be thrown.
  831. */
  832. WASM_RUNTIME_API_EXTERN bool
  833. wasm_runtime_validate_native_addr(wasm_module_inst_t module_inst,
  834. void *native_ptr, uint32_t size);
  835. /**
  836. * Convert app address(relative address) to native address(absolute address)
  837. *
  838. * Note that native addresses to module instance memory can be invalidated
  839. * on a memory growth. (Except shared memory, whose native addresses are
  840. * stable.)
  841. *
  842. * @param module_inst the WASM module instance
  843. * @param app_offset the app adress
  844. *
  845. * @return the native address converted
  846. */
  847. WASM_RUNTIME_API_EXTERN void *
  848. wasm_runtime_addr_app_to_native(wasm_module_inst_t module_inst,
  849. uint32_t app_offset);
  850. /**
  851. * Convert native address(absolute address) to app address(relative address)
  852. *
  853. * @param module_inst the WASM module instance
  854. * @param native_ptr the native address
  855. *
  856. * @return the app address converted
  857. */
  858. WASM_RUNTIME_API_EXTERN uint32_t
  859. wasm_runtime_addr_native_to_app(wasm_module_inst_t module_inst,
  860. void *native_ptr);
  861. /**
  862. * Get the app address range (relative address) that a app address belongs to
  863. *
  864. * @param module_inst the WASM module instance
  865. * @param app_offset the app address to retrieve
  866. * @param p_app_start_offset buffer to output the app start offset if not NULL
  867. * @param p_app_end_offset buffer to output the app end offset if not NULL
  868. *
  869. * @return true if success, false otherwise.
  870. */
  871. WASM_RUNTIME_API_EXTERN bool
  872. wasm_runtime_get_app_addr_range(wasm_module_inst_t module_inst,
  873. uint32_t app_offset,
  874. uint32_t *p_app_start_offset,
  875. uint32_t *p_app_end_offset);
  876. /**
  877. * Get the native address range (absolute address) that a native address
  878. * belongs to
  879. *
  880. * @param module_inst the WASM module instance
  881. * @param native_ptr the native address to retrieve
  882. * @param p_native_start_addr buffer to output the native start address
  883. * if not NULL
  884. * @param p_native_end_addr buffer to output the native end address
  885. * if not NULL
  886. *
  887. * @return true if success, false otherwise.
  888. */
  889. WASM_RUNTIME_API_EXTERN bool
  890. wasm_runtime_get_native_addr_range(wasm_module_inst_t module_inst,
  891. uint8_t *native_ptr,
  892. uint8_t **p_native_start_addr,
  893. uint8_t **p_native_end_addr);
  894. /**
  895. * Register native functions with same module name
  896. *
  897. * Note: The array `native_symbols` should not be read-only because the
  898. * library can modify it in-place.
  899. *
  900. * Note: After successful call of this function, the array `native_symbols`
  901. * is owned by the library.
  902. *
  903. * @param module_name the module name of the native functions
  904. * @param native_symbols specifies an array of NativeSymbol structures which
  905. * contain the names, function pointers and signatures
  906. * Note: WASM runtime will not allocate memory to clone the data, so
  907. * user must ensure the array can be used forever
  908. * Meanings of letters in function signature:
  909. * 'i': the parameter is i32 type
  910. * 'I': the parameter is i64 type
  911. * 'f': the parameter is f32 type
  912. * 'F': the parameter is f64 type
  913. * 'r': the parameter is externref type, it should be a uintptr_t in host
  914. * '*': the parameter is a pointer (i32 in WASM), and runtime will
  915. * auto check its boundary before calling the native function.
  916. * If it is followed by '~', the checked length of the pointer
  917. * is gotten from the following parameter, if not, the checked
  918. * length of the pointer is 1.
  919. * '~': the parameter is the pointer's length with i32 type, and must
  920. * follow after '*'
  921. * '$': the parameter is a string (i32 in WASM), and runtime will
  922. * auto check its boundary before calling the native function
  923. * @param n_native_symbols specifies the number of native symbols in the array
  924. *
  925. * @return true if success, false otherwise
  926. */
  927. WASM_RUNTIME_API_EXTERN bool
  928. wasm_runtime_register_natives(const char *module_name,
  929. NativeSymbol *native_symbols,
  930. uint32_t n_native_symbols);
  931. /**
  932. * Register native functions with same module name, similar to
  933. * wasm_runtime_register_natives, the difference is that runtime passes raw
  934. * arguments to native API, which means that the native API should be defined as
  935. * void foo(wasm_exec_env_t exec_env, uint64 *args);
  936. * and native API should extract arguments one by one from args array with macro
  937. * native_raw_get_arg
  938. * and write the return value back to args[0] with macro
  939. * native_raw_return_type and native_raw_set_return
  940. */
  941. WASM_RUNTIME_API_EXTERN bool
  942. wasm_runtime_register_natives_raw(const char *module_name,
  943. NativeSymbol *native_symbols,
  944. uint32_t n_native_symbols);
  945. /**
  946. * Undo wasm_runtime_register_natives or wasm_runtime_register_natives_raw
  947. *
  948. * @param module_name Should be the same as the corresponding
  949. * wasm_runtime_register_natives.
  950. * (Same in term of strcmp.)
  951. *
  952. * @param native_symbols Should be the same as the corresponding
  953. * wasm_runtime_register_natives.
  954. * (Same in term of pointer comparison.)
  955. *
  956. * @return true if success, false otherwise
  957. */
  958. WASM_RUNTIME_API_EXTERN bool
  959. wasm_runtime_unregister_natives(const char *module_name,
  960. NativeSymbol *native_symbols);
  961. /**
  962. * Get attachment of native function from execution environment
  963. *
  964. * @param exec_env the execution environment to retrieve
  965. *
  966. * @return the attachment of native function
  967. */
  968. WASM_RUNTIME_API_EXTERN void *
  969. wasm_runtime_get_function_attachment(wasm_exec_env_t exec_env);
  970. /**
  971. * Set user data to execution environment.
  972. *
  973. * @param exec_env the execution environment
  974. * @param user_data the user data to be set
  975. */
  976. WASM_RUNTIME_API_EXTERN void
  977. wasm_runtime_set_user_data(wasm_exec_env_t exec_env, void *user_data);
  978. /**
  979. * Get the user data within execution environment.
  980. *
  981. * @param exec_env the execution environment
  982. *
  983. * @return the user data (NULL if not set yet)
  984. */
  985. WASM_RUNTIME_API_EXTERN void *
  986. wasm_runtime_get_user_data(wasm_exec_env_t exec_env);
  987. /**
  988. * Dump runtime memory consumption, including:
  989. * Exec env memory consumption
  990. * WASM module memory consumption
  991. * WASM module instance memory consumption
  992. * stack and app heap used info
  993. *
  994. * @param exec_env the execution environment
  995. */
  996. WASM_RUNTIME_API_EXTERN void
  997. wasm_runtime_dump_mem_consumption(wasm_exec_env_t exec_env);
  998. /**
  999. * Dump runtime performance profiler data of each function
  1000. *
  1001. * @param module_inst the WASM module instance to profile
  1002. */
  1003. WASM_RUNTIME_API_EXTERN void
  1004. wasm_runtime_dump_perf_profiling(wasm_module_inst_t module_inst);
  1005. /* wasm thread callback function type */
  1006. typedef void *(*wasm_thread_callback_t)(wasm_exec_env_t, void *);
  1007. /* wasm thread type */
  1008. typedef uintptr_t wasm_thread_t;
  1009. /**
  1010. * Set the max thread num per cluster.
  1011. *
  1012. * @param num maximum thread num
  1013. */
  1014. WASM_RUNTIME_API_EXTERN void
  1015. wasm_runtime_set_max_thread_num(uint32_t num);
  1016. /**
  1017. * Spawn a new exec_env, the spawned exec_env
  1018. * can be used in other threads
  1019. *
  1020. * @param num the original exec_env
  1021. *
  1022. * @return the spawned exec_env if success, NULL otherwise
  1023. */
  1024. WASM_RUNTIME_API_EXTERN wasm_exec_env_t
  1025. wasm_runtime_spawn_exec_env(wasm_exec_env_t exec_env);
  1026. /**
  1027. * Destroy the spawned exec_env
  1028. *
  1029. * @param exec_env the spawned exec_env
  1030. */
  1031. WASM_RUNTIME_API_EXTERN void
  1032. wasm_runtime_destroy_spawned_exec_env(wasm_exec_env_t exec_env);
  1033. /**
  1034. * Spawn a thread from the given exec_env
  1035. *
  1036. * @param exec_env the original exec_env
  1037. * @param tid thread id to be returned to the caller
  1038. * @param callback the callback function provided by the user
  1039. * @param arg the arguments passed to the callback
  1040. *
  1041. * @return 0 if success, -1 otherwise
  1042. */
  1043. WASM_RUNTIME_API_EXTERN int32_t
  1044. wasm_runtime_spawn_thread(wasm_exec_env_t exec_env, wasm_thread_t *tid,
  1045. wasm_thread_callback_t callback, void *arg);
  1046. /**
  1047. * Wait a spawned thread to terminate
  1048. *
  1049. * @param tid thread id
  1050. * @param retval if not NULL, output the return value of the thread
  1051. *
  1052. * @return 0 if success, error number otherwise
  1053. */
  1054. WASM_RUNTIME_API_EXTERN int32_t
  1055. wasm_runtime_join_thread(wasm_thread_t tid, void **retval);
  1056. /**
  1057. * Map external object to an internal externref index: if the index
  1058. * has been created, return it, otherwise create the index.
  1059. *
  1060. * @param module_inst the WASM module instance that the extern object
  1061. * belongs to
  1062. * @param extern_obj the external object to be mapped
  1063. * @param p_externref_idx return externref index of the external object
  1064. *
  1065. * @return true if success, false otherwise
  1066. */
  1067. WASM_RUNTIME_API_EXTERN bool
  1068. wasm_externref_obj2ref(wasm_module_inst_t module_inst,
  1069. void *extern_obj, uint32_t *p_externref_idx);
  1070. /**
  1071. * Retrieve the external object from an internal externref index
  1072. *
  1073. * @param externref_idx the externref index to retrieve
  1074. * @param p_extern_obj return the mapped external object of
  1075. * the externref index
  1076. *
  1077. * @return true if success, false otherwise
  1078. */
  1079. WASM_RUNTIME_API_EXTERN bool
  1080. wasm_externref_ref2obj(uint32_t externref_idx, void **p_extern_obj);
  1081. /**
  1082. * Retain an extern object which is mapped to the internal externref
  1083. * so that the object won't be cleaned during extern object reclaim
  1084. * if it isn't used.
  1085. *
  1086. * @param externref_idx the externref index of an external object
  1087. * to retain
  1088. * @return true if success, false otherwise
  1089. */
  1090. WASM_RUNTIME_API_EXTERN bool
  1091. wasm_externref_retain(uint32_t externref_idx);
  1092. /**
  1093. * Dump the call stack to stdout
  1094. *
  1095. * @param exec_env the execution environment
  1096. */
  1097. WASM_RUNTIME_API_EXTERN void
  1098. wasm_runtime_dump_call_stack(wasm_exec_env_t exec_env);
  1099. /**
  1100. * Get the size required to store the call stack contents, including
  1101. * the space for terminating null byte ('\0')
  1102. *
  1103. * @param exec_env the execution environment
  1104. *
  1105. * @return size required to store the contents, 0 means error
  1106. */
  1107. WASM_RUNTIME_API_EXTERN uint32_t
  1108. wasm_runtime_get_call_stack_buf_size(wasm_exec_env_t exec_env);
  1109. /**
  1110. * Dump the call stack to buffer.
  1111. *
  1112. * @note this function is not thread-safe, please only use this API
  1113. * when the exec_env is not executing
  1114. *
  1115. * @param exec_env the execution environment
  1116. * @param buf buffer to store the dumped content
  1117. * @param len length of the buffer
  1118. *
  1119. * @return bytes dumped to the buffer, including the terminating null
  1120. * byte ('\0'), 0 means error and data in buf may be invalid
  1121. */
  1122. WASM_RUNTIME_API_EXTERN uint32_t
  1123. wasm_runtime_dump_call_stack_to_buf(wasm_exec_env_t exec_env, char *buf,
  1124. uint32_t len);
  1125. /**
  1126. * Get a custom section by name
  1127. *
  1128. * @param module_comm the module to find
  1129. * @param name name of the custom section
  1130. * @param len return the length of the content if found
  1131. *
  1132. * @return Custom section content (not including the name length
  1133. * and name string) if found, NULL otherwise
  1134. */
  1135. WASM_RUNTIME_API_EXTERN const uint8_t *
  1136. wasm_runtime_get_custom_section(wasm_module_t const module_comm,
  1137. const char *name, uint32_t *len);
  1138. /**
  1139. * Get WAMR semantic version
  1140. */
  1141. WASM_RUNTIME_API_EXTERN void
  1142. wasm_runtime_get_version(uint32_t *major, uint32_t *minor, uint32_t *patch);
  1143. /* clang-format on */
  1144. #ifdef __cplusplus
  1145. }
  1146. #endif
  1147. #endif /* end of _WASM_EXPORT_H */