2019-05-07 02:18:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
2019-11-11 23:45:21 +00:00
|
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-05-07 02:18:18 +00:00
|
|
|
*/
|
|
|
|
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
#include "wasm_native.h"
|
2020-03-04 12:12:38 +00:00
|
|
|
#include "wasm_runtime_common.h"
|
|
|
|
#include "bh_log.h"
|
2019-05-07 02:18:18 +00:00
|
|
|
|
2020-11-26 11:10:05 +00:00
|
|
|
#if !defined(BH_PLATFORM_ZEPHYR) && !defined(BH_PLATFORM_ALIOS_THINGS) \
|
2020-11-30 08:03:51 +00:00
|
|
|
&& !defined(BH_PLATFORM_OPENRTOS) && !defined(BH_PLATFORM_ESP_IDF)
|
2020-07-31 12:54:03 +00:00
|
|
|
#define ENABLE_QUICKSORT 1
|
2020-08-03 03:30:26 +00:00
|
|
|
#else
|
|
|
|
#define ENABLE_QUICKSORT 0
|
|
|
|
#endif
|
|
|
|
|
2020-07-31 12:54:03 +00:00
|
|
|
#define ENABLE_SORT_DEBUG 0
|
|
|
|
|
|
|
|
#if ENABLE_SORT_DEBUG != 0
|
2021-10-08 09:47:11 +00:00
|
|
|
#include <sys/time.h>
|
2020-07-31 12:54:03 +00:00
|
|
|
#endif
|
2019-05-07 02:18:18 +00:00
|
|
|
|
2020-03-04 12:12:38 +00:00
|
|
|
static NativeSymbolsList g_native_symbols_list = NULL;
|
|
|
|
|
|
|
|
uint32
|
|
|
|
get_libc_builtin_export_apis(NativeSymbol **p_libc_builtin_apis);
|
|
|
|
|
2020-04-30 09:52:11 +00:00
|
|
|
#if WASM_ENABLE_SPEC_TEST != 0
|
2020-03-04 12:12:38 +00:00
|
|
|
uint32
|
|
|
|
get_spectest_export_apis(NativeSymbol **p_libc_builtin_apis);
|
2020-04-30 09:52:11 +00:00
|
|
|
#endif
|
2020-03-04 12:12:38 +00:00
|
|
|
|
|
|
|
uint32
|
|
|
|
get_libc_wasi_export_apis(NativeSymbol **p_libc_wasi_apis);
|
|
|
|
|
2022-10-12 04:09:29 +00:00
|
|
|
uint32_t
|
|
|
|
get_wasi_nn_export_apis(NativeSymbol **p_libc_wasi_apis);
|
|
|
|
|
2020-03-04 12:12:38 +00:00
|
|
|
uint32
|
|
|
|
get_base_lib_export_apis(NativeSymbol **p_base_lib_apis);
|
|
|
|
|
|
|
|
uint32
|
|
|
|
get_ext_lib_export_apis(NativeSymbol **p_ext_lib_apis);
|
2019-05-07 02:18:18 +00:00
|
|
|
|
2020-06-15 11:04:04 +00:00
|
|
|
#if WASM_ENABLE_LIB_PTHREAD != 0
|
|
|
|
bool
|
|
|
|
lib_pthread_init();
|
|
|
|
|
|
|
|
void
|
|
|
|
lib_pthread_destroy();
|
|
|
|
|
|
|
|
uint32
|
|
|
|
get_lib_pthread_export_apis(NativeSymbol **p_lib_pthread_apis);
|
|
|
|
#endif
|
|
|
|
|
2022-12-06 13:11:27 +00:00
|
|
|
#if WASM_ENABLE_LIB_WASI_THREADS != 0
|
2022-12-13 13:33:27 +00:00
|
|
|
bool
|
|
|
|
lib_wasi_threads_init(void);
|
|
|
|
|
|
|
|
void
|
|
|
|
lib_wasi_threads_destroy(void);
|
|
|
|
|
2022-12-06 13:11:27 +00:00
|
|
|
uint32
|
|
|
|
get_lib_wasi_threads_export_apis(NativeSymbol **p_lib_wasi_threads_apis);
|
|
|
|
#endif
|
|
|
|
|
2020-10-22 08:18:37 +00:00
|
|
|
uint32
|
|
|
|
get_libc_emcc_export_apis(NativeSymbol **p_libc_emcc_apis);
|
|
|
|
|
2022-09-06 06:29:58 +00:00
|
|
|
uint32
|
|
|
|
get_lib_rats_export_apis(NativeSymbol **p_lib_rats_apis);
|
|
|
|
|
2022-01-19 03:25:08 +00:00
|
|
|
static bool
|
|
|
|
compare_type_with_signautre(uint8 type, const char signature)
|
|
|
|
{
|
|
|
|
const char num_sig_map[] = { 'F', 'f', 'I', 'i' };
|
|
|
|
|
|
|
|
if (VALUE_TYPE_F64 <= type && type <= VALUE_TYPE_I32
|
|
|
|
&& signature == num_sig_map[type - VALUE_TYPE_F64]) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if WASM_ENABLE_REF_TYPES != 0
|
|
|
|
if ('r' == signature && type == VALUE_TYPE_EXTERNREF)
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* TODO: a v128 parameter */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-07 02:18:18 +00:00
|
|
|
static bool
|
2020-03-04 12:12:38 +00:00
|
|
|
check_symbol_signature(const WASMType *type, const char *signature)
|
2019-05-07 02:18:18 +00:00
|
|
|
{
|
2020-03-04 12:12:38 +00:00
|
|
|
const char *p = signature, *p_end;
|
2022-01-19 03:25:08 +00:00
|
|
|
char sig;
|
2020-03-04 12:12:38 +00:00
|
|
|
uint32 i = 0;
|
2019-05-07 02:18:18 +00:00
|
|
|
|
2020-03-04 12:12:38 +00:00
|
|
|
if (!p || strlen(p) < 2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
p_end = p + strlen(signature);
|
|
|
|
|
|
|
|
if (*p++ != '(')
|
|
|
|
return false;
|
|
|
|
|
2020-07-10 08:29:15 +00:00
|
|
|
if ((uint32)(p_end - p) < (uint32)(type->param_count + 1))
|
2020-03-04 12:12:38 +00:00
|
|
|
/* signatures of parameters, and ')' */
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (i = 0; i < type->param_count; i++) {
|
|
|
|
sig = *p++;
|
2022-01-19 03:25:08 +00:00
|
|
|
|
|
|
|
/* a f64/f32/i64/i32/externref parameter */
|
|
|
|
if (compare_type_with_signautre(type->types[i], sig))
|
2020-03-04 12:12:38 +00:00
|
|
|
continue;
|
|
|
|
|
2022-01-19 03:25:08 +00:00
|
|
|
/* a pointer/string paramter */
|
2020-03-04 12:12:38 +00:00
|
|
|
if (type->types[i] != VALUE_TYPE_I32)
|
|
|
|
/* pointer and string must be i32 type */
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (sig == '*') {
|
|
|
|
/* it is a pointer */
|
|
|
|
if (i + 1 < type->param_count
|
2021-10-08 09:47:11 +00:00
|
|
|
&& type->types[i + 1] == VALUE_TYPE_I32 && *p == '~') {
|
2020-03-04 12:12:38 +00:00
|
|
|
/* pointer length followed */
|
|
|
|
i++;
|
|
|
|
p++;
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-04 12:12:38 +00:00
|
|
|
else if (sig == '$') {
|
|
|
|
/* it is a string */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* invalid signature */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*p++ != ')')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (type->result_count) {
|
|
|
|
if (p >= p_end)
|
|
|
|
return false;
|
2022-01-19 03:25:08 +00:00
|
|
|
|
|
|
|
/* result types includes: f64,f32,i64,i32,externref */
|
|
|
|
if (!compare_type_with_signautre(type->types[i], *p))
|
2020-03-04 12:12:38 +00:00
|
|
|
return false;
|
2022-01-19 03:25:08 +00:00
|
|
|
|
|
|
|
p++;
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 12:12:38 +00:00
|
|
|
if (*p != '\0')
|
|
|
|
return false;
|
|
|
|
|
2019-05-07 02:18:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-31 12:54:03 +00:00
|
|
|
#if ENABLE_QUICKSORT == 0
|
2020-03-04 12:12:38 +00:00
|
|
|
static void
|
|
|
|
sort_symbol_ptr(NativeSymbol *native_symbols, uint32 n_native_symbols)
|
|
|
|
{
|
|
|
|
uint32 i, j;
|
|
|
|
NativeSymbol temp;
|
|
|
|
|
|
|
|
for (i = 0; i < n_native_symbols - 1; i++) {
|
|
|
|
for (j = i + 1; j < n_native_symbols; j++) {
|
2021-10-08 09:47:11 +00:00
|
|
|
if (strcmp(native_symbols[i].symbol, native_symbols[j].symbol)
|
|
|
|
> 0) {
|
2020-03-04 12:12:38 +00:00
|
|
|
temp = native_symbols[i];
|
|
|
|
native_symbols[i] = native_symbols[j];
|
|
|
|
native_symbols[j] = temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-07-31 12:54:03 +00:00
|
|
|
#else
|
|
|
|
static void
|
2021-10-08 09:47:11 +00:00
|
|
|
swap_symbol(NativeSymbol *left, NativeSymbol *right)
|
2020-07-31 12:54:03 +00:00
|
|
|
{
|
|
|
|
NativeSymbol temp = *left;
|
|
|
|
*left = *right;
|
|
|
|
*right = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-08 09:47:11 +00:00
|
|
|
quick_sort_symbols(NativeSymbol *native_symbols, int left, int right)
|
2020-07-31 12:54:03 +00:00
|
|
|
{
|
|
|
|
NativeSymbol base_symbol;
|
|
|
|
int pin_left = left;
|
|
|
|
int pin_right = right;
|
|
|
|
|
|
|
|
if (left >= right) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
base_symbol = native_symbols[left];
|
|
|
|
while (left < right) {
|
|
|
|
while (left < right
|
2021-10-08 09:47:11 +00:00
|
|
|
&& strcmp(native_symbols[right].symbol, base_symbol.symbol)
|
|
|
|
> 0) {
|
2020-07-31 12:54:03 +00:00
|
|
|
right--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (left < right) {
|
|
|
|
swap_symbol(&native_symbols[left], &native_symbols[right]);
|
|
|
|
left++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (left < right
|
2021-10-08 09:47:11 +00:00
|
|
|
&& strcmp(native_symbols[left].symbol, base_symbol.symbol) < 0) {
|
2020-07-31 12:54:03 +00:00
|
|
|
left++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (left < right) {
|
|
|
|
swap_symbol(&native_symbols[left], &native_symbols[right]);
|
|
|
|
right--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
native_symbols[left] = base_symbol;
|
|
|
|
|
|
|
|
quick_sort_symbols(native_symbols, pin_left, left - 1);
|
|
|
|
quick_sort_symbols(native_symbols, left + 1, pin_right);
|
|
|
|
}
|
|
|
|
#endif /* end of ENABLE_QUICKSORT */
|
2020-03-04 12:12:38 +00:00
|
|
|
|
2019-05-07 02:18:18 +00:00
|
|
|
static void *
|
2020-03-04 12:12:38 +00:00
|
|
|
lookup_symbol(NativeSymbol *native_symbols, uint32 n_native_symbols,
|
2020-04-01 04:52:08 +00:00
|
|
|
const char *symbol, const char **p_signature, void **p_attachment)
|
2019-05-07 02:18:18 +00:00
|
|
|
{
|
|
|
|
int low = 0, mid, ret;
|
2020-08-26 10:33:29 +00:00
|
|
|
int high = (int32)n_native_symbols - 1;
|
2019-05-07 02:18:18 +00:00
|
|
|
|
|
|
|
while (low <= high) {
|
|
|
|
mid = (low + high) / 2;
|
2020-03-04 12:12:38 +00:00
|
|
|
ret = strcmp(symbol, native_symbols[mid].symbol);
|
|
|
|
if (ret == 0) {
|
|
|
|
*p_signature = native_symbols[mid].signature;
|
2020-04-01 04:52:08 +00:00
|
|
|
*p_attachment = native_symbols[mid].attachment;
|
2020-03-04 12:12:38 +00:00
|
|
|
return native_symbols[mid].func_ptr;
|
|
|
|
}
|
2019-05-07 02:18:18 +00:00
|
|
|
else if (ret < 0)
|
|
|
|
high = mid - 1;
|
|
|
|
else
|
|
|
|
low = mid + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2023-02-13 07:06:04 +00:00
|
|
|
/**
|
|
|
|
* allow func_type and all outputs, like p_signature, p_attachment and
|
|
|
|
* p_call_conv_raw to be NULL
|
|
|
|
*/
|
2021-10-08 09:47:11 +00:00
|
|
|
void *
|
2020-03-04 12:12:38 +00:00
|
|
|
wasm_native_resolve_symbol(const char *module_name, const char *field_name,
|
2020-04-01 04:52:08 +00:00
|
|
|
const WASMType *func_type, const char **p_signature,
|
|
|
|
void **p_attachment, bool *p_call_conv_raw)
|
2020-03-04 12:12:38 +00:00
|
|
|
{
|
|
|
|
NativeSymbolsNode *node, *node_next;
|
|
|
|
const char *signature = NULL;
|
2020-04-01 04:52:08 +00:00
|
|
|
void *func_ptr = NULL, *attachment;
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
|
2020-03-04 12:12:38 +00:00
|
|
|
node = g_native_symbols_list;
|
|
|
|
while (node) {
|
|
|
|
node_next = node->next;
|
|
|
|
if (!strcmp(node->module_name, module_name)) {
|
2021-10-08 09:47:11 +00:00
|
|
|
if ((func_ptr =
|
|
|
|
lookup_symbol(node->native_symbols, node->n_native_symbols,
|
|
|
|
field_name, &signature, &attachment))
|
2020-03-04 12:12:38 +00:00
|
|
|
|| (field_name[0] == '_'
|
2021-10-08 09:47:11 +00:00
|
|
|
&& (func_ptr = lookup_symbol(
|
|
|
|
node->native_symbols, node->n_native_symbols,
|
|
|
|
field_name + 1, &signature, &attachment))))
|
|
|
|
break;
|
2020-03-04 12:12:38 +00:00
|
|
|
}
|
|
|
|
node = node_next;
|
|
|
|
}
|
2019-05-07 02:18:18 +00:00
|
|
|
|
2023-02-13 07:06:04 +00:00
|
|
|
if (!p_signature || !p_attachment || !p_call_conv_raw)
|
|
|
|
return func_ptr;
|
|
|
|
|
2020-03-04 12:12:38 +00:00
|
|
|
if (func_ptr) {
|
|
|
|
if (signature && signature[0] != '\0') {
|
|
|
|
/* signature is not empty, check its format */
|
2023-02-13 07:06:04 +00:00
|
|
|
if (!func_type || !check_symbol_signature(func_type, signature)) {
|
2021-10-08 09:47:11 +00:00
|
|
|
#if WASM_ENABLE_WAMR_COMPILER == 0
|
|
|
|
/* Output warning except running aot compiler */
|
2020-03-04 12:12:38 +00:00
|
|
|
LOG_WARNING("failed to check signature '%s' and resolve "
|
|
|
|
"pointer params for import function (%s %s)\n",
|
|
|
|
signature, module_name, field_name);
|
2020-04-13 02:49:40 +00:00
|
|
|
#endif
|
2020-03-04 12:12:38 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* Save signature for runtime to do pointer check and
|
|
|
|
address conversion */
|
|
|
|
*p_signature = signature;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* signature is empty */
|
|
|
|
*p_signature = NULL;
|
2020-04-01 04:52:08 +00:00
|
|
|
|
|
|
|
*p_attachment = attachment;
|
|
|
|
*p_call_conv_raw = node->call_conv_raw;
|
2020-03-04 12:12:38 +00:00
|
|
|
}
|
2019-05-07 02:18:18 +00:00
|
|
|
|
2020-03-04 12:12:38 +00:00
|
|
|
return func_ptr;
|
|
|
|
}
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
|
2020-04-01 04:52:08 +00:00
|
|
|
static bool
|
2021-10-08 09:47:11 +00:00
|
|
|
register_natives(const char *module_name, NativeSymbol *native_symbols,
|
|
|
|
uint32 n_native_symbols, bool call_conv_raw)
|
2020-03-04 12:12:38 +00:00
|
|
|
{
|
|
|
|
NativeSymbolsNode *node;
|
2020-07-31 12:54:03 +00:00
|
|
|
#if ENABLE_SORT_DEBUG != 0
|
|
|
|
struct timeval start;
|
|
|
|
struct timeval end;
|
|
|
|
unsigned long timer;
|
|
|
|
#endif
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
|
2020-03-10 11:54:44 +00:00
|
|
|
if (!(node = wasm_runtime_malloc(sizeof(NativeSymbolsNode))))
|
2020-03-04 12:12:38 +00:00
|
|
|
return false;
|
2020-09-18 10:04:56 +00:00
|
|
|
#if WASM_ENABLE_MEMORY_TRACING != 0
|
|
|
|
os_printf("Register native, size: %u\n", sizeof(NativeSymbolsNode));
|
|
|
|
#endif
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
|
2020-03-04 12:12:38 +00:00
|
|
|
node->module_name = module_name;
|
|
|
|
node->native_symbols = native_symbols;
|
|
|
|
node->n_native_symbols = n_native_symbols;
|
2020-04-01 04:52:08 +00:00
|
|
|
node->call_conv_raw = call_conv_raw;
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
|
2021-02-07 03:05:48 +00:00
|
|
|
/* Add to list head */
|
|
|
|
node->next = g_native_symbols_list;
|
|
|
|
g_native_symbols_list = node;
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
|
2020-07-31 12:54:03 +00:00
|
|
|
#if ENABLE_SORT_DEBUG != 0
|
|
|
|
gettimeofday(&start, NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLE_QUICKSORT == 0
|
2020-03-04 12:12:38 +00:00
|
|
|
sort_symbol_ptr(native_symbols, n_native_symbols);
|
2020-07-31 12:54:03 +00:00
|
|
|
#else
|
|
|
|
quick_sort_symbols(native_symbols, 0, (int)(n_native_symbols - 1));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLE_SORT_DEBUG != 0
|
|
|
|
gettimeofday(&end, NULL);
|
2021-10-08 09:47:11 +00:00
|
|
|
timer =
|
|
|
|
1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);
|
|
|
|
LOG_ERROR("module_name: %s, nums: %d, sorted used: %ld us", module_name,
|
|
|
|
n_native_symbols, timer);
|
2020-07-31 12:54:03 +00:00
|
|
|
#endif
|
2020-03-04 12:12:38 +00:00
|
|
|
return true;
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 04:52:08 +00:00
|
|
|
bool
|
|
|
|
wasm_native_register_natives(const char *module_name,
|
|
|
|
NativeSymbol *native_symbols,
|
|
|
|
uint32 n_native_symbols)
|
|
|
|
{
|
2021-10-08 09:47:11 +00:00
|
|
|
return register_natives(module_name, native_symbols, n_native_symbols,
|
|
|
|
false);
|
2020-04-01 04:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
wasm_native_register_natives_raw(const char *module_name,
|
|
|
|
NativeSymbol *native_symbols,
|
|
|
|
uint32 n_native_symbols)
|
|
|
|
{
|
2021-10-08 09:47:11 +00:00
|
|
|
return register_natives(module_name, native_symbols, n_native_symbols,
|
|
|
|
true);
|
2020-04-01 04:52:08 +00:00
|
|
|
}
|
|
|
|
|
2022-10-28 03:03:39 +00:00
|
|
|
bool
|
|
|
|
wasm_native_unregister_natives(const char *module_name,
|
|
|
|
NativeSymbol *native_symbols)
|
|
|
|
{
|
|
|
|
NativeSymbolsNode **prevp;
|
|
|
|
NativeSymbolsNode *node;
|
|
|
|
|
|
|
|
prevp = &g_native_symbols_list;
|
|
|
|
while ((node = *prevp) != NULL) {
|
|
|
|
if (node->native_symbols == native_symbols
|
|
|
|
&& !strcmp(node->module_name, module_name)) {
|
|
|
|
*prevp = node->next;
|
|
|
|
wasm_runtime_free(node);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
prevp = &node->next;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-04 12:12:38 +00:00
|
|
|
bool
|
|
|
|
wasm_native_init()
|
|
|
|
{
|
2022-12-02 03:41:40 +00:00
|
|
|
#if WASM_ENABLE_SPEC_TEST != 0 || WASM_ENABLE_LIBC_BUILTIN != 0 \
|
|
|
|
|| WASM_ENABLE_BASE_LIB != 0 || WASM_ENABLE_LIBC_EMCC != 0 \
|
|
|
|
|| WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \
|
|
|
|
|| WASM_ENABLE_APP_FRAMEWORK != 0 || WASM_ENABLE_LIBC_WASI != 0 \
|
2022-12-06 13:11:27 +00:00
|
|
|
|| WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0
|
2020-03-04 12:12:38 +00:00
|
|
|
NativeSymbol *native_symbols;
|
|
|
|
uint32 n_native_symbols;
|
2022-11-28 01:44:33 +00:00
|
|
|
#endif
|
2019-05-07 02:18:18 +00:00
|
|
|
|
2020-03-04 12:12:38 +00:00
|
|
|
#if WASM_ENABLE_LIBC_BUILTIN != 0
|
|
|
|
n_native_symbols = get_libc_builtin_export_apis(&native_symbols);
|
2021-10-08 09:47:11 +00:00
|
|
|
if (!wasm_native_register_natives("env", native_symbols, n_native_symbols))
|
2022-09-08 06:22:34 +00:00
|
|
|
goto fail;
|
2020-06-02 06:53:06 +00:00
|
|
|
#endif /* WASM_ENABLE_LIBC_BUILTIN */
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
|
2020-04-30 09:52:11 +00:00
|
|
|
#if WASM_ENABLE_SPEC_TEST
|
2020-03-04 12:12:38 +00:00
|
|
|
n_native_symbols = get_spectest_export_apis(&native_symbols);
|
2021-10-08 09:47:11 +00:00
|
|
|
if (!wasm_native_register_natives("spectest", native_symbols,
|
|
|
|
n_native_symbols))
|
2022-09-08 06:22:34 +00:00
|
|
|
goto fail;
|
2020-04-30 09:52:11 +00:00
|
|
|
#endif /* WASM_ENABLE_SPEC_TEST */
|
2020-03-04 12:12:38 +00:00
|
|
|
|
|
|
|
#if WASM_ENABLE_LIBC_WASI != 0
|
|
|
|
n_native_symbols = get_libc_wasi_export_apis(&native_symbols);
|
2021-10-08 09:47:11 +00:00
|
|
|
if (!wasm_native_register_natives("wasi_unstable", native_symbols,
|
|
|
|
n_native_symbols))
|
2022-09-08 06:22:34 +00:00
|
|
|
goto fail;
|
2021-10-08 09:47:11 +00:00
|
|
|
if (!wasm_native_register_natives("wasi_snapshot_preview1", native_symbols,
|
|
|
|
n_native_symbols))
|
2022-09-08 06:22:34 +00:00
|
|
|
goto fail;
|
2020-03-04 12:12:38 +00:00
|
|
|
#endif
|
2019-05-07 02:18:18 +00:00
|
|
|
|
2020-03-04 12:12:38 +00:00
|
|
|
#if WASM_ENABLE_BASE_LIB != 0
|
|
|
|
n_native_symbols = get_base_lib_export_apis(&native_symbols);
|
|
|
|
if (n_native_symbols > 0
|
2021-10-08 09:47:11 +00:00
|
|
|
&& !wasm_native_register_natives("env", native_symbols,
|
|
|
|
n_native_symbols))
|
2022-09-08 06:22:34 +00:00
|
|
|
goto fail;
|
2020-03-04 12:12:38 +00:00
|
|
|
#endif
|
2019-05-07 02:18:18 +00:00
|
|
|
|
2020-03-04 12:12:38 +00:00
|
|
|
#if WASM_ENABLE_APP_FRAMEWORK != 0
|
|
|
|
n_native_symbols = get_ext_lib_export_apis(&native_symbols);
|
|
|
|
if (n_native_symbols > 0
|
2021-10-08 09:47:11 +00:00
|
|
|
&& !wasm_native_register_natives("env", native_symbols,
|
|
|
|
n_native_symbols))
|
2022-09-08 06:22:34 +00:00
|
|
|
goto fail;
|
2020-03-04 12:12:38 +00:00
|
|
|
#endif
|
2019-05-07 02:18:18 +00:00
|
|
|
|
2020-06-15 11:04:04 +00:00
|
|
|
#if WASM_ENABLE_LIB_PTHREAD != 0
|
|
|
|
if (!lib_pthread_init())
|
2022-09-08 06:22:34 +00:00
|
|
|
goto fail;
|
2020-06-15 11:04:04 +00:00
|
|
|
|
|
|
|
n_native_symbols = get_lib_pthread_export_apis(&native_symbols);
|
|
|
|
if (n_native_symbols > 0
|
2021-10-08 09:47:11 +00:00
|
|
|
&& !wasm_native_register_natives("env", native_symbols,
|
|
|
|
n_native_symbols))
|
2022-09-08 06:22:34 +00:00
|
|
|
goto fail;
|
2020-06-15 11:04:04 +00:00
|
|
|
#endif
|
|
|
|
|
2022-12-06 13:11:27 +00:00
|
|
|
#if WASM_ENABLE_LIB_WASI_THREADS != 0
|
2022-12-13 13:33:27 +00:00
|
|
|
if (!lib_wasi_threads_init())
|
|
|
|
goto fail;
|
|
|
|
|
2022-12-06 13:11:27 +00:00
|
|
|
n_native_symbols = get_lib_wasi_threads_export_apis(&native_symbols);
|
|
|
|
if (n_native_symbols > 0
|
|
|
|
&& !wasm_native_register_natives("wasi", native_symbols,
|
|
|
|
n_native_symbols))
|
|
|
|
goto fail;
|
|
|
|
#endif
|
|
|
|
|
2020-10-22 08:18:37 +00:00
|
|
|
#if WASM_ENABLE_LIBC_EMCC != 0
|
|
|
|
n_native_symbols = get_libc_emcc_export_apis(&native_symbols);
|
|
|
|
if (n_native_symbols > 0
|
2021-10-08 09:47:11 +00:00
|
|
|
&& !wasm_native_register_natives("env", native_symbols,
|
|
|
|
n_native_symbols))
|
2022-09-08 06:22:34 +00:00
|
|
|
goto fail;
|
2020-10-22 08:18:37 +00:00
|
|
|
#endif /* WASM_ENABLE_LIBC_EMCC */
|
|
|
|
|
2022-09-06 06:29:58 +00:00
|
|
|
#if WASM_ENABLE_LIB_RATS != 0
|
|
|
|
n_native_symbols = get_lib_rats_export_apis(&native_symbols);
|
|
|
|
if (n_native_symbols > 0
|
|
|
|
&& !wasm_native_register_natives("env", native_symbols,
|
|
|
|
n_native_symbols))
|
2022-09-08 06:22:34 +00:00
|
|
|
goto fail;
|
2022-09-06 06:29:58 +00:00
|
|
|
#endif /* WASM_ENABLE_LIB_RATS */
|
|
|
|
|
2022-10-12 04:09:29 +00:00
|
|
|
#if WASM_ENABLE_WASI_NN != 0
|
|
|
|
n_native_symbols = get_wasi_nn_export_apis(&native_symbols);
|
|
|
|
if (!wasm_native_register_natives("wasi_nn", native_symbols,
|
|
|
|
n_native_symbols))
|
2022-12-13 13:33:27 +00:00
|
|
|
goto fail;
|
2022-10-12 04:09:29 +00:00
|
|
|
#endif
|
|
|
|
|
2020-03-04 12:12:38 +00:00
|
|
|
return true;
|
2022-12-02 03:41:40 +00:00
|
|
|
#if WASM_ENABLE_SPEC_TEST != 0 || WASM_ENABLE_LIBC_BUILTIN != 0 \
|
|
|
|
|| WASM_ENABLE_BASE_LIB != 0 || WASM_ENABLE_LIBC_EMCC != 0 \
|
|
|
|
|| WASM_ENABLE_LIB_RATS != 0 || WASM_ENABLE_WASI_NN != 0 \
|
|
|
|
|| WASM_ENABLE_APP_FRAMEWORK != 0 || WASM_ENABLE_LIBC_WASI != 0 \
|
2022-12-06 13:11:27 +00:00
|
|
|
|| WASM_ENABLE_LIB_PTHREAD != 0 || WASM_ENABLE_LIB_WASI_THREADS != 0
|
2022-09-08 06:22:34 +00:00
|
|
|
fail:
|
|
|
|
wasm_native_destroy();
|
|
|
|
return false;
|
2022-11-28 01:44:33 +00:00
|
|
|
#endif
|
2020-03-04 12:12:38 +00:00
|
|
|
}
|
2019-05-07 02:18:18 +00:00
|
|
|
|
2020-03-04 12:12:38 +00:00
|
|
|
void
|
|
|
|
wasm_native_destroy()
|
|
|
|
{
|
|
|
|
NativeSymbolsNode *node, *node_next;
|
2019-05-07 02:18:18 +00:00
|
|
|
|
2020-06-15 11:04:04 +00:00
|
|
|
#if WASM_ENABLE_LIB_PTHREAD != 0
|
|
|
|
lib_pthread_destroy();
|
|
|
|
#endif
|
|
|
|
|
2022-12-13 13:33:27 +00:00
|
|
|
#if WASM_ENABLE_LIB_WASI_THREADS != 0
|
|
|
|
lib_wasi_threads_destroy();
|
|
|
|
#endif
|
|
|
|
|
2020-03-04 12:12:38 +00:00
|
|
|
node = g_native_symbols_list;
|
|
|
|
while (node) {
|
|
|
|
node_next = node->next;
|
2020-03-10 11:54:44 +00:00
|
|
|
wasm_runtime_free(node);
|
2020-03-04 12:12:38 +00:00
|
|
|
node = node_next;
|
|
|
|
}
|
2019-05-07 02:18:18 +00:00
|
|
|
|
2021-02-07 03:05:48 +00:00
|
|
|
g_native_symbols_list = NULL;
|
2019-05-07 02:18:18 +00:00
|
|
|
}
|