Add Windows support for C-API and Runtime API libraries and examples. (#379)
* Add Windows support for C-API and Runtime API libraries and examples. Signed-off-by: Wu Zhongmin <vwzm@live.com> Signed-off-by: Xiaokang Qin <xiaokang.qxk@antgroup.com> * Address the review comments Signed-off-by: Xiaokang Qin <xiaokang.qxk@antgroup.com> * Rewrite the the bh_getopt to make it avaliable for more kinds of options Signed-off-by: Wu Zhongmin <vwzm@live.com> Signed-off-by: Xiaokang Qin <xiaokang.qxk@antgroup.com> * Add the license header Signed-off-by: Xiaokang Qin <xiaokang.qxk@antgroup.com> Co-authored-by: Zhongmin Wu <vwzm@live.com>
This commit is contained in:
parent
5418e09712
commit
264e189690
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
|
.vs
|
||||||
.vscode
|
.vscode
|
||||||
**/*build/
|
**/*build/
|
||||||
core/deps/**
|
core/deps/**
|
||||||
|
@ -11,6 +11,18 @@
|
|||||||
#include "lib_export.h"
|
#include "lib_export.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef WASM_RUNTIME_API_EXTERN
|
||||||
|
#if defined(MSVC)
|
||||||
|
#if defined(COMPILING_WASM_RUNTIME_API)
|
||||||
|
#define WASM_RUNTIME_API_EXTERN __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define WASM_RUNTIME_API_EXTERN __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define WASM_RUNTIME_API_EXTERN
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -156,7 +168,7 @@ typedef struct wasm_val_t {
|
|||||||
*
|
*
|
||||||
* @return true if success, false otherwise
|
* @return true if success, false otherwise
|
||||||
*/
|
*/
|
||||||
bool
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_runtime_init(void);
|
wasm_runtime_init(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -168,13 +180,13 @@ wasm_runtime_init(void);
|
|||||||
*
|
*
|
||||||
* @return return true if success, false otherwise
|
* @return return true if success, false otherwise
|
||||||
*/
|
*/
|
||||||
bool
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_runtime_full_init(RuntimeInitArgs *init_args);
|
wasm_runtime_full_init(RuntimeInitArgs *init_args);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy the WASM runtime environment.
|
* Destroy the WASM runtime environment.
|
||||||
*/
|
*/
|
||||||
void
|
WASM_RUNTIME_API_EXTERN void
|
||||||
wasm_runtime_destroy(void);
|
wasm_runtime_destroy(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,7 +196,7 @@ wasm_runtime_destroy(void);
|
|||||||
*
|
*
|
||||||
* @return the pointer to memory allocated
|
* @return the pointer to memory allocated
|
||||||
*/
|
*/
|
||||||
void *
|
WASM_RUNTIME_API_EXTERN void *
|
||||||
wasm_runtime_malloc(unsigned int size);
|
wasm_runtime_malloc(unsigned int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -195,13 +207,14 @@ wasm_runtime_malloc(unsigned int size);
|
|||||||
*
|
*
|
||||||
* @return the pointer to memory reallocated
|
* @return the pointer to memory reallocated
|
||||||
*/
|
*/
|
||||||
void *
|
WASM_RUNTIME_API_EXTERN void *
|
||||||
wasm_runtime_realloc(void *ptr, unsigned int size);
|
wasm_runtime_realloc(void *ptr, unsigned int size);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Free memory to runtime memory environment.
|
* Free memory to runtime memory environment.
|
||||||
*/
|
*/
|
||||||
void wasm_runtime_free(void *ptr);
|
WASM_RUNTIME_API_EXTERN void
|
||||||
|
wasm_runtime_free(void *ptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the package type of a buffer.
|
* Get the package type of a buffer.
|
||||||
@ -211,7 +224,7 @@ void wasm_runtime_free(void *ptr);
|
|||||||
*
|
*
|
||||||
* @return the package type, return Package_Type_Unknown if the type is unknown
|
* @return the package type, return Package_Type_Unknown if the type is unknown
|
||||||
*/
|
*/
|
||||||
package_type_t
|
WASM_RUNTIME_API_EXTERN package_type_t
|
||||||
get_package_type(const uint8_t *buf, uint32_t size);
|
get_package_type(const uint8_t *buf, uint32_t size);
|
||||||
|
|
||||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||||
@ -234,7 +247,7 @@ typedef void (*module_destroyer)(uint8_t *buffer, uint32_t size);
|
|||||||
* @param reader a callback to read a module file into a buffer
|
* @param reader a callback to read a module file into a buffer
|
||||||
* @param destroyer a callback to release above buffer
|
* @param destroyer a callback to release above buffer
|
||||||
*/
|
*/
|
||||||
void
|
WASM_RUNTIME_API_EXTERN void
|
||||||
wasm_runtime_set_module_reader(const module_reader reader,
|
wasm_runtime_set_module_reader(const module_reader reader,
|
||||||
const module_destroyer destroyer);
|
const module_destroyer destroyer);
|
||||||
/**
|
/**
|
||||||
@ -248,7 +261,7 @@ wasm_runtime_set_module_reader(const module_reader reader,
|
|||||||
*
|
*
|
||||||
* @return true means success, false means failed
|
* @return true means success, false means failed
|
||||||
*/
|
*/
|
||||||
bool
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_runtime_register_module(const char *module_name, wasm_module_t module,
|
wasm_runtime_register_module(const char *module_name, wasm_module_t module,
|
||||||
char *error_buf, uint32_t error_buf_size);
|
char *error_buf, uint32_t error_buf_size);
|
||||||
|
|
||||||
@ -260,7 +273,7 @@ wasm_runtime_register_module(const char *module_name, wasm_module_t module,
|
|||||||
*
|
*
|
||||||
* @return return WASM module loaded, NULL if failed
|
* @return return WASM module loaded, NULL if failed
|
||||||
*/
|
*/
|
||||||
wasm_module_t
|
WASM_RUNTIME_API_EXTERN wasm_module_t
|
||||||
wasm_runtime_find_module_registered(const char *module_name);
|
wasm_runtime_find_module_registered(const char *module_name);
|
||||||
#endif /* WASM_ENABLE_MULTI_MODULE */
|
#endif /* WASM_ENABLE_MULTI_MODULE */
|
||||||
|
|
||||||
@ -276,7 +289,7 @@ wasm_runtime_find_module_registered(const char *module_name);
|
|||||||
*
|
*
|
||||||
* @return return WASM module loaded, NULL if failed
|
* @return return WASM module loaded, NULL if failed
|
||||||
*/
|
*/
|
||||||
wasm_module_t
|
WASM_RUNTIME_API_EXTERN wasm_module_t
|
||||||
wasm_runtime_load(const uint8_t *buf, uint32_t size,
|
wasm_runtime_load(const uint8_t *buf, uint32_t size,
|
||||||
char *error_buf, uint32_t error_buf_size);
|
char *error_buf, uint32_t error_buf_size);
|
||||||
|
|
||||||
@ -290,7 +303,7 @@ wasm_runtime_load(const uint8_t *buf, uint32_t size,
|
|||||||
*
|
*
|
||||||
* @return return WASM module loaded, NULL if failed
|
* @return return WASM module loaded, NULL if failed
|
||||||
*/
|
*/
|
||||||
wasm_module_t
|
WASM_RUNTIME_API_EXTERN wasm_module_t
|
||||||
wasm_runtime_load_from_sections(wasm_section_list_t section_list, bool is_aot,
|
wasm_runtime_load_from_sections(wasm_section_list_t section_list, bool is_aot,
|
||||||
char *error_buf, uint32_t error_buf_size);
|
char *error_buf, uint32_t error_buf_size);
|
||||||
|
|
||||||
@ -299,10 +312,10 @@ wasm_runtime_load_from_sections(wasm_section_list_t section_list, bool is_aot,
|
|||||||
*
|
*
|
||||||
* @param module the module to be unloaded
|
* @param module the module to be unloaded
|
||||||
*/
|
*/
|
||||||
void
|
WASM_RUNTIME_API_EXTERN void
|
||||||
wasm_runtime_unload(wasm_module_t module);
|
wasm_runtime_unload(wasm_module_t module);
|
||||||
|
|
||||||
void
|
WASM_RUNTIME_API_EXTERN void
|
||||||
wasm_runtime_set_wasi_args(wasm_module_t module,
|
wasm_runtime_set_wasi_args(wasm_module_t module,
|
||||||
const char *dir_list[], uint32_t dir_count,
|
const char *dir_list[], uint32_t dir_count,
|
||||||
const char *map_dir_list[], uint32_t map_dir_count,
|
const char *map_dir_list[], uint32_t map_dir_count,
|
||||||
@ -329,7 +342,7 @@ wasm_runtime_set_wasi_args(wasm_module_t module,
|
|||||||
*
|
*
|
||||||
* @return return the instantiated WASM module instance, NULL if failed
|
* @return return the instantiated WASM module instance, NULL if failed
|
||||||
*/
|
*/
|
||||||
wasm_module_inst_t
|
WASM_RUNTIME_API_EXTERN wasm_module_inst_t
|
||||||
wasm_runtime_instantiate(const wasm_module_t module,
|
wasm_runtime_instantiate(const wasm_module_t module,
|
||||||
uint32_t stack_size, uint32_t heap_size,
|
uint32_t stack_size, uint32_t heap_size,
|
||||||
char *error_buf, uint32_t error_buf_size);
|
char *error_buf, uint32_t error_buf_size);
|
||||||
@ -339,13 +352,13 @@ wasm_runtime_instantiate(const wasm_module_t module,
|
|||||||
*
|
*
|
||||||
* @param module_inst the WASM module instance to destroy
|
* @param module_inst the WASM module instance to destroy
|
||||||
*/
|
*/
|
||||||
void
|
WASM_RUNTIME_API_EXTERN void
|
||||||
wasm_runtime_deinstantiate(wasm_module_inst_t module_inst);
|
wasm_runtime_deinstantiate(wasm_module_inst_t module_inst);
|
||||||
|
|
||||||
bool
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_runtime_is_wasi_mode(wasm_module_inst_t module_inst);
|
wasm_runtime_is_wasi_mode(wasm_module_inst_t module_inst);
|
||||||
|
|
||||||
wasm_function_inst_t
|
WASM_RUNTIME_API_EXTERN wasm_function_inst_t
|
||||||
wasm_runtime_lookup_wasi_start_function(wasm_module_inst_t module_inst);
|
wasm_runtime_lookup_wasi_start_function(wasm_module_inst_t module_inst);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -357,7 +370,7 @@ wasm_runtime_lookup_wasi_start_function(wasm_module_inst_t module_inst);
|
|||||||
*
|
*
|
||||||
* @return the function instance found, NULL if not found
|
* @return the function instance found, NULL if not found
|
||||||
*/
|
*/
|
||||||
wasm_function_inst_t
|
WASM_RUNTIME_API_EXTERN wasm_function_inst_t
|
||||||
wasm_runtime_lookup_function(wasm_module_inst_t const module_inst,
|
wasm_runtime_lookup_function(wasm_module_inst_t const module_inst,
|
||||||
const char *name, const char *signature);
|
const char *name, const char *signature);
|
||||||
|
|
||||||
@ -370,7 +383,7 @@ wasm_runtime_lookup_function(wasm_module_inst_t const module_inst,
|
|||||||
* @return the execution environment, NULL if failed, e.g. invalid
|
* @return the execution environment, NULL if failed, e.g. invalid
|
||||||
* stack size is passed
|
* stack size is passed
|
||||||
*/
|
*/
|
||||||
wasm_exec_env_t
|
WASM_RUNTIME_API_EXTERN wasm_exec_env_t
|
||||||
wasm_runtime_create_exec_env(wasm_module_inst_t module_inst,
|
wasm_runtime_create_exec_env(wasm_module_inst_t module_inst,
|
||||||
uint32_t stack_size);
|
uint32_t stack_size);
|
||||||
|
|
||||||
@ -379,7 +392,7 @@ wasm_runtime_create_exec_env(wasm_module_inst_t module_inst,
|
|||||||
*
|
*
|
||||||
* @param exec_env the execution environment to destroy
|
* @param exec_env the execution environment to destroy
|
||||||
*/
|
*/
|
||||||
void
|
WASM_RUNTIME_API_EXTERN void
|
||||||
wasm_runtime_destroy_exec_env(wasm_exec_env_t exec_env);
|
wasm_runtime_destroy_exec_env(wasm_exec_env_t exec_env);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -389,7 +402,7 @@ wasm_runtime_destroy_exec_env(wasm_exec_env_t exec_env);
|
|||||||
*
|
*
|
||||||
* @return the WASM module instance
|
* @return the WASM module instance
|
||||||
*/
|
*/
|
||||||
wasm_module_inst_t
|
WASM_RUNTIME_API_EXTERN wasm_module_inst_t
|
||||||
wasm_runtime_get_module_inst(wasm_exec_env_t exec_env);
|
wasm_runtime_get_module_inst(wasm_exec_env_t exec_env);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -409,7 +422,7 @@ wasm_runtime_get_module_inst(wasm_exec_env_t exec_env);
|
|||||||
* the caller can call wasm_runtime_get_exception to get the exception
|
* the caller can call wasm_runtime_get_exception to get the exception
|
||||||
* info.
|
* info.
|
||||||
*/
|
*/
|
||||||
bool
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_runtime_call_wasm(wasm_exec_env_t exec_env,
|
wasm_runtime_call_wasm(wasm_exec_env_t exec_env,
|
||||||
wasm_function_inst_t function,
|
wasm_function_inst_t function,
|
||||||
uint32_t argc, uint32_t argv[]);
|
uint32_t argc, uint32_t argv[]);
|
||||||
@ -430,7 +443,7 @@ wasm_runtime_call_wasm(wasm_exec_env_t exec_env,
|
|||||||
* the caller can call wasm_runtime_get_exception to get the exception
|
* the caller can call wasm_runtime_get_exception to get the exception
|
||||||
* info.
|
* info.
|
||||||
*/
|
*/
|
||||||
bool
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_runtime_call_wasm_a(wasm_exec_env_t exec_env,
|
wasm_runtime_call_wasm_a(wasm_exec_env_t exec_env,
|
||||||
wasm_function_inst_t function,
|
wasm_function_inst_t function,
|
||||||
uint32_t num_results, wasm_val_t results[],
|
uint32_t num_results, wasm_val_t results[],
|
||||||
@ -452,7 +465,7 @@ wasm_runtime_call_wasm_a(wasm_exec_env_t exec_env,
|
|||||||
* the caller can call wasm_runtime_get_exception to get the exception
|
* the caller can call wasm_runtime_get_exception to get the exception
|
||||||
* info.
|
* info.
|
||||||
*/
|
*/
|
||||||
bool
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_runtime_call_wasm_v(wasm_exec_env_t exec_env,
|
wasm_runtime_call_wasm_v(wasm_exec_env_t exec_env,
|
||||||
wasm_function_inst_t function,
|
wasm_function_inst_t function,
|
||||||
uint32_t num_results, wasm_val_t results[],
|
uint32_t num_results, wasm_val_t results[],
|
||||||
@ -470,7 +483,7 @@ wasm_runtime_call_wasm_v(wasm_exec_env_t exec_env,
|
|||||||
* will be thrown, the caller can call wasm_runtime_get_exception to get
|
* will be thrown, the caller can call wasm_runtime_get_exception to get
|
||||||
* the exception info.
|
* the exception info.
|
||||||
*/
|
*/
|
||||||
bool
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_application_execute_main(wasm_module_inst_t module_inst,
|
wasm_application_execute_main(wasm_module_inst_t module_inst,
|
||||||
int32_t argc, char *argv[]);
|
int32_t argc, char *argv[]);
|
||||||
|
|
||||||
@ -489,7 +502,7 @@ wasm_application_execute_main(wasm_module_inst_t module_inst,
|
|||||||
* exception will be thrown, the caller can call wasm_runtime_get_exception
|
* exception will be thrown, the caller can call wasm_runtime_get_exception
|
||||||
* to get the exception info.
|
* to get the exception info.
|
||||||
*/
|
*/
|
||||||
bool
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_application_execute_func(wasm_module_inst_t module_inst,
|
wasm_application_execute_func(wasm_module_inst_t module_inst,
|
||||||
const char *name, int32_t argc, char *argv[]);
|
const char *name, int32_t argc, char *argv[]);
|
||||||
/**
|
/**
|
||||||
@ -499,7 +512,7 @@ wasm_application_execute_func(wasm_module_inst_t module_inst,
|
|||||||
*
|
*
|
||||||
* @return the exception string
|
* @return the exception string
|
||||||
*/
|
*/
|
||||||
const char *
|
WASM_RUNTIME_API_EXTERN const char *
|
||||||
wasm_runtime_get_exception(wasm_module_inst_t module_inst);
|
wasm_runtime_get_exception(wasm_module_inst_t module_inst);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -509,7 +522,7 @@ wasm_runtime_get_exception(wasm_module_inst_t module_inst);
|
|||||||
*
|
*
|
||||||
* @param exception the exception string
|
* @param exception the exception string
|
||||||
*/
|
*/
|
||||||
void
|
WASM_RUNTIME_API_EXTERN void
|
||||||
wasm_runtime_set_exception(wasm_module_inst_t module_inst,
|
wasm_runtime_set_exception(wasm_module_inst_t module_inst,
|
||||||
const char *exception);
|
const char *exception);
|
||||||
|
|
||||||
@ -518,7 +531,7 @@ wasm_runtime_set_exception(wasm_module_inst_t module_inst,
|
|||||||
*
|
*
|
||||||
* @param module_inst the WASM module instance
|
* @param module_inst the WASM module instance
|
||||||
*/
|
*/
|
||||||
void
|
WASM_RUNTIME_API_EXTERN void
|
||||||
wasm_runtime_clear_exception(wasm_module_inst_t module_inst);
|
wasm_runtime_clear_exception(wasm_module_inst_t module_inst);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -527,7 +540,7 @@ wasm_runtime_clear_exception(wasm_module_inst_t module_inst);
|
|||||||
* @param module_inst the WASM module instance
|
* @param module_inst the WASM module instance
|
||||||
* @param custom_data the custom data to be set
|
* @param custom_data the custom data to be set
|
||||||
*/
|
*/
|
||||||
void
|
WASM_RUNTIME_API_EXTERN void
|
||||||
wasm_runtime_set_custom_data(wasm_module_inst_t module_inst,
|
wasm_runtime_set_custom_data(wasm_module_inst_t module_inst,
|
||||||
void *custom_data);
|
void *custom_data);
|
||||||
/**
|
/**
|
||||||
@ -537,7 +550,7 @@ wasm_runtime_set_custom_data(wasm_module_inst_t module_inst,
|
|||||||
*
|
*
|
||||||
* @return the custom data (NULL if not set yet)
|
* @return the custom data (NULL if not set yet)
|
||||||
*/
|
*/
|
||||||
void *
|
WASM_RUNTIME_API_EXTERN void *
|
||||||
wasm_runtime_get_custom_data(wasm_module_inst_t module_inst);
|
wasm_runtime_get_custom_data(wasm_module_inst_t module_inst);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -553,7 +566,7 @@ wasm_runtime_get_custom_data(wasm_module_inst_t module_inst);
|
|||||||
* it is not an absolute address.
|
* it is not an absolute address.
|
||||||
* Return non-zero if success, zero if failed.
|
* Return non-zero if success, zero if failed.
|
||||||
*/
|
*/
|
||||||
uint32_t
|
WASM_RUNTIME_API_EXTERN uint32_t
|
||||||
wasm_runtime_module_malloc(wasm_module_inst_t module_inst, uint32_t size,
|
wasm_runtime_module_malloc(wasm_module_inst_t module_inst, uint32_t size,
|
||||||
void **p_native_addr);
|
void **p_native_addr);
|
||||||
|
|
||||||
@ -563,7 +576,7 @@ wasm_runtime_module_malloc(wasm_module_inst_t module_inst, uint32_t size,
|
|||||||
* @param module_inst the WASM module instance which contains heap
|
* @param module_inst the WASM module instance which contains heap
|
||||||
* @param ptr the pointer to free
|
* @param ptr the pointer to free
|
||||||
*/
|
*/
|
||||||
void
|
WASM_RUNTIME_API_EXTERN void
|
||||||
wasm_runtime_module_free(wasm_module_inst_t module_inst, uint32_t ptr);
|
wasm_runtime_module_free(wasm_module_inst_t module_inst, uint32_t ptr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -579,7 +592,7 @@ wasm_runtime_module_free(wasm_module_inst_t module_inst, uint32_t ptr);
|
|||||||
* it is not an absolute address.
|
* it is not an absolute address.
|
||||||
* Return non-zero if success, zero if failed.
|
* Return non-zero if success, zero if failed.
|
||||||
*/
|
*/
|
||||||
uint32_t
|
WASM_RUNTIME_API_EXTERN uint32_t
|
||||||
wasm_runtime_module_dup_data(wasm_module_inst_t module_inst,
|
wasm_runtime_module_dup_data(wasm_module_inst_t module_inst,
|
||||||
const char *src, uint32_t size);
|
const char *src, uint32_t size);
|
||||||
|
|
||||||
@ -594,7 +607,7 @@ wasm_runtime_module_dup_data(wasm_module_inst_t module_inst,
|
|||||||
* @return true if success, false otherwise. If failed, an exception will
|
* @return true if success, false otherwise. If failed, an exception will
|
||||||
* be thrown.
|
* be thrown.
|
||||||
*/
|
*/
|
||||||
bool
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_runtime_validate_app_addr(wasm_module_inst_t module_inst,
|
wasm_runtime_validate_app_addr(wasm_module_inst_t module_inst,
|
||||||
uint32_t app_offset, uint32_t size);
|
uint32_t app_offset, uint32_t size);
|
||||||
|
|
||||||
@ -611,7 +624,7 @@ wasm_runtime_validate_app_addr(wasm_module_inst_t module_inst,
|
|||||||
* @return true if success, false otherwise. If failed, an exception will
|
* @return true if success, false otherwise. If failed, an exception will
|
||||||
* be thrown.
|
* be thrown.
|
||||||
*/
|
*/
|
||||||
bool
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_runtime_validate_app_str_addr(wasm_module_inst_t module_inst,
|
wasm_runtime_validate_app_str_addr(wasm_module_inst_t module_inst,
|
||||||
uint32_t app_str_offset);
|
uint32_t app_str_offset);
|
||||||
|
|
||||||
@ -627,7 +640,7 @@ wasm_runtime_validate_app_str_addr(wasm_module_inst_t module_inst,
|
|||||||
* @return true if success, false otherwise. If failed, an exception will
|
* @return true if success, false otherwise. If failed, an exception will
|
||||||
* be thrown.
|
* be thrown.
|
||||||
*/
|
*/
|
||||||
bool
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_runtime_validate_native_addr(wasm_module_inst_t module_inst,
|
wasm_runtime_validate_native_addr(wasm_module_inst_t module_inst,
|
||||||
void *native_ptr, uint32_t size);
|
void *native_ptr, uint32_t size);
|
||||||
|
|
||||||
@ -639,7 +652,7 @@ wasm_runtime_validate_native_addr(wasm_module_inst_t module_inst,
|
|||||||
*
|
*
|
||||||
* @return the native address converted
|
* @return the native address converted
|
||||||
*/
|
*/
|
||||||
void*
|
WASM_RUNTIME_API_EXTERN void *
|
||||||
wasm_runtime_addr_app_to_native(wasm_module_inst_t module_inst,
|
wasm_runtime_addr_app_to_native(wasm_module_inst_t module_inst,
|
||||||
uint32_t app_offset);
|
uint32_t app_offset);
|
||||||
|
|
||||||
@ -651,7 +664,7 @@ wasm_runtime_addr_app_to_native(wasm_module_inst_t module_inst,
|
|||||||
*
|
*
|
||||||
* @return the app address converted
|
* @return the app address converted
|
||||||
*/
|
*/
|
||||||
uint32_t
|
WASM_RUNTIME_API_EXTERN uint32_t
|
||||||
wasm_runtime_addr_native_to_app(wasm_module_inst_t module_inst,
|
wasm_runtime_addr_native_to_app(wasm_module_inst_t module_inst,
|
||||||
void *native_ptr);
|
void *native_ptr);
|
||||||
|
|
||||||
@ -665,7 +678,7 @@ wasm_runtime_addr_native_to_app(wasm_module_inst_t module_inst,
|
|||||||
*
|
*
|
||||||
* @return true if success, false otherwise.
|
* @return true if success, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_runtime_get_app_addr_range(wasm_module_inst_t module_inst,
|
wasm_runtime_get_app_addr_range(wasm_module_inst_t module_inst,
|
||||||
uint32_t app_offset,
|
uint32_t app_offset,
|
||||||
uint32_t *p_app_start_offset,
|
uint32_t *p_app_start_offset,
|
||||||
@ -681,7 +694,7 @@ wasm_runtime_get_app_addr_range(wasm_module_inst_t module_inst,
|
|||||||
*
|
*
|
||||||
* @return true if success, false otherwise.
|
* @return true if success, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_runtime_get_native_addr_range(wasm_module_inst_t module_inst,
|
wasm_runtime_get_native_addr_range(wasm_module_inst_t module_inst,
|
||||||
uint8_t *native_ptr,
|
uint8_t *native_ptr,
|
||||||
uint8_t **p_native_start_addr,
|
uint8_t **p_native_start_addr,
|
||||||
@ -713,7 +726,8 @@ wasm_runtime_get_native_addr_range(wasm_module_inst_t module_inst,
|
|||||||
*
|
*
|
||||||
* @return true if success, false otherwise
|
* @return true if success, false otherwise
|
||||||
*/
|
*/
|
||||||
bool wasm_runtime_register_natives(const char *module_name,
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
|
wasm_runtime_register_natives(const char *module_name,
|
||||||
NativeSymbol *native_symbols,
|
NativeSymbol *native_symbols,
|
||||||
uint32_t n_native_symbols);
|
uint32_t n_native_symbols);
|
||||||
|
|
||||||
@ -727,7 +741,8 @@ bool wasm_runtime_register_natives(const char *module_name,
|
|||||||
* and write the return value back to args[0] with macro
|
* and write the return value back to args[0] with macro
|
||||||
* native_raw_return_type and native_raw_set_return
|
* native_raw_return_type and native_raw_set_return
|
||||||
*/
|
*/
|
||||||
bool wasm_runtime_register_natives_raw(const char *module_name,
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
|
wasm_runtime_register_natives_raw(const char *module_name,
|
||||||
NativeSymbol *native_symbols,
|
NativeSymbol *native_symbols,
|
||||||
uint32_t n_native_symbols);
|
uint32_t n_native_symbols);
|
||||||
|
|
||||||
@ -738,7 +753,7 @@ bool wasm_runtime_register_natives_raw(const char *module_name,
|
|||||||
*
|
*
|
||||||
* @return the attachment of native function
|
* @return the attachment of native function
|
||||||
*/
|
*/
|
||||||
void *
|
WASM_RUNTIME_API_EXTERN void *
|
||||||
wasm_runtime_get_function_attachment(wasm_exec_env_t exec_env);
|
wasm_runtime_get_function_attachment(wasm_exec_env_t exec_env);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -747,7 +762,7 @@ wasm_runtime_get_function_attachment(wasm_exec_env_t exec_env);
|
|||||||
* @param exec_env the execution environment
|
* @param exec_env the execution environment
|
||||||
* @param user_data the user data to be set
|
* @param user_data the user data to be set
|
||||||
*/
|
*/
|
||||||
void
|
WASM_RUNTIME_API_EXTERN void
|
||||||
wasm_runtime_set_user_data(wasm_exec_env_t exec_env,
|
wasm_runtime_set_user_data(wasm_exec_env_t exec_env,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
/**
|
/**
|
||||||
@ -757,7 +772,7 @@ wasm_runtime_set_user_data(wasm_exec_env_t exec_env,
|
|||||||
*
|
*
|
||||||
* @return the user data (NULL if not set yet)
|
* @return the user data (NULL if not set yet)
|
||||||
*/
|
*/
|
||||||
void *
|
WASM_RUNTIME_API_EXTERN void *
|
||||||
wasm_runtime_get_user_data(wasm_exec_env_t exec_env);
|
wasm_runtime_get_user_data(wasm_exec_env_t exec_env);
|
||||||
|
|
||||||
#if WASM_ENABLE_THREAD_MGR != 0
|
#if WASM_ENABLE_THREAD_MGR != 0
|
||||||
@ -771,7 +786,7 @@ typedef uintptr_t wasm_thread_t;
|
|||||||
*
|
*
|
||||||
* @param num maximum thread num
|
* @param num maximum thread num
|
||||||
*/
|
*/
|
||||||
void
|
WASM_RUNTIME_API_EXTERN void
|
||||||
wasm_runtime_set_max_thread_num(uint32_t num);
|
wasm_runtime_set_max_thread_num(uint32_t num);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -782,7 +797,7 @@ wasm_runtime_set_max_thread_num(uint32_t num);
|
|||||||
*
|
*
|
||||||
* @return the spawned exec_env if success, NULL otherwise
|
* @return the spawned exec_env if success, NULL otherwise
|
||||||
*/
|
*/
|
||||||
wasm_exec_env_t
|
WASM_RUNTIME_API_EXTERN wasm_exec_env_t
|
||||||
wasm_runtime_spawn_exec_env(wasm_exec_env_t exec_env);
|
wasm_runtime_spawn_exec_env(wasm_exec_env_t exec_env);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -790,7 +805,7 @@ wasm_runtime_spawn_exec_env(wasm_exec_env_t exec_env);
|
|||||||
*
|
*
|
||||||
* @param exec_env the spawned exec_env
|
* @param exec_env the spawned exec_env
|
||||||
*/
|
*/
|
||||||
void
|
WASM_RUNTIME_API_EXTERN void
|
||||||
wasm_runtime_destroy_spawned_exec_env(wasm_exec_env_t exec_env);
|
wasm_runtime_destroy_spawned_exec_env(wasm_exec_env_t exec_env);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -803,7 +818,7 @@ wasm_runtime_destroy_spawned_exec_env(wasm_exec_env_t exec_env);
|
|||||||
*
|
*
|
||||||
* @return 0 if success, -1 otherwise
|
* @return 0 if success, -1 otherwise
|
||||||
*/
|
*/
|
||||||
int32_t
|
WASM_RUNTIME_API_EXTERN int32_t
|
||||||
wasm_runtime_spawn_thread(wasm_exec_env_t exec_env, wasm_thread_t *tid,
|
wasm_runtime_spawn_thread(wasm_exec_env_t exec_env, wasm_thread_t *tid,
|
||||||
wasm_thread_callback_t callback, void *arg);
|
wasm_thread_callback_t callback, void *arg);
|
||||||
|
|
||||||
@ -815,7 +830,7 @@ wasm_runtime_spawn_thread(wasm_exec_env_t exec_env, wasm_thread_t *tid,
|
|||||||
*
|
*
|
||||||
* @return 0 if success, error number otherwise
|
* @return 0 if success, error number otherwise
|
||||||
*/
|
*/
|
||||||
int32_t
|
WASM_RUNTIME_API_EXTERN int32_t
|
||||||
wasm_runtime_join_thread(wasm_thread_t tid, void **retval);
|
wasm_runtime_join_thread(wasm_thread_t tid, void **retval);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -34,8 +34,13 @@ extern "C" {
|
|||||||
#define BH_FREE os_free
|
#define BH_FREE os_free
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(MSVC)
|
||||||
|
__declspec(dllimport) void *BH_MALLOC(unsigned int size);
|
||||||
|
__declspec(dllimport) void BH_FREE(void *ptr);
|
||||||
|
#else
|
||||||
void *BH_MALLOC(unsigned int size);
|
void *BH_MALLOC(unsigned int size);
|
||||||
void BH_FREE(void *ptr);
|
void BH_FREE(void *ptr);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef NULL
|
#ifndef NULL
|
||||||
#define NULL (void*)0
|
#define NULL (void*)0
|
||||||
|
60
core/shared/utils/uncommon/bh_getopt.c
Normal file
60
core/shared/utils/uncommon/bh_getopt.c
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Ant Financial Services Group. All rights reserved.
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __GNUC__
|
||||||
|
|
||||||
|
#include "bh_getopt.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char* optarg = NULL;
|
||||||
|
int optind = 1;
|
||||||
|
|
||||||
|
int getopt(int argc, char *const argv[], const char *optstring)
|
||||||
|
{
|
||||||
|
static int sp = 1;
|
||||||
|
int c;
|
||||||
|
int opt;
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
if (sp == 1) {
|
||||||
|
if ((optind >= argc) || (argv[optind][0] != '-') || (argv[optind][1] == 0)){
|
||||||
|
return -1;
|
||||||
|
} else if (!strcmp(argv[optind], "--")) {
|
||||||
|
optind++;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
opt = argv[optind][sp];
|
||||||
|
p = strchr(optstring, opt);
|
||||||
|
if (opt == ':' || p == NULL) {
|
||||||
|
printf("illegal option : '-%c'\n", opt);
|
||||||
|
if ( argv[optind][++sp] == '\0') {
|
||||||
|
optind ++;
|
||||||
|
sp = 1;
|
||||||
|
}
|
||||||
|
return ('?');
|
||||||
|
}
|
||||||
|
if (p[1] == ':') {
|
||||||
|
if (argv[optind][sp + 1] != '\0')
|
||||||
|
optarg = &argv[optind++][sp + 1];
|
||||||
|
else if (++optind >= argc) {
|
||||||
|
printf("option '-%c' requires an argument :\n", opt);
|
||||||
|
sp = 1;
|
||||||
|
return ('?');
|
||||||
|
} else {
|
||||||
|
optarg = argv[optind++];
|
||||||
|
}
|
||||||
|
sp = 1;
|
||||||
|
} else {
|
||||||
|
if (argv[optind][++sp] == '\0') {
|
||||||
|
sp = 1;
|
||||||
|
optind++;
|
||||||
|
}
|
||||||
|
optarg = NULL;
|
||||||
|
}
|
||||||
|
return (opt);
|
||||||
|
}
|
||||||
|
#endif
|
27
core/shared/utils/uncommon/bh_getopt.h
Normal file
27
core/shared/utils/uncommon/bh_getopt.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Ant Financial Services Group. All rights reserved.
|
||||||
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#include <getopt.h>
|
||||||
|
#endif
|
||||||
|
#ifndef __GNUC__
|
||||||
|
#ifndef GETOPT_H__
|
||||||
|
#define GETOPT_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern char *optarg;
|
||||||
|
extern int optind;
|
||||||
|
|
||||||
|
int getopt(int argc, char *const argv[], const char *optstring);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* end of GETOPT_H__ */
|
||||||
|
#endif /* end of __GNUC__ */
|
@ -119,3 +119,5 @@ install (TARGETS libiwasm DESTINATION lib)
|
|||||||
set_target_properties (libiwasm PROPERTIES OUTPUT_NAME iwasm)
|
set_target_properties (libiwasm PROPERTIES OUTPUT_NAME iwasm)
|
||||||
|
|
||||||
target_link_libraries (libiwasm ${LLVM_AVAILABLE_LIBS})
|
target_link_libraries (libiwasm ${LLVM_AVAILABLE_LIBS})
|
||||||
|
|
||||||
|
target_compile_definitions(libiwasm PRIVATE COMPILING_WASM_RUNTIME_API=1)
|
||||||
|
@ -3,7 +3,12 @@
|
|||||||
|
|
||||||
cmake_minimum_required (VERSION 2.8)
|
cmake_minimum_required (VERSION 2.8)
|
||||||
|
|
||||||
|
if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows")
|
||||||
project (basic)
|
project (basic)
|
||||||
|
else()
|
||||||
|
project (basic C ASM)
|
||||||
|
enable_language (ASM_MASM)
|
||||||
|
endif()
|
||||||
|
|
||||||
################ runtime settings ################
|
################ runtime settings ################
|
||||||
string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
|
string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
|
||||||
@ -22,9 +27,12 @@ set (WAMR_BUILD_INTERP 1)
|
|||||||
set (WAMR_BUILD_AOT 1)
|
set (WAMR_BUILD_AOT 1)
|
||||||
set (WAMR_BUILD_JIT 0)
|
set (WAMR_BUILD_JIT 0)
|
||||||
set (WAMR_BUILD_LIBC_BUILTIN 1)
|
set (WAMR_BUILD_LIBC_BUILTIN 1)
|
||||||
|
if (NOT MSVC)
|
||||||
set (WAMR_BUILD_LIBC_WASI 1)
|
set (WAMR_BUILD_LIBC_WASI 1)
|
||||||
|
endif ()
|
||||||
set (WAMR_BUILD_FAST_INTERP 0)
|
set (WAMR_BUILD_FAST_INTERP 0)
|
||||||
|
|
||||||
|
if (NOT MSVC)
|
||||||
# linker flags
|
# linker flags
|
||||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie -fPIE")
|
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie -fPIE")
|
||||||
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
|
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
|
||||||
@ -36,6 +44,7 @@ if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
|
|||||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
|
||||||
endif ()
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
endif ()
|
||||||
|
|
||||||
# build out vmlib
|
# build out vmlib
|
||||||
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
|
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "wasm_export.h"
|
#include "wasm_export.h"
|
||||||
#include "bh_read_file.h"
|
#include "bh_read_file.h"
|
||||||
|
#include "bh_getopt.h"
|
||||||
|
|
||||||
int intToStr(int x, char* str, int str_len, int digit);
|
int intToStr(int x, char* str, int str_len, int digit);
|
||||||
int get_pow(int x, int y);
|
int get_pow(int x, int y);
|
||||||
|
@ -2,7 +2,13 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
|
||||||
cmake_minimum_required (VERSION 2.8)
|
cmake_minimum_required (VERSION 2.8)
|
||||||
|
|
||||||
|
if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows")
|
||||||
project(c-api)
|
project(c-api)
|
||||||
|
else()
|
||||||
|
project (c-api C ASM)
|
||||||
|
enable_language (ASM_MASM)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(NOT CMAKE_BUILD_TYPE)
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
set(CMAKE_BUILD_TYPE Release)
|
set(CMAKE_BUILD_TYPE Release)
|
||||||
@ -39,6 +45,7 @@ if(NOT DEFINED WAMR_BUILD_FAST_INTERP)
|
|||||||
set(WAMR_BUILD_FAST_INTERP 0)
|
set(WAMR_BUILD_FAST_INTERP 0)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (NOT MSVC)
|
||||||
# compiling and linking flags
|
# compiling and linking flags
|
||||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie -fPIE")
|
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie -fPIE")
|
||||||
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
|
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
|
||||||
@ -50,13 +57,16 @@ if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
|
|||||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
|
||||||
endif ()
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
endif()
|
||||||
# build out vmlib
|
# build out vmlib
|
||||||
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
|
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
|
||||||
set(WAMRC ${WAMR_ROOT_DIR}/wamr-compiler/build/wamrc)
|
set(WAMRC ${WAMR_ROOT_DIR}/wamr-compiler/build/wamrc)
|
||||||
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
||||||
|
|
||||||
add_library(vmlib STATIC ${WAMR_RUNTIME_LIB_SOURCE})
|
add_library(vmlib STATIC ${WAMR_RUNTIME_LIB_SOURCE})
|
||||||
|
if (MSVC)
|
||||||
|
target_compile_definitions(vmlib PRIVATE WASM_API_EXTERN=)
|
||||||
|
endif()
|
||||||
################################################
|
################################################
|
||||||
|
|
||||||
################ application related ################
|
################ application related ################
|
||||||
@ -66,6 +76,9 @@ target_include_directories(c-api
|
|||||||
PRIVATE ${C_API_PATH}/include
|
PRIVATE ${C_API_PATH}/include
|
||||||
)
|
)
|
||||||
target_link_libraries(c-api PRIVATE vmlib -lpthread -lm)
|
target_link_libraries(c-api PRIVATE vmlib -lpthread -lm)
|
||||||
|
if (MSVC)
|
||||||
|
target_compile_definitions(c-api PRIVATE WASM_API_EXTERN=)
|
||||||
|
endif()
|
||||||
|
|
||||||
foreach(SRC ${SOURCES})
|
foreach(SRC ${SOURCES})
|
||||||
get_filename_component(APPNAME ${SRC} NAME_WE)
|
get_filename_component(APPNAME ${SRC} NAME_WE)
|
||||||
@ -74,6 +87,9 @@ foreach(SRC ${SOURCES})
|
|||||||
add_executable(${APPNAME} ${SRC})
|
add_executable(${APPNAME} ${SRC})
|
||||||
message("create executable about ${APPNAME}")
|
message("create executable about ${APPNAME}")
|
||||||
target_link_libraries(${APPNAME} c-api)
|
target_link_libraries(${APPNAME} c-api)
|
||||||
|
if (MSVC)
|
||||||
|
target_compile_definitions(${APPNAME} PRIVATE WASM_API_EXTERN=)
|
||||||
|
endif()
|
||||||
|
|
||||||
# copy .wasm
|
# copy .wasm
|
||||||
add_custom_command(TARGET ${APPNAME} POST_BUILD
|
add_custom_command(TARGET ${APPNAME} POST_BUILD
|
||||||
|
Reference in New Issue
Block a user