wasm_export.h 42 KB

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