13 #ifndef _WASM_EXPORT_H
14 #define _WASM_EXPORT_H
20 #ifndef WASM_RUNTIME_API_EXTERN
21 #if defined(_MSC_BUILD)
22 #if defined(COMPILING_WASM_RUNTIME_API)
23 #define WASM_RUNTIME_API_EXTERN __declspec(dllexport)
25 #define WASM_RUNTIME_API_EXTERN __declspec(dllimport)
28 #define WASM_RUNTIME_API_EXTERN
38 #define get_module_inst(exec_env) \
39 wasm_runtime_get_module_inst(exec_env)
41 #define validate_app_addr(offset, size) \
42 wasm_runtime_validate_app_addr(module_inst, offset, size)
44 #define validate_app_str_addr(offset) \
45 wasm_runtime_validate_app_str_addr(module_inst, offset)
47 #define addr_app_to_native(offset) \
48 wasm_runtime_addr_app_to_native(module_inst, offset)
50 #define addr_native_to_app(ptr) \
51 wasm_runtime_addr_native_to_app(module_inst, ptr)
53 #define module_malloc(size, p_native_addr) \
54 wasm_runtime_module_malloc(module_inst, size, p_native_addr)
56 #define module_free(offset) \
57 wasm_runtime_module_free(module_inst, offset)
59 #define native_raw_return_type(type, args) type *raw_ret = (type *)(args)
61 #define native_raw_get_arg(type, name, args) type name = *((type *)(args++))
63 #define native_raw_set_return(val) *raw_ret = (val)
65 #ifndef WASM_MODULE_T_DEFINED
66 #define WASM_MODULE_T_DEFINED
69 struct WASMModuleCommon;
70 typedef struct WASMModuleCommon *wasm_module_t;
74 struct WASMModuleInstanceCommon;
75 typedef struct WASMModuleInstanceCommon *wasm_module_inst_t;
78 typedef void WASMFunctionInstanceCommon;
79 typedef WASMFunctionInstanceCommon *wasm_function_inst_t;
87 uint8_t *section_body;
89 uint32_t section_body_size;
94 typedef struct WASMExecEnv *wasm_exec_env_t;
98 Wasm_Module_Bytecode = 0,
100 Package_Type_Unknown = 0xFFFF
103 #ifndef MEM_ALLOC_OPTION_DEFINED
104 #define MEM_ALLOC_OPTION_DEFINED
111 Alloc_With_Allocator,
114 Alloc_With_System_Allocator,
137 uint32_t total_free_size;
138 uint32_t highmark_size;
142 typedef enum RunningMode {
151 mem_alloc_type_t mem_alloc_type;
154 const char *native_module_name;
156 uint32_t n_native_symbols;
160 uint32_t max_thread_num;
169 uint32_t fast_jit_code_cache_size;
172 uint32_t gc_heap_size;
175 RunningMode running_mode;
178 uint32_t llvm_jit_opt_level;
179 uint32_t llvm_jit_size_level;
181 uint32_t segue_flags;
193 #ifndef INSTANTIATION_ARGS_OPTION_DEFINED
194 #define INSTANTIATION_ARGS_OPTION_DEFINED
197 uint32_t default_stack_size;
198 uint32_t host_managed_heap_size;
199 uint32_t max_memory_pages;
203 #ifndef WASM_VALKIND_T_DEFINED
204 #define WASM_VALKIND_T_DEFINED
205 typedef uint8_t wasm_valkind_t;
206 enum wasm_valkind_enum {
216 #ifndef WASM_VAL_T_DEFINED
217 #define WASM_VAL_T_DEFINED
222 uint8_t __paddings[7];
231 struct wasm_ref_t *ref;
237 WASM_LOG_LEVEL_FATAL = 0,
238 WASM_LOG_LEVEL_ERROR = 1,
239 WASM_LOG_LEVEL_WARNING = 2,
240 WASM_LOG_LEVEL_DEBUG = 3,
241 WASM_LOG_LEVEL_VERBOSE = 4
251 WASM_RUNTIME_API_EXTERN
bool
263 WASM_RUNTIME_API_EXTERN
bool
271 WASM_RUNTIME_API_EXTERN
void
281 WASM_RUNTIME_API_EXTERN
bool
293 WASM_RUNTIME_API_EXTERN
bool
299 WASM_RUNTIME_API_EXTERN
void
309 WASM_RUNTIME_API_EXTERN
void *
320 WASM_RUNTIME_API_EXTERN
void *
326 WASM_RUNTIME_API_EXTERN
void
327 wasm_runtime_free(
void *ptr);
332 WASM_RUNTIME_API_EXTERN
bool
343 WASM_RUNTIME_API_EXTERN package_type_t
354 WASM_RUNTIME_API_EXTERN
bool
361 const char *module_name,
362 uint8_t **p_buffer, uint32_t *p_size);
375 WASM_RUNTIME_API_EXTERN
void
389 WASM_RUNTIME_API_EXTERN
bool
391 char *error_buf, uint32_t error_buf_size);
401 WASM_RUNTIME_API_EXTERN wasm_module_t
425 WASM_RUNTIME_API_EXTERN wasm_module_t
427 char *error_buf, uint32_t error_buf_size);
439 WASM_RUNTIME_API_EXTERN wasm_module_t
441 char *error_buf, uint32_t error_buf_size);
448 WASM_RUNTIME_API_EXTERN
void
495 WASM_RUNTIME_API_EXTERN
void
497 const char *dir_list[], uint32_t dir_count,
498 const char *map_dir_list[], uint32_t map_dir_count,
499 const char *env[], uint32_t env_count,
500 char *argv[],
int argc, int64_t stdinfd,
501 int64_t stdoutfd, int64_t stderrfd);
508 WASM_RUNTIME_API_EXTERN
void
510 const char *dir_list[], uint32_t dir_count,
511 const char *map_dir_list[], uint32_t map_dir_count,
512 const char *env[], uint32_t env_count,
513 char *argv[],
int argc);
515 WASM_RUNTIME_API_EXTERN
void
516 wasm_runtime_set_wasi_addr_pool(wasm_module_t module,
const char *addr_pool[],
517 uint32_t addr_pool_size);
519 WASM_RUNTIME_API_EXTERN
void
520 wasm_runtime_set_wasi_ns_lookup_pool(wasm_module_t module,
const char *ns_lookup_pool[],
521 uint32_t ns_lookup_pool_size);
542 WASM_RUNTIME_API_EXTERN wasm_module_inst_t
544 uint32_t default_stack_size, uint32_t host_managed_heap_size,
545 char *error_buf, uint32_t error_buf_size);
552 WASM_RUNTIME_API_EXTERN wasm_module_inst_t
555 char *error_buf, uint32_t error_buf_size);
568 WASM_RUNTIME_API_EXTERN
bool
570 RunningMode running_mode);
582 WASM_RUNTIME_API_EXTERN RunningMode
590 WASM_RUNTIME_API_EXTERN
void
600 WASM_RUNTIME_API_EXTERN wasm_module_t
603 WASM_RUNTIME_API_EXTERN
bool
604 wasm_runtime_is_wasi_mode(wasm_module_inst_t module_inst);
606 WASM_RUNTIME_API_EXTERN wasm_function_inst_t
607 wasm_runtime_lookup_wasi_start_function(wasm_module_inst_t module_inst);
618 WASM_RUNTIME_API_EXTERN uint32_t
629 WASM_RUNTIME_API_EXTERN wasm_function_inst_t
641 WASM_RUNTIME_API_EXTERN uint32_t
643 wasm_module_inst_t
const module_inst);
653 WASM_RUNTIME_API_EXTERN uint32_t
655 wasm_module_inst_t
const module_inst);
664 WASM_RUNTIME_API_EXTERN
void
666 wasm_module_inst_t
const module_inst,
667 wasm_valkind_t *param_types);
676 WASM_RUNTIME_API_EXTERN
void
678 wasm_module_inst_t
const module_inst,
679 wasm_valkind_t *result_types);
690 WASM_RUNTIME_API_EXTERN wasm_exec_env_t
692 uint32_t stack_size);
699 WASM_RUNTIME_API_EXTERN
void
716 WASM_RUNTIME_API_EXTERN wasm_exec_env_t
739 WASM_RUNTIME_API_EXTERN uint32_t
745 WASM_RUNTIME_API_EXTERN uint32_t
760 WASM_RUNTIME_API_EXTERN
bool
766 WASM_RUNTIME_API_EXTERN
void
772 WASM_RUNTIME_API_EXTERN
bool
782 WASM_RUNTIME_API_EXTERN wasm_module_inst_t
796 WASM_RUNTIME_API_EXTERN
void
798 const wasm_module_inst_t module_inst);
820 WASM_RUNTIME_API_EXTERN
bool
822 wasm_function_inst_t
function,
823 uint32_t argc, uint32_t argv[]);
841 WASM_RUNTIME_API_EXTERN
bool
843 wasm_function_inst_t
function,
863 WASM_RUNTIME_API_EXTERN
bool
865 wasm_function_inst_t
function,
867 uint32_t num_args, ...);
890 WASM_RUNTIME_API_EXTERN
bool
892 uint32_t argc, uint32_t argv[]);
908 WASM_RUNTIME_API_EXTERN
bool
910 int32_t argc,
char *argv[]);
927 WASM_RUNTIME_API_EXTERN
bool
929 const char *name, int32_t argc,
char *argv[]);
938 WASM_RUNTIME_API_EXTERN
const char *
948 WASM_RUNTIME_API_EXTERN
void
950 const char *exception);
957 WASM_RUNTIME_API_EXTERN
void
975 WASM_RUNTIME_API_EXTERN
void
987 WASM_RUNTIME_API_EXTERN
void
998 WASM_RUNTIME_API_EXTERN
void *
1007 WASM_RUNTIME_API_EXTERN
void
1017 WASM_RUNTIME_API_EXTERN
bool
1019 wasm_module_inst_t module_inst);
1040 WASM_RUNTIME_API_EXTERN uint64_t
1042 void **p_native_addr);
1050 WASM_RUNTIME_API_EXTERN
void
1066 WASM_RUNTIME_API_EXTERN uint64_t
1068 const char *src, uint64_t size);
1081 WASM_RUNTIME_API_EXTERN
bool
1083 uint64_t app_offset, uint64_t size);
1103 WASM_RUNTIME_API_EXTERN
bool
1105 uint64_t app_str_offset);
1119 WASM_RUNTIME_API_EXTERN
bool
1121 void *native_ptr, uint64_t size);
1135 WASM_RUNTIME_API_EXTERN
void *
1137 uint64_t app_offset);
1147 WASM_RUNTIME_API_EXTERN uint64_t
1161 WASM_RUNTIME_API_EXTERN
bool
1163 uint64_t app_offset,
1164 uint64_t *p_app_start_offset,
1165 uint64_t *p_app_end_offset);
1180 WASM_RUNTIME_API_EXTERN
bool
1182 uint8_t *native_ptr,
1183 uint8_t **p_native_start_addr,
1184 uint8_t **p_native_end_addr);
1219 WASM_RUNTIME_API_EXTERN
bool
1222 uint32_t n_native_symbols);
1234 WASM_RUNTIME_API_EXTERN
bool
1237 uint32_t n_native_symbols);
1253 WASM_RUNTIME_API_EXTERN
bool
1264 WASM_RUNTIME_API_EXTERN
void *
1273 WASM_RUNTIME_API_EXTERN
void
1283 WASM_RUNTIME_API_EXTERN
void *
1295 WASM_RUNTIME_API_EXTERN
void
1303 WASM_RUNTIME_API_EXTERN
void
1311 WASM_RUNTIME_API_EXTERN
double
1322 WASM_RUNTIME_API_EXTERN
double
1324 const char *func_name);
1327 typedef void *(*wasm_thread_callback_t)(wasm_exec_env_t,
void *);
1329 typedef uintptr_t wasm_thread_t;
1336 WASM_RUNTIME_API_EXTERN
void
1347 WASM_RUNTIME_API_EXTERN wasm_exec_env_t
1355 WASM_RUNTIME_API_EXTERN
void
1368 WASM_RUNTIME_API_EXTERN int32_t
1370 wasm_thread_callback_t callback,
void *arg);
1380 WASM_RUNTIME_API_EXTERN int32_t
1394 WASM_RUNTIME_API_EXTERN
bool
1396 void *extern_obj, uint32_t *p_externref_idx);
1407 WASM_RUNTIME_API_EXTERN
bool
1421 WASM_RUNTIME_API_EXTERN
bool
1423 void (*extern_obj_cleanup)(
void *));
1434 WASM_RUNTIME_API_EXTERN
bool
1446 WASM_RUNTIME_API_EXTERN
bool
1454 WASM_RUNTIME_API_EXTERN
void
1465 WASM_RUNTIME_API_EXTERN uint32_t
1481 WASM_RUNTIME_API_EXTERN uint32_t
1492 WASM_RUNTIME_API_EXTERN uint32_t
1505 WASM_RUNTIME_API_EXTERN uint32_t
1507 char *buf, uint32_t len);
1519 WASM_RUNTIME_API_EXTERN
const uint8_t *
1521 const char *name, uint32_t *len);
1527 WASM_RUNTIME_API_EXTERN
void
1534 WASM_RUNTIME_API_EXTERN
bool
1536 const char *func_name);
1542 WASM_RUNTIME_API_EXTERN
bool
1544 const char *global_name);
1549 } enlarge_memory_error_reason_t;
1551 typedef void (*enlarge_memory_error_callback_t)(
1552 uint32_t inc_page_count, uint64_t current_memory_size,
1553 uint32_t memory_index, enlarge_memory_error_reason_t failure_reason,
1554 wasm_module_inst_t instance, wasm_exec_env_t exec_env,
1560 WASM_RUNTIME_API_EXTERN
void
1562 const enlarge_memory_error_callback_t callback,
void *user_data);
1616 WASM_RUNTIME_API_EXTERN
void *
1617 wasm_runtime_create_context_key(
1618 void (*dtor)(wasm_module_inst_t inst,
void *ctx));
1620 WASM_RUNTIME_API_EXTERN
void
1621 wasm_runtime_destroy_context_key(
void *key);
1623 WASM_RUNTIME_API_EXTERN
void
1624 wasm_runtime_set_context(wasm_module_inst_t inst,
void *key,
void *ctx);
1626 WASM_RUNTIME_API_EXTERN
void
1627 wasm_runtime_set_context_spread(wasm_module_inst_t inst,
void *key,
void *ctx);
1629 WASM_RUNTIME_API_EXTERN
void *
1630 wasm_runtime_get_context(wasm_module_inst_t inst,
void *key);
1673 WASM_RUNTIME_API_EXTERN
bool
1674 wasm_runtime_begin_blocking_op(wasm_exec_env_t exec_env);
1676 WASM_RUNTIME_API_EXTERN
void
1677 wasm_runtime_end_blocking_op(wasm_exec_env_t exec_env);
1680 WASM_RUNTIME_API_EXTERN
bool
1681 wasm_runtime_set_module_name(wasm_module_t module,
const char *name,
1682 char *error_buf, uint32_t error_buf_size);
1685 WASM_RUNTIME_API_EXTERN
const char*
1686 wasm_runtime_get_module_name(wasm_module_t module);