Add additional WAMR header for clangd to find

This commit is contained in:
2026-07-26 18:08:43 +02:00
parent 8c9cc08de0
commit 167c3a1290
2 changed files with 323 additions and 314 deletions
+59
View File
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
/**
* @file lib_export.h
*
*/
#ifndef _LIB_EXPORT_H_
#define _LIB_EXPORT_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct NativeSymbol {
const char *symbol;
void *func_ptr;
const char *signature;
/* attachment which can be retrieved in native API by
calling wasm_runtime_get_function_attachment(exec_env) */
void *attachment;
} NativeSymbol;
/* clang-format off */
#define EXPORT_WASM_API(symbol) \
{ #symbol, (void *)symbol, NULL, NULL }
#define EXPORT_WASM_API2(symbol) \
{ #symbol, (void *)symbol##_wrapper, NULL, NULL }
#define EXPORT_WASM_API_WITH_SIG(symbol, signature) \
{ #symbol, (void *)symbol, signature, NULL }
#define EXPORT_WASM_API_WITH_SIG2(symbol, signature) \
{ #symbol, (void *)symbol##_wrapper, signature, NULL }
#define EXPORT_WASM_API_WITH_ATT(symbol, signature, attachment) \
{ #symbol, (void *)symbol, signature, attachment }
#define EXPORT_WASM_API_WITH_ATT2(symbol, signature, attachment) \
{ #symbol, (void *)symbol##_wrapper, signature, attachment }
/* clang-format on */
/**
* Get the exported APIs of base lib
*
* @param p_base_lib_apis return the exported API array of base lib
*
* @return the number of the exported API
*/
uint32_t get_base_lib_export_apis(NativeSymbol **p_base_lib_apis);
#ifdef __cplusplus
}
#endif
#endif /* end of _LIB_EXPORT_H_ */
+264 -314
View File
@@ -12,9 +12,9 @@
#ifndef _WASM_EXPORT_H
#define _WASM_EXPORT_H
#include <stdint.h>
#include <stdbool.h>
#include "lib_export.h"
#include <stdbool.h>
#include <stdint.h>
#ifndef WASM_RUNTIME_API_EXTERN
#if defined(_MSC_BUILD)
@@ -36,20 +36,20 @@ extern "C" {
#define get_module_inst(exec_env) wasm_runtime_get_module_inst(exec_env)
#define validate_app_addr(offset, size) \
wasm_runtime_validate_app_addr(module_inst, offset, size)
#define validate_app_addr(offset, size) \
wasm_runtime_validate_app_addr(module_inst, offset, size)
#define validate_app_str_addr(offset) \
wasm_runtime_validate_app_str_addr(module_inst, offset)
#define validate_app_str_addr(offset) \
wasm_runtime_validate_app_str_addr(module_inst, offset)
#define addr_app_to_native(offset) \
wasm_runtime_addr_app_to_native(module_inst, offset)
#define addr_app_to_native(offset) \
wasm_runtime_addr_app_to_native(module_inst, offset)
#define addr_native_to_app(ptr) \
wasm_runtime_addr_native_to_app(module_inst, ptr)
#define addr_native_to_app(ptr) \
wasm_runtime_addr_native_to_app(module_inst, ptr)
#define module_malloc(size, p_native_addr) \
wasm_runtime_module_malloc(module_inst, size, p_native_addr)
#define module_malloc(size, p_native_addr) \
wasm_runtime_module_malloc(module_inst, size, p_native_addr)
#define module_free(offset) wasm_runtime_module_free(module_inst, offset)
@@ -68,10 +68,10 @@ typedef struct WASMModuleCommon *wasm_module_t;
#endif
typedef enum {
WASM_IMPORT_EXPORT_KIND_FUNC,
WASM_IMPORT_EXPORT_KIND_TABLE,
WASM_IMPORT_EXPORT_KIND_MEMORY,
WASM_IMPORT_EXPORT_KIND_GLOBAL
WASM_IMPORT_EXPORT_KIND_FUNC,
WASM_IMPORT_EXPORT_KIND_TABLE,
WASM_IMPORT_EXPORT_KIND_MEMORY,
WASM_IMPORT_EXPORT_KIND_GLOBAL
} wasm_import_export_kind_t;
struct WASMFuncType;
@@ -91,27 +91,27 @@ typedef struct WASMMemory WASMMemoryType;
typedef WASMMemoryType *wasm_memory_type_t;
typedef struct wasm_import_t {
const char *module_name;
const char *name;
wasm_import_export_kind_t kind;
bool linked;
union {
wasm_func_type_t func_type;
wasm_table_type_t table_type;
wasm_global_type_t global_type;
wasm_memory_type_t memory_type;
} u;
const char *module_name;
const char *name;
wasm_import_export_kind_t kind;
bool linked;
union {
wasm_func_type_t func_type;
wasm_table_type_t table_type;
wasm_global_type_t global_type;
wasm_memory_type_t memory_type;
} u;
} wasm_import_t;
typedef struct wasm_export_t {
const char *name;
wasm_import_export_kind_t kind;
union {
wasm_func_type_t func_type;
wasm_table_type_t table_type;
wasm_global_type_t global_type;
wasm_memory_type_t memory_type;
} u;
const char *name;
wasm_import_export_kind_t kind;
union {
wasm_func_type_t func_type;
wasm_table_type_t table_type;
wasm_global_type_t global_type;
wasm_memory_type_t memory_type;
} u;
} wasm_export_t;
/* Instantiated WASM module */
@@ -127,27 +127,27 @@ struct WASMMemoryInstance;
typedef struct WASMMemoryInstance *wasm_memory_inst_t;
typedef struct wasm_frame_t {
/* wasm_instance_t */
void *instance;
uint32_t module_offset;
uint32_t func_index;
uint32_t func_offset;
const char *func_name_wp;
/* wasm_instance_t */
void *instance;
uint32_t module_offset;
uint32_t func_index;
uint32_t func_offset;
const char *func_name_wp;
uint32_t *sp;
uint8_t *frame_ref;
uint32_t *lp;
uint32_t *sp;
uint8_t *frame_ref;
uint32_t *lp;
} WASMCApiFrame;
/* WASM section */
typedef struct wasm_section_t {
struct wasm_section_t *next;
/* section type */
int section_type;
/* section body, not include type and size */
uint8_t *section_body;
/* section body size */
uint32_t section_body_size;
struct wasm_section_t *next;
/* section type */
int section_type;
/* section body, not include type and size */
uint8_t *section_body;
/* section body size */
uint32_t section_body_size;
} wasm_section_t, aot_section_t, *wasm_section_list_t, *aot_section_list_t;
/* Execution environment, e.g. stack info */
@@ -159,123 +159,123 @@ typedef struct WASMSharedHeap *wasm_shared_heap_t;
/* Package Type */
typedef enum {
Wasm_Module_Bytecode = 0,
Wasm_Module_AoT,
Package_Type_Unknown = 0xFFFF
Wasm_Module_Bytecode = 0,
Wasm_Module_AoT,
Package_Type_Unknown = 0xFFFF
} package_type_t;
#ifndef MEM_ALLOC_OPTION_DEFINED
#define MEM_ALLOC_OPTION_DEFINED
/* Memory allocator type */
typedef enum {
/* pool mode, allocate memory from user defined heap buffer */
Alloc_With_Pool = 0,
/* user allocator mode, allocate memory from user defined
malloc function */
Alloc_With_Allocator,
/* system allocator mode, allocate memory from system allocator,
or, platform's os_malloc function */
Alloc_With_System_Allocator,
/* pool mode, allocate memory from user defined heap buffer */
Alloc_With_Pool = 0,
/* user allocator mode, allocate memory from user defined
malloc function */
Alloc_With_Allocator,
/* system allocator mode, allocate memory from system allocator,
or, platform's os_malloc function */
Alloc_With_System_Allocator,
} mem_alloc_type_t;
typedef enum { Alloc_For_Runtime, Alloc_For_LinearMemory } mem_alloc_usage_t;
/* Memory allocator option */
typedef union MemAllocOption {
struct {
void *heap_buf;
uint32_t heap_size;
} pool;
struct {
/* the function signature is varied when
WASM_MEM_ALLOC_WITH_USER_DATA and
WASM_MEM_ALLOC_WITH_USAGE are defined */
void *malloc_func;
void *realloc_func;
void *free_func;
/* allocator user data, only used when
WASM_MEM_ALLOC_WITH_USER_DATA is defined */
void *user_data;
} allocator;
struct {
void *heap_buf;
uint32_t heap_size;
} pool;
struct {
/* the function signature is varied when
WASM_MEM_ALLOC_WITH_USER_DATA and
WASM_MEM_ALLOC_WITH_USAGE are defined */
void *malloc_func;
void *realloc_func;
void *free_func;
/* allocator user data, only used when
WASM_MEM_ALLOC_WITH_USER_DATA is defined */
void *user_data;
} allocator;
} MemAllocOption;
#endif
/* Memory pool info */
typedef struct mem_alloc_info_t {
uint32_t total_size;
uint32_t total_free_size;
uint32_t highmark_size;
uint32_t total_size;
uint32_t total_free_size;
uint32_t highmark_size;
} mem_alloc_info_t;
/* Running mode of runtime and module instance*/
typedef enum RunningMode {
Mode_Interp = 1,
Mode_Fast_JIT,
Mode_LLVM_JIT,
Mode_Multi_Tier_JIT,
Mode_Interp = 1,
Mode_Fast_JIT,
Mode_LLVM_JIT,
Mode_Multi_Tier_JIT,
} RunningMode;
/* WASM runtime initialize arguments */
typedef struct RuntimeInitArgs {
mem_alloc_type_t mem_alloc_type;
MemAllocOption mem_alloc_option;
mem_alloc_type_t mem_alloc_type;
MemAllocOption mem_alloc_option;
const char *native_module_name;
NativeSymbol *native_symbols;
uint32_t n_native_symbols;
const char *native_module_name;
NativeSymbol *native_symbols;
uint32_t n_native_symbols;
/* maximum thread number, only used when
WASM_ENABLE_THREAD_MGR is defined */
uint32_t max_thread_num;
/* maximum thread number, only used when
WASM_ENABLE_THREAD_MGR is defined */
uint32_t max_thread_num;
/* Debug settings, only used when
WASM_ENABLE_DEBUG_INTERP != 0 */
char ip_addr[128];
int unused; /* was platform_port */
int instance_port;
/* Debug settings, only used when
WASM_ENABLE_DEBUG_INTERP != 0 */
char ip_addr[128];
int unused; /* was platform_port */
int instance_port;
/* Fast JIT code cache size */
uint32_t fast_jit_code_cache_size;
/* Fast JIT code cache size */
uint32_t fast_jit_code_cache_size;
/* Default GC heap size */
uint32_t gc_heap_size;
/* Default GC heap size */
uint32_t gc_heap_size;
/* Default running mode of the runtime */
RunningMode running_mode;
/* Default running mode of the runtime */
RunningMode running_mode;
/* LLVM JIT opt and size level */
uint32_t llvm_jit_opt_level;
uint32_t llvm_jit_size_level;
/* Segue optimization flags for LLVM JIT */
uint32_t segue_flags;
/**
* If enabled
* - llvm-jit will output a jitdump file for `perf inject`
* - aot will output a perf-${pid}.map for `perf record`
* - fast-jit. TBD
* - multi-tier-jit. TBD
* - interpreter. TBD
*/
bool enable_linux_perf;
/* LLVM JIT opt and size level */
uint32_t llvm_jit_opt_level;
uint32_t llvm_jit_size_level;
/* Segue optimization flags for LLVM JIT */
uint32_t segue_flags;
/**
* If enabled
* - llvm-jit will output a jitdump file for `perf inject`
* - aot will output a perf-${pid}.map for `perf record`
* - fast-jit. TBD
* - multi-tier-jit. TBD
* - interpreter. TBD
*/
bool enable_linux_perf;
} RuntimeInitArgs;
#ifndef LOAD_ARGS_OPTION_DEFINED
#define LOAD_ARGS_OPTION_DEFINED
typedef struct LoadArgs {
char *name;
/* This option is only used by the Wasm C API (see wasm_c_api.h) */
bool clone_wasm_binary;
/* False by default, used by AOT/wasm loader only.
If true, the AOT/wasm loader creates a copy of some module fields (e.g.
const strings), making it possible to free the wasm binary buffer after
loading. */
bool wasm_binary_freeable;
char *name;
/* This option is only used by the Wasm C API (see wasm_c_api.h) */
bool clone_wasm_binary;
/* False by default, used by AOT/wasm loader only.
If true, the AOT/wasm loader creates a copy of some module fields (e.g.
const strings), making it possible to free the wasm binary buffer after
loading. */
bool wasm_binary_freeable;
/* false by default, if true, don't resolve the symbols yet. The
wasm_runtime_load_ex has to be followed by a wasm_runtime_resolve_symbols
call */
bool no_resolve;
/* TODO: more fields? */
/* false by default, if true, don't resolve the symbols yet. The
wasm_runtime_load_ex has to be followed by a wasm_runtime_resolve_symbols
call */
bool no_resolve;
/* TODO: more fields? */
} LoadArgs;
#endif /* LOAD_ARGS_OPTION_DEFINED */
@@ -283,9 +283,9 @@ typedef struct LoadArgs {
#define INSTANTIATION_ARGS_OPTION_DEFINED
/* WASM module instantiation arguments */
typedef struct InstantiationArgs {
uint32_t default_stack_size;
uint32_t host_managed_heap_size;
uint32_t max_memory_pages;
uint32_t default_stack_size;
uint32_t host_managed_heap_size;
uint32_t max_memory_pages;
} InstantiationArgs;
#endif /* INSTANTIATION_ARGS_OPTION_DEFINED */
@@ -295,13 +295,13 @@ struct InstantiationArgs2;
#define WASM_VALKIND_T_DEFINED
typedef uint8_t wasm_valkind_t;
enum wasm_valkind_enum {
WASM_I32,
WASM_I64,
WASM_F32,
WASM_F64,
WASM_V128,
WASM_EXTERNREF = 128,
WASM_FUNCREF,
WASM_I32,
WASM_I64,
WASM_F32,
WASM_F64,
WASM_V128,
WASM_EXTERNREF = 128,
WASM_FUNCREF,
};
#endif
@@ -310,48 +310,48 @@ enum wasm_valkind_enum {
struct wasm_ref_t;
typedef struct wasm_val_t {
wasm_valkind_t kind;
uint8_t _paddings[7];
union {
/* also represent a function index */
int32_t i32;
int64_t i64;
float f32;
double f64;
/* represent a foreign object, aka externref in .wat */
uintptr_t foreign;
struct wasm_ref_t *ref;
} of;
wasm_valkind_t kind;
uint8_t _paddings[7];
union {
/* also represent a function index */
int32_t i32;
int64_t i64;
float f32;
double f64;
/* represent a foreign object, aka externref in .wat */
uintptr_t foreign;
struct wasm_ref_t *ref;
} of;
} wasm_val_t;
#endif
/* Global instance*/
typedef struct wasm_global_inst_t {
wasm_valkind_t kind;
bool is_mutable;
void *global_data;
wasm_valkind_t kind;
bool is_mutable;
void *global_data;
} wasm_global_inst_t;
/* Table instance*/
typedef struct wasm_table_inst_t {
wasm_valkind_t elem_kind;
uint32_t cur_size;
uint32_t max_size;
/* represents the elements of the table, for internal use only */
void *elems;
wasm_valkind_t elem_kind;
uint32_t cur_size;
uint32_t max_size;
/* represents the elements of the table, for internal use only */
void *elems;
} wasm_table_inst_t;
typedef enum {
WASM_LOG_LEVEL_FATAL = 0,
WASM_LOG_LEVEL_ERROR = 1,
WASM_LOG_LEVEL_WARNING = 2,
WASM_LOG_LEVEL_DEBUG = 3,
WASM_LOG_LEVEL_VERBOSE = 4
WASM_LOG_LEVEL_FATAL = 0,
WASM_LOG_LEVEL_ERROR = 1,
WASM_LOG_LEVEL_WARNING = 2,
WASM_LOG_LEVEL_DEBUG = 3,
WASM_LOG_LEVEL_VERBOSE = 4
} log_level_t;
typedef struct SharedHeapInitArgs {
uint32_t size;
void *pre_allocated_addr;
uint32_t size;
void *pre_allocated_addr;
} SharedHeapInitArgs;
/**
@@ -361,8 +361,7 @@ typedef struct SharedHeapInitArgs {
*
* @return true if success, false otherwise
*/
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_init(void);
WASM_RUNTIME_API_EXTERN bool wasm_runtime_init(void);
/**
* Initialize the WASM runtime environment, WASM running mode,
@@ -373,16 +372,14 @@ wasm_runtime_init(void);
*
* @return return true if success, false otherwise
*/
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_full_init(RuntimeInitArgs *init_args);
WASM_RUNTIME_API_EXTERN bool wasm_runtime_full_init(RuntimeInitArgs *init_args);
/**
* Set the log level. To be called after the runtime is initialized.
*
* @param level the log level to set
*/
WASM_RUNTIME_API_EXTERN void
wasm_runtime_set_log_level(log_level_t level);
WASM_RUNTIME_API_EXTERN void wasm_runtime_set_log_level(log_level_t level);
/**
* Query whether a certain running mode is supported for the runtime
@@ -409,8 +406,7 @@ wasm_runtime_set_default_running_mode(RunningMode running_mode);
/**
* Destroy the WASM runtime environment.
*/
WASM_RUNTIME_API_EXTERN void
wasm_runtime_destroy(void);
WASM_RUNTIME_API_EXTERN void wasm_runtime_destroy(void);
/**
* Allocate memory from runtime memory environment.
@@ -419,8 +415,7 @@ wasm_runtime_destroy(void);
*
* @return the pointer to memory allocated
*/
WASM_RUNTIME_API_EXTERN void *
wasm_runtime_malloc(unsigned int size);
WASM_RUNTIME_API_EXTERN void *wasm_runtime_malloc(unsigned int size);
/**
* Reallocate memory from runtime memory environment
@@ -430,14 +425,13 @@ wasm_runtime_malloc(unsigned int size);
*
* @return the pointer to memory reallocated
*/
WASM_RUNTIME_API_EXTERN void *
wasm_runtime_realloc(void *ptr, unsigned int size);
WASM_RUNTIME_API_EXTERN void *wasm_runtime_realloc(void *ptr,
unsigned int size);
/*
* Free memory to runtime memory environment.
*/
WASM_RUNTIME_API_EXTERN void
wasm_runtime_free(void *ptr);
WASM_RUNTIME_API_EXTERN void wasm_runtime_free(void *ptr);
/*
* Get memory info, only pool mode is supported now.
@@ -453,8 +447,8 @@ wasm_runtime_get_mem_alloc_info(mem_alloc_info_t *mem_alloc_info);
*
* @return the package type, return Package_Type_Unknown if the type is unknown
*/
WASM_RUNTIME_API_EXTERN package_type_t
get_package_type(const uint8_t *buf, uint32_t size);
WASM_RUNTIME_API_EXTERN package_type_t get_package_type(const uint8_t *buf,
uint32_t size);
/**
* Get the package type of a buffer (same as get_package_type).
@@ -517,8 +511,8 @@ wasm_runtime_get_current_package_version(package_type_t package_type);
*
* @return true if success, false otherwise
*/
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_is_xip_file(const uint8_t *buf, uint32_t size);
WASM_RUNTIME_API_EXTERN bool wasm_runtime_is_xip_file(const uint8_t *buf,
uint32_t size);
/**
* Callback to load a module file into a buffer in multi-module feature
@@ -588,9 +582,8 @@ wasm_runtime_find_module_registered(const char *module_name);
*
* @return return WASM module loaded, NULL if failed
*/
WASM_RUNTIME_API_EXTERN wasm_module_t
wasm_runtime_load(uint8_t *buf, uint32_t size, char *error_buf,
uint32_t error_buf_size);
WASM_RUNTIME_API_EXTERN wasm_module_t wasm_runtime_load(
uint8_t *buf, uint32_t size, char *error_buf, uint32_t error_buf_size);
/**
* Load a WASM module with specified load argument.
@@ -603,8 +596,7 @@ wasm_runtime_load_ex(uint8_t *buf, uint32_t size, const LoadArgs *args,
* Resolve symbols for a previously loaded WASM module. Only useful when the
* module was loaded with LoadArgs::no_resolve set to true
*/
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_resolve_symbols(wasm_module_t module);
WASM_RUNTIME_API_EXTERN bool wasm_runtime_resolve_symbols(wasm_module_t module);
/**
* Load a WASM module from a specified WASM or AOT section list.
*
@@ -624,8 +616,7 @@ wasm_runtime_load_from_sections(wasm_section_list_t section_list, bool is_aot,
*
* @param module the module to be unloaded
*/
WASM_RUNTIME_API_EXTERN void
wasm_runtime_unload(wasm_module_t module);
WASM_RUNTIME_API_EXTERN void wasm_runtime_unload(wasm_module_t module);
/**
* Get the module hash of a WASM module, currently only available on
@@ -635,8 +626,7 @@ wasm_runtime_unload(wasm_module_t module);
*
* @return the module hash of the WASM module
*/
char *
wasm_runtime_get_module_hash(wasm_module_t module);
char *wasm_runtime_get_module_hash(wasm_module_t module);
/**
* Set WASI parameters.
@@ -671,13 +661,11 @@ wasm_runtime_get_module_hash(wasm_module_t module);
* INVALID_HANDLE_VALUE on Windows), the platform default
* for STDERR is used.
*/
WASM_RUNTIME_API_EXTERN void
wasm_runtime_set_wasi_args_ex(wasm_module_t module, const char *dir_list[],
uint32_t dir_count, const char *map_dir_list[],
uint32_t map_dir_count, const char *env[],
uint32_t env_count, char *argv[], int argc,
int64_t stdinfd, int64_t stdoutfd,
int64_t stderrfd);
WASM_RUNTIME_API_EXTERN void wasm_runtime_set_wasi_args_ex(
wasm_module_t module, const char *dir_list[], uint32_t dir_count,
const char *map_dir_list[], uint32_t map_dir_count, const char *env[],
uint32_t env_count, char *argv[], int argc, int64_t stdinfd,
int64_t stdoutfd, int64_t stderrfd);
/**
* Set WASI parameters.
@@ -718,11 +706,9 @@ wasm_runtime_set_wasi_ns_lookup_pool(wasm_module_t module,
*
* @return return the instantiated WASM module instance, NULL if failed
*/
WASM_RUNTIME_API_EXTERN wasm_module_inst_t
wasm_runtime_instantiate(const wasm_module_t module,
uint32_t default_stack_size,
uint32_t host_managed_heap_size, char *error_buf,
uint32_t error_buf_size);
WASM_RUNTIME_API_EXTERN wasm_module_inst_t wasm_runtime_instantiate(
const wasm_module_t module, uint32_t default_stack_size,
uint32_t host_managed_heap_size, char *error_buf, uint32_t error_buf_size);
/**
* Instantiate a WASM module, with specified instantiation arguments
@@ -730,10 +716,9 @@ wasm_runtime_instantiate(const wasm_module_t module,
* Same as wasm_runtime_instantiate, but it also allows overwriting maximum
* memory
*/
WASM_RUNTIME_API_EXTERN wasm_module_inst_t
wasm_runtime_instantiate_ex(const wasm_module_t module,
const InstantiationArgs *args, char *error_buf,
uint32_t error_buf_size);
WASM_RUNTIME_API_EXTERN wasm_module_inst_t wasm_runtime_instantiate_ex(
const wasm_module_t module, const InstantiationArgs *args, char *error_buf,
uint32_t error_buf_size);
/**
* Create an InstantiationArgs2 object with default parameters.
@@ -768,23 +753,16 @@ WASM_RUNTIME_API_EXTERN void
wasm_runtime_instantiation_args_set_wasi_arg(struct InstantiationArgs2 *p,
char *argv[], int argc);
WASM_RUNTIME_API_EXTERN void
wasm_runtime_instantiation_args_set_wasi_env(struct InstantiationArgs2 *p,
const char *env[],
uint32_t env_count);
WASM_RUNTIME_API_EXTERN void wasm_runtime_instantiation_args_set_wasi_env(
struct InstantiationArgs2 *p, const char *env[], uint32_t env_count);
WASM_RUNTIME_API_EXTERN void
wasm_runtime_instantiation_args_set_wasi_dir(struct InstantiationArgs2 *p,
const char *dir_list[],
uint32_t dir_count,
const char *map_dir_list[],
uint32_t map_dir_count);
WASM_RUNTIME_API_EXTERN void wasm_runtime_instantiation_args_set_wasi_dir(
struct InstantiationArgs2 *p, const char *dir_list[], uint32_t dir_count,
const char *map_dir_list[], uint32_t map_dir_count);
WASM_RUNTIME_API_EXTERN void
wasm_runtime_instantiation_args_set_wasi_stdio(struct InstantiationArgs2 *p,
int64_t stdinfd,
int64_t stdoutfd,
int64_t stderrfd);
WASM_RUNTIME_API_EXTERN void wasm_runtime_instantiation_args_set_wasi_stdio(
struct InstantiationArgs2 *p, int64_t stdinfd, int64_t stdoutfd,
int64_t stderrfd);
WASM_RUNTIME_API_EXTERN void
wasm_runtime_instantiation_args_set_wasi_addr_pool(struct InstantiationArgs2 *p,
@@ -802,10 +780,9 @@ wasm_runtime_instantiation_args_set_wasi_ns_lookup_pool(
* Same as wasm_runtime_instantiate_ex, but this version takes
* InstantiationArgs2, which can be extended without breaking the ABI.
*/
WASM_RUNTIME_API_EXTERN wasm_module_inst_t
wasm_runtime_instantiate_ex2(const wasm_module_t module,
const struct InstantiationArgs2 *args,
char *error_buf, uint32_t error_buf_size);
WASM_RUNTIME_API_EXTERN wasm_module_inst_t wasm_runtime_instantiate_ex2(
const wasm_module_t module, const struct InstantiationArgs2 *args,
char *error_buf, uint32_t error_buf_size);
/**
* Set the running mode of a WASM module instance, override the
@@ -879,9 +856,8 @@ wasm_runtime_get_wasi_exit_code(wasm_module_inst_t module_inst);
*
* @return the function instance found, NULL if not found
*/
WASM_RUNTIME_API_EXTERN wasm_function_inst_t
wasm_runtime_lookup_function(const wasm_module_inst_t module_inst,
const char *name);
WASM_RUNTIME_API_EXTERN wasm_function_inst_t wasm_runtime_lookup_function(
const wasm_module_inst_t module_inst, const char *name);
/**
* Get parameter count of the function instance
@@ -891,9 +867,8 @@ wasm_runtime_lookup_function(const wasm_module_inst_t module_inst,
*
* @return the parameter count of the function instance
*/
WASM_RUNTIME_API_EXTERN uint32_t
wasm_func_get_param_count(const wasm_function_inst_t func_inst,
const wasm_module_inst_t module_inst);
WASM_RUNTIME_API_EXTERN uint32_t wasm_func_get_param_count(
const wasm_function_inst_t func_inst, const wasm_module_inst_t module_inst);
/**
* Get result count of the function instance
@@ -903,9 +878,8 @@ wasm_func_get_param_count(const wasm_function_inst_t func_inst,
*
* @return the result count of the function instance
*/
WASM_RUNTIME_API_EXTERN uint32_t
wasm_func_get_result_count(const wasm_function_inst_t func_inst,
const wasm_module_inst_t module_inst);
WASM_RUNTIME_API_EXTERN uint32_t wasm_func_get_result_count(
const wasm_function_inst_t func_inst, const wasm_module_inst_t module_inst);
/**
* Get parameter types of the function instance
@@ -940,9 +914,8 @@ wasm_func_get_result_types(const wasm_function_inst_t func_inst,
* @return the execution environment, NULL if failed, e.g. invalid
* stack size is passed
*/
WASM_RUNTIME_API_EXTERN wasm_exec_env_t
wasm_runtime_create_exec_env(wasm_module_inst_t module_inst,
uint32_t stack_size);
WASM_RUNTIME_API_EXTERN wasm_exec_env_t wasm_runtime_create_exec_env(
wasm_module_inst_t module_inst, uint32_t stack_size);
/**
* Destroy the execution environment.
@@ -1018,9 +991,8 @@ wasm_runtime_get_exec_env_singleton(wasm_module_inst_t module_inst);
*
* @return debug port if success, 0 otherwise.
*/
WASM_RUNTIME_API_EXTERN uint32_t
wasm_runtime_start_debug_instance_with_port(wasm_exec_env_t exec_env,
int32_t port);
WASM_RUNTIME_API_EXTERN uint32_t wasm_runtime_start_debug_instance_with_port(
wasm_exec_env_t exec_env, int32_t port);
/**
* Same as wasm_runtime_start_debug_instance_with_port(env, -1).
@@ -1040,20 +1012,17 @@ wasm_runtime_start_debug_instance(wasm_exec_env_t exec_env);
*
* @return true if success, false otherwise
*/
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_init_thread_env(void);
WASM_RUNTIME_API_EXTERN bool wasm_runtime_init_thread_env(void);
/**
* Destroy the thread environment
*/
WASM_RUNTIME_API_EXTERN void
wasm_runtime_destroy_thread_env(void);
WASM_RUNTIME_API_EXTERN void wasm_runtime_destroy_thread_env(void);
/**
* Whether the thread environment is initialized
*/
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_thread_env_inited(void);
WASM_RUNTIME_API_EXTERN bool wasm_runtime_thread_env_inited(void);
/**
* Get WASM module instance from execution environment
@@ -1088,9 +1057,8 @@ wasm_runtime_set_module_inst(wasm_exec_env_t exec_env,
*
* @return The memory instance if found, NULL otherwise
*/
WASM_RUNTIME_API_EXTERN wasm_memory_inst_t
wasm_runtime_lookup_memory(const wasm_module_inst_t module_inst,
const char *name);
WASM_RUNTIME_API_EXTERN wasm_memory_inst_t wasm_runtime_lookup_memory(
const wasm_module_inst_t module_inst, const char *name);
/**
* @brief Get the default memory instance
@@ -1171,8 +1139,8 @@ wasm_memory_get_base_address(const wasm_memory_inst_t memory_inst);
*
* @return True if successful, false otherwise
*/
WASM_RUNTIME_API_EXTERN bool
wasm_memory_enlarge(wasm_memory_inst_t memory_inst, uint64_t inc_page_count);
WASM_RUNTIME_API_EXTERN bool wasm_memory_enlarge(wasm_memory_inst_t memory_inst,
uint64_t inc_page_count);
/**
* Call the given WASM function of a WASM module instance with
@@ -1409,9 +1377,8 @@ wasm_runtime_is_bounds_checks_enabled(wasm_module_inst_t module_inst);
* it is not an absolute address.
* Return non-zero if success, zero if failed.
*/
WASM_RUNTIME_API_EXTERN uint64_t
wasm_runtime_module_malloc(wasm_module_inst_t module_inst, uint64_t size,
void **p_native_addr);
WASM_RUNTIME_API_EXTERN uint64_t wasm_runtime_module_malloc(
wasm_module_inst_t module_inst, uint64_t size, void **p_native_addr);
/**
* Free memory to the heap of WASM module instance
@@ -1435,9 +1402,8 @@ wasm_runtime_module_free(wasm_module_inst_t module_inst, uint64_t ptr);
* it is not an absolute address.
* Return non-zero if success, zero if failed.
*/
WASM_RUNTIME_API_EXTERN uint64_t
wasm_runtime_module_dup_data(wasm_module_inst_t module_inst, const char *src,
uint64_t size);
WASM_RUNTIME_API_EXTERN uint64_t wasm_runtime_module_dup_data(
wasm_module_inst_t module_inst, const char *src, uint64_t size);
/**
* Validate the app address, check whether it belongs to WASM module
@@ -1516,9 +1482,8 @@ wasm_runtime_addr_app_to_native(wasm_module_inst_t module_inst,
*
* @return the app address converted
*/
WASM_RUNTIME_API_EXTERN uint64_t
wasm_runtime_addr_native_to_app(wasm_module_inst_t module_inst,
void *native_ptr);
WASM_RUNTIME_API_EXTERN uint64_t wasm_runtime_addr_native_to_app(
wasm_module_inst_t module_inst, void *native_ptr);
/**
* Get the app address range (relative address) that a app address belongs to
@@ -1530,11 +1495,9 @@ wasm_runtime_addr_native_to_app(wasm_module_inst_t module_inst,
*
* @return true if success, false otherwise.
*/
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_get_app_addr_range(wasm_module_inst_t module_inst,
uint64_t app_offset,
uint64_t *p_app_start_offset,
uint64_t *p_app_end_offset);
WASM_RUNTIME_API_EXTERN bool wasm_runtime_get_app_addr_range(
wasm_module_inst_t module_inst, uint64_t app_offset,
uint64_t *p_app_start_offset, uint64_t *p_app_end_offset);
/**
* Get the native address range (absolute address) that a native address
@@ -1549,11 +1512,9 @@ wasm_runtime_get_app_addr_range(wasm_module_inst_t module_inst,
*
* @return true if success, false otherwise.
*/
WASM_RUNTIME_API_EXTERN bool
wasm_runtime_get_native_addr_range(wasm_module_inst_t module_inst,
uint8_t *native_ptr,
uint8_t **p_native_start_addr,
uint8_t **p_native_end_addr);
WASM_RUNTIME_API_EXTERN bool wasm_runtime_get_native_addr_range(
wasm_module_inst_t module_inst, uint8_t *native_ptr,
uint8_t **p_native_start_addr, uint8_t **p_native_end_addr);
/**
* Get the number of import items for a WASM module
@@ -1631,9 +1592,8 @@ wasm_func_type_get_param_count(const wasm_func_type_t func_type);
*
* @return the kind of the parameter if successful, -1 otherwise
*/
WASM_RUNTIME_API_EXTERN wasm_valkind_t
wasm_func_type_get_param_valkind(const wasm_func_type_t func_type,
uint32_t param_index);
WASM_RUNTIME_API_EXTERN wasm_valkind_t wasm_func_type_get_param_valkind(
const wasm_func_type_t func_type, uint32_t param_index);
/**
* Get the number of results for a function type
@@ -1653,9 +1613,8 @@ wasm_func_type_get_result_count(const wasm_func_type_t func_type);
*
* @return the kind of the result if successful, -1 otherwise
*/
WASM_RUNTIME_API_EXTERN wasm_valkind_t
wasm_func_type_get_result_valkind(const wasm_func_type_t func_type,
uint32_t result_index);
WASM_RUNTIME_API_EXTERN wasm_valkind_t wasm_func_type_get_result_valkind(
const wasm_func_type_t func_type, uint32_t result_index);
/**
* Get the kind for a global type
@@ -1978,8 +1937,7 @@ typedef uintptr_t wasm_thread_t;
*
* @param num maximum thread num
*/
WASM_RUNTIME_API_EXTERN void
wasm_runtime_set_max_thread_num(uint32_t num);
WASM_RUNTIME_API_EXTERN void wasm_runtime_set_max_thread_num(uint32_t num);
/**
* Spawn a new exec_env, the spawned exec_env
@@ -2022,8 +1980,8 @@ wasm_runtime_spawn_thread(wasm_exec_env_t exec_env, wasm_thread_t *tid,
*
* @return 0 if success, error number otherwise
*/
WASM_RUNTIME_API_EXTERN int32_t
wasm_runtime_join_thread(wasm_thread_t tid, void **retval);
WASM_RUNTIME_API_EXTERN int32_t wasm_runtime_join_thread(wasm_thread_t tid,
void **retval);
/**
* Map external object to an internal externref index: if the index
@@ -2076,8 +2034,8 @@ wasm_externref_set_cleanup(wasm_module_inst_t module_inst, void *extern_obj,
*
* @return true if success, false otherwise
*/
WASM_RUNTIME_API_EXTERN bool
wasm_externref_ref2obj(uint32_t externref_idx, void **p_extern_obj);
WASM_RUNTIME_API_EXTERN bool wasm_externref_ref2obj(uint32_t externref_idx,
void **p_extern_obj);
/**
* Retain an extern object which is mapped to the internal externref
@@ -2088,8 +2046,7 @@ wasm_externref_ref2obj(uint32_t externref_idx, void **p_extern_obj);
* to retain
* @return true if success, false otherwise
*/
WASM_RUNTIME_API_EXTERN bool
wasm_externref_retain(uint32_t externref_idx);
WASM_RUNTIME_API_EXTERN bool wasm_externref_retain(uint32_t externref_idx);
/**
* Dump the call stack to stdout
@@ -2123,9 +2080,8 @@ wasm_runtime_get_call_stack_buf_size(wasm_exec_env_t exec_env);
* @return bytes dumped to the buffer, including the terminating null
* byte ('\0'), 0 means error and data in buf may be invalid
*/
WASM_RUNTIME_API_EXTERN uint32_t
wasm_runtime_dump_call_stack_to_buf(wasm_exec_env_t exec_env, char *buf,
uint32_t len);
WASM_RUNTIME_API_EXTERN uint32_t wasm_runtime_dump_call_stack_to_buf(
wasm_exec_env_t exec_env, char *buf, uint32_t len);
/**
* Get the size required to store the LLVM PGO profile data
@@ -2147,9 +2103,8 @@ wasm_runtime_get_pgo_prof_data_size(wasm_module_inst_t module_inst);
* @return bytes dumped to the buffer, 0 means error and data in buf
* may be invalid
*/
WASM_RUNTIME_API_EXTERN uint32_t
wasm_runtime_dump_pgo_prof_data_to_buf(wasm_module_inst_t module_inst,
char *buf, uint32_t len);
WASM_RUNTIME_API_EXTERN uint32_t wasm_runtime_dump_pgo_prof_data_to_buf(
wasm_module_inst_t module_inst, char *buf, uint32_t len);
/**
* Get a custom section by name
@@ -2200,8 +2155,8 @@ wasm_runtime_enlarge_memory(wasm_module_inst_t module_inst,
uint64_t inc_page_count);
typedef enum {
INTERNAL_ERROR,
MAX_SIZE_REACHED,
INTERNAL_ERROR,
MAX_SIZE_REACHED,
} enlarge_memory_error_reason_t;
typedef void (*enlarge_memory_error_callback_t)(
@@ -2212,8 +2167,7 @@ typedef void (*enlarge_memory_error_callback_t)(
/**
* Setup callback invoked when memory.grow fails
*/
WASM_RUNTIME_API_EXTERN void
wasm_runtime_set_enlarge_mem_error_callback(
WASM_RUNTIME_API_EXTERN void wasm_runtime_set_enlarge_mem_error_callback(
const enlarge_memory_error_callback_t callback, void *user_data);
/*
@@ -2268,21 +2222,19 @@ wasm_runtime_set_enlarge_mem_error_callback(
* - The destructor is called only on the main instance.
*/
WASM_RUNTIME_API_EXTERN void *
wasm_runtime_create_context_key(void (*dtor)(wasm_module_inst_t inst,
void *ctx));
WASM_RUNTIME_API_EXTERN void *wasm_runtime_create_context_key(
void (*dtor)(wasm_module_inst_t inst, void *ctx));
WASM_RUNTIME_API_EXTERN void
wasm_runtime_destroy_context_key(void *key);
WASM_RUNTIME_API_EXTERN void wasm_runtime_destroy_context_key(void *key);
WASM_RUNTIME_API_EXTERN void
wasm_runtime_set_context(wasm_module_inst_t inst, void *key, void *ctx);
WASM_RUNTIME_API_EXTERN void wasm_runtime_set_context(wasm_module_inst_t inst,
void *key, void *ctx);
WASM_RUNTIME_API_EXTERN void
wasm_runtime_set_context_spread(wasm_module_inst_t inst, void *key, void *ctx);
WASM_RUNTIME_API_EXTERN void *
wasm_runtime_get_context(wasm_module_inst_t inst, void *key);
WASM_RUNTIME_API_EXTERN void *wasm_runtime_get_context(wasm_module_inst_t inst,
void *key);
/*
* wasm_runtime_begin_blocking_op/wasm_runtime_end_blocking_op
@@ -2419,9 +2371,8 @@ wasm_runtime_create_shared_heap(SharedHeapInitArgs *init_args);
* @param body The body of the shared heap chain to be appended.
* @return The new head of the shared heap chain. NULL if failed.
*/
WASM_RUNTIME_API_EXTERN wasm_shared_heap_t
wasm_runtime_chain_shared_heaps(wasm_shared_heap_t head,
wasm_shared_heap_t body);
WASM_RUNTIME_API_EXTERN wasm_shared_heap_t wasm_runtime_chain_shared_heaps(
wasm_shared_heap_t head, wasm_shared_heap_t body);
/**
* This function unchains the shared heaps from the given head. If
@@ -2434,8 +2385,8 @@ wasm_runtime_chain_shared_heaps(wasm_shared_heap_t head,
* @return The new head of the shared heap chain. Or the last shared heap in the
* chain if `entire_chain` is true.
*/
wasm_shared_heap_t
wasm_runtime_unchain_shared_heaps(wasm_shared_heap_t head, bool entire_chain);
wasm_shared_heap_t wasm_runtime_unchain_shared_heaps(wasm_shared_heap_t head,
bool entire_chain);
/**
* Reset shared heap chain. For each shared heap in the chain, if it is a
@@ -2482,9 +2433,8 @@ wasm_runtime_detach_shared_heap(wasm_module_inst_t module_inst);
* (when the wasm memory is 64-bit). Note that it is not an absolute address.
* Return non-zero if success, zero if failed.
*/
WASM_RUNTIME_API_EXTERN uint64_t
wasm_runtime_shared_heap_malloc(wasm_module_inst_t module_inst, uint64_t size,
void **p_native_addr);
WASM_RUNTIME_API_EXTERN uint64_t wasm_runtime_shared_heap_malloc(
wasm_module_inst_t module_inst, uint64_t size, void **p_native_addr);
/**
* Free the memory allocated from shared heap, or the non-preallocated shared