mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-02-06 06:55:07 +00:00
re-org bh_definition.c && introduce wamr fast interpreter (#189)
Co-authored-by: Xu Jun
This commit is contained in:
parent
cfcaca3d35
commit
057c849fc0
|
@ -8,6 +8,8 @@ WAMR project reused some components from other open source project:
|
||||||
- **freebsd libm**: used in core/shared/platform/alios/bh_math.c
|
- **freebsd libm**: used in core/shared/platform/alios/bh_math.c
|
||||||
- **littlevgl**: for the gui samples and wrapped the wasm graphic layer.
|
- **littlevgl**: for the gui samples and wrapped the wasm graphic layer.
|
||||||
|
|
||||||
|
The WAMR fast interpreter is a clean room development. We would acknowledge the inspirations by [WASM3](https://github.com/wasm3/wasm3) open source project for the approach of pre-calculated oprand stack location.
|
||||||
|
|
||||||
## Licenses
|
## Licenses
|
||||||
|
|
||||||
### wasmtime
|
### wasmtime
|
||||||
|
|
22
README.md
22
README.md
|
@ -20,12 +20,13 @@ iwasm VM core
|
||||||
|
|
||||||
### key features
|
### key features
|
||||||
|
|
||||||
- [Embeddable with the supporting C API's](./doc/embed_wamr.md)
|
- 100% compliant to the W3C WASM MVP
|
||||||
- Small runtime binary size (85K for interpreter and 50K for AoT) and low memory usage
|
- Small runtime binary size (85K for interpreter and 50K for AoT) and low memory usage
|
||||||
- Near to native speed by AoT
|
- Near to native speed by AoT
|
||||||
- Unique AoT support for embedded systems which have no system loaders
|
- Self-implemented module loader enables AoT working cross Linux, SGX and MCU systems
|
||||||
- Choices of WASM application libc support: the built-in libc subset for the embedded environment or [WASI](https://github.com/WebAssembly/WASI) for standard libc
|
- Choices of WASM application libc support: the built-in libc subset for the embedded environment or [WASI](https://github.com/WebAssembly/WASI) for standard libc
|
||||||
- [The mechanism for exporting native API's to WASM applications](./doc/export_native_api.md)
|
- [Embeddable with the supporting C API's](./doc/embed_wamr.md)
|
||||||
|
- [The mechanism for exporting native API's to WASM applications](./doc/export_native_api.md)
|
||||||
|
|
||||||
### Supported architectures and platforms
|
### Supported architectures and platforms
|
||||||
|
|
||||||
|
@ -36,11 +37,11 @@ The iwasm supports the following architectures:
|
||||||
- MIPS
|
- MIPS
|
||||||
- XTENSA
|
- XTENSA
|
||||||
|
|
||||||
Following platforms are supported:
|
Following platforms are supported. Refer to [WAMR porting guide](./doc/port_wamr.md) for how to port WAMR to a new platform.
|
||||||
|
|
||||||
- [Linux](./doc/build_wamr.md#linux), [Zephyr](./doc/build_wamr.md#zephyr), [MacOS](./doc/build_wamr.md#macos), [VxWorks](./doc/build_wamr.md#vxworks), [AliOS-Things](./doc/build_wamr.md#alios-things), [Intel Software Guard Extention (Linux)](./doc/build_wamr.md#linux-sgx-intel-software-guard-extention), [Android](./doc/build_wamr.md#android)
|
- [Linux](./doc/build_wamr.md#linux), [Zephyr](./doc/build_wamr.md#zephyr), [MacOS](./doc/build_wamr.md#macos), [VxWorks](./doc/build_wamr.md#vxworks), [AliOS-Things](./doc/build_wamr.md#alios-things), [Intel Software Guard Extention (Linux)](./doc/build_wamr.md#linux-sgx-intel-software-guard-extention), [Android](./doc/build_wamr.md#android)
|
||||||
|
|
||||||
Refer to [WAMR porting guide](./doc/port_wamr.md) for how to port WAMR to a new platform.
|
|
||||||
|
|
||||||
### Build wamrc AoT compiler
|
### Build wamrc AoT compiler
|
||||||
|
|
||||||
|
@ -76,27 +77,26 @@ Browse the folder [core/app-framework](./core/app-framework) for how to extend
|
||||||
|
|
||||||
# Remote application management
|
# Remote application management
|
||||||
|
|
||||||
The WAMR application manager supports remote application management from the host environment or the cloud through any physical communications such as TCP, UPD, UART, BLE, etc. Its modular design makes it able to support application management for different managed runtimes.
|
The WAMR application manager supports [remote application management](./core/app-mgr) from the host environment or the cloud through any physical communications such as TCP, UPD, UART, BLE, etc. Its modular design makes it able to support application management for different managed runtimes.
|
||||||
|
|
||||||
The tool [host_tool](./test-tools/host-tool) communicates to the WAMR app manager for installing/uninstalling the WASM applications on companion chip from the host system. And the [IoT App Store Demo](./test-tools/IoT-APP-Store-Demo/) shows the conception of remotely managing the device applications from the cloud.
|
The tool [host_tool](./test-tools/host-tool) communicates to the WAMR app manager for installing/uninstalling the WASM applications on companion chip from the host system. And the [IoT App Store Demo](./test-tools/IoT-APP-Store-Demo/) shows the conception of remotely managing the device applications from the cloud.
|
||||||
|
|
||||||
Browse the folder [core/app-mgr](./core/app-mgr) for the details.
|
|
||||||
|
|
||||||
WAMR SDK
|
WAMR SDK
|
||||||
==========
|
==========
|
||||||
|
|
||||||
Usually there are two tasks for integrating the WAMR into a particular project:
|
Usually there are two tasks for integrating the WAMR into a particular project:
|
||||||
|
|
||||||
- Select what WAMR components (vmcore, libc, app-mgr, app-framework components) to be integrated, and get the associated source files added into the project building configuration
|
- Select what WAMR components (vmcore, libc, app-mgr, app-framework components) to be integrated, and get the associated source files added into the project building configuration
|
||||||
- Generate the APP SDK for developing the WASM apps on the selected libc and framework components
|
- Generate the APP SDK for developing the WASM apps on the selected libc and framework components
|
||||||
|
|
||||||
The **[WAMR SDK](./wamr-sdk)** tools is helpful to finish the two tasks quickly. It supports menu configuration for selecting WAMR components and builds the WAMR to a SDK package that includes **runtime SDK** and **APP SDK**. The runtime SDK is used for building the native application and the APP SDK should be shipped to WASM application developers.
|
The **[WAMR SDK](./wamr-sdk)** tools is helpful to finish the two tasks quickly. It supports menu configuration for selecting WAMR components and builds the WAMR to a SDK package that includes **runtime SDK** and **APP SDK**. The runtime SDK is used for building the native application and the APP SDK should be shipped to WASM application developers.
|
||||||
|
|
||||||
|
|
||||||
Samples
|
Samples
|
||||||
=================
|
=================
|
||||||
|
|
||||||
The WAMR samples integrate the iwasm VM core, application manager and selected application framework components. The samples are located in folder [samples](./samples):
|
The WAMR [samples](./samples) integrate the iwasm VM core, application manager and selected application framework components.
|
||||||
- **[Simple](./samples/simple/README.md)**: The runtime is integrated with most of the WAMR APP libraries, and a few WASM applications are provided for testing the WAMR APP API set. It uses **built-in libc** and executes apps in **interpreter** mode by default.
|
- **[Simple](./samples/simple/README.md)**: The runtime is integrated with most of the WAMR APP libraries, and a few WASM applications are provided for testing the WAMR APP API set. It uses **built-in libc** and executes apps in **interpreter** mode by default.
|
||||||
- **[littlevgl](./samples/littlevgl/README.md)**: Demonstrating the graphic user interface application usage on WAMR. The whole [LittlevGL](https://github.com/littlevgl/) 2D user graphic library and the UI application is built into WASM application. It uses **WASI libc** and executes apps in **AoT mode** by default.
|
- **[littlevgl](./samples/littlevgl/README.md)**: Demonstrating the graphic user interface application usage on WAMR. The whole [LittlevGL](https://github.com/littlevgl/) 2D user graphic library and the UI application is built into WASM application. It uses **WASI libc** and executes apps in **AoT mode** by default.
|
||||||
- **[gui](./samples/gui/README.md)**: Moved the [LittlevGL](https://github.com/littlevgl/) library into the runtime and defined a WASM application interface by wrapping the littlevgl API. It uses **WASI libc** and executes apps in **interpreter** mode by default.
|
- **[gui](./samples/gui/README.md)**: Moved the [LittlevGL](https://github.com/littlevgl/) library into the runtime and defined a WASM application interface by wrapping the littlevgl API. It uses **WASI libc** and executes apps in **interpreter** mode by default.
|
||||||
|
|
|
@ -127,4 +127,11 @@ if (WAMR_BUILD_LIBC_WASI EQUAL 1)
|
||||||
else ()
|
else ()
|
||||||
message (" Libc WASI disbled")
|
message (" Libc WASI disbled")
|
||||||
endif ()
|
endif ()
|
||||||
|
if (WAMR_BUILD_FAST_INTERP EQUAL 1)
|
||||||
|
add_definitions (-DWASM_ENABLE_FAST_INTERP=1)
|
||||||
|
message (" Fast interpreter enabled")
|
||||||
|
else ()
|
||||||
|
add_definitions (-DWASM_ENABLE_FAST_INTERP=0)
|
||||||
|
message (" Fast interpreter disbled")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ Application framework
|
||||||
|
|
||||||
This folder "app-native-shared" is for the source files shared by both WASM APP and native runtime
|
This folder "app-native-shared" is for the source files shared by both WASM APP and native runtime
|
||||||
|
|
||||||
- The c files in this directory are compiled into both the WASM APP and runtime.
|
- The c files in this directory are compiled into both the WASM APP and runtime.
|
||||||
- The header files for distributing to SDK are placed in the "bi-inc" folder.
|
- The header files for distributing to SDK are placed in the "bi-inc" folder.
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ This folder "template" contains a pre-defined directory structure for a framewor
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Every other subfolder is framework component. Each component contains two library parts: **app and native**.
|
Every other subfolder is framework component. Each component contains two library parts: **app and native**.
|
||||||
|
|
||||||
- The "base" component provide timer API and inter-app communication support. It must be enabled if other components are selected.
|
- The "base" component provide timer API and inter-app communication support. It must be enabled if other components are selected.
|
||||||
- Under the "app" folder of a component, the subfolder "wa_inc" holds all header files that should be included by the WASM applications
|
- Under the "app" folder of a component, the subfolder "wa_inc" holds all header files that should be included by the WASM applications
|
||||||
|
@ -85,13 +85,13 @@ Generally you should follow following steps to create a new component:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
//use right signature for your functions
|
//use right signature for your functions
|
||||||
EXPORT_WASM_API_WITH_SIG(wasm_my_component_api_1, "(i*~)i"),
|
EXPORT_WASM_API_WITH_SIG(wasm_my_component_api_1, "(i*~)i"),
|
||||||
EXPORT_WASM_API_WITH_SIG(wasm_my_component_api_2, "(i)i"),
|
EXPORT_WASM_API_WITH_SIG(wasm_my_component_api_2, "(i)i"),
|
||||||
```
|
```
|
||||||
|
|
||||||
- Ensure "wasm_lib.cmake" is provided as it will be included by the WAMR SDK building script
|
- Ensure "wasm_lib.cmake" is provided as it will be included by the WAMR SDK building script
|
||||||
|
|
||||||
- Add a definition in "wasm_lib.cmake" for your component, e.g.
|
- Add a definition in "wasm_lib.cmake" for your component, e.g.
|
||||||
|
|
||||||
```cmake
|
```cmake
|
||||||
add_definitions (-DAPP_FRAMEWORK_MY_COMPONENT)
|
add_definitions (-DAPP_FRAMEWORK_MY_COMPONENT)
|
||||||
|
@ -101,12 +101,12 @@ Generally you should follow following steps to create a new component:
|
||||||
|
|
||||||
```
|
```
|
||||||
#include "lib_export.h"
|
#include "lib_export.h"
|
||||||
|
|
||||||
...
|
...
|
||||||
#ifdef APP_FRAMEWORK_MY_COMPONENT // this definition is created in wasm_lib.cmake
|
#ifdef APP_FRAMEWORK_MY_COMPONENT // this definition is created in wasm_lib.cmake
|
||||||
#include "my_component_native_api.h"
|
#include "my_component_native_api.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static NativeSymbol extended_native_symbol_defs[] = {
|
static NativeSymbol extended_native_symbol_defs[] = {
|
||||||
...
|
...
|
||||||
#ifdef APP_FRAMEWORK_MY_COMPONENT
|
#ifdef APP_FRAMEWORK_MY_COMPONENT
|
||||||
|
@ -115,7 +115,7 @@ Generally you should follow following steps to create a new component:
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Sensor component working flow
|
## Sensor component working flow
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ static NativeSymbol extended_native_symbol_defs[] = {
|
||||||
#include "base_lib.inl"
|
#include "base_lib.inl"
|
||||||
};
|
};
|
||||||
|
|
||||||
int get_base_lib_export_apis(NativeSymbol **p_base_lib_apis)
|
uint32 get_base_lib_export_apis(NativeSymbol **p_base_lib_apis)
|
||||||
{
|
{
|
||||||
*p_base_lib_apis = extended_native_symbol_defs;
|
*p_base_lib_apis = extended_native_symbol_defs;
|
||||||
return sizeof(extended_native_symbol_defs) / sizeof(NativeSymbol);
|
return sizeof(extended_native_symbol_defs) / sizeof(NativeSymbol);
|
||||||
|
|
|
@ -1703,7 +1703,7 @@ create_sections(const uint8 *buf, uint32 size,
|
||||||
|
|
||||||
memset(section, 0, sizeof(AOTSection));
|
memset(section, 0, sizeof(AOTSection));
|
||||||
section->section_type = (int32)section_type;
|
section->section_type = (int32)section_type;
|
||||||
section->section_body = p;
|
section->section_body = (uint8*)p;
|
||||||
section->section_body_size = section_size;
|
section->section_body_size = section_size;
|
||||||
|
|
||||||
if (section_type == AOT_SECTION_TYPE_TEXT) {
|
if (section_type == AOT_SECTION_TYPE_TEXT) {
|
||||||
|
|
|
@ -7,18 +7,13 @@
|
||||||
#define _WASM_NATIVE_H
|
#define _WASM_NATIVE_H
|
||||||
|
|
||||||
#include "bh_common.h"
|
#include "bh_common.h"
|
||||||
|
#include "../include/wasm_export.h"
|
||||||
#include "../interpreter/wasm.h"
|
#include "../interpreter/wasm.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct NativeSymbol {
|
|
||||||
const char *symbol;
|
|
||||||
void *func_ptr;
|
|
||||||
const char *signature;
|
|
||||||
} NativeSymbol;
|
|
||||||
|
|
||||||
typedef struct NativeSymbolsNode {
|
typedef struct NativeSymbolsNode {
|
||||||
struct NativeSymbolsNode *next;
|
struct NativeSymbolsNode *next;
|
||||||
const char *module_name;
|
const char *module_name;
|
||||||
|
|
|
@ -50,6 +50,49 @@ wasm_runtime_destroy()
|
||||||
vm_thread_sys_destroy();
|
vm_thread_sys_destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
wasm_runtime_full_init(RuntimeInitArgs *init_args)
|
||||||
|
{
|
||||||
|
if (init_args->mem_alloc_type == Alloc_With_Pool) {
|
||||||
|
void *heap_buf = init_args->mem_alloc.pool.heap_buf;
|
||||||
|
uint32 heap_size = init_args->mem_alloc.pool.heap_size;
|
||||||
|
if (bh_memory_init_with_pool(heap_buf, heap_size) != 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (init_args->mem_alloc_type == Alloc_With_Allocator) {
|
||||||
|
void *malloc_func = init_args->mem_alloc.allocator.malloc_func;
|
||||||
|
void *free_func = init_args->mem_alloc.allocator.free_func;
|
||||||
|
if (bh_memory_init_with_allocator(malloc_func, free_func) != 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!wasm_runtime_init())
|
||||||
|
goto fail1;
|
||||||
|
|
||||||
|
if (init_args->n_native_symbols > 0
|
||||||
|
&& !wasm_runtime_register_natives(init_args->native_module_name,
|
||||||
|
init_args->native_symbols,
|
||||||
|
init_args->n_native_symbols))
|
||||||
|
goto fail2;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
fail2:
|
||||||
|
wasm_runtime_destroy();
|
||||||
|
fail1:
|
||||||
|
bh_memory_destroy();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wasm_runtime_full_destroy()
|
||||||
|
{
|
||||||
|
wasm_runtime_destroy();
|
||||||
|
bh_memory_destroy();
|
||||||
|
}
|
||||||
|
|
||||||
PackageType
|
PackageType
|
||||||
get_package_type(const uint8 *buf, uint32 size)
|
get_package_type(const uint8 *buf, uint32 size)
|
||||||
{
|
{
|
||||||
|
@ -202,7 +245,7 @@ wasm_runtime_get_module_inst(WASMExecEnv *exec_env)
|
||||||
}
|
}
|
||||||
|
|
||||||
WASMFunctionInstanceCommon *
|
WASMFunctionInstanceCommon *
|
||||||
wasm_runtime_lookup_function(const WASMModuleInstanceCommon *module_inst,
|
wasm_runtime_lookup_function(WASMModuleInstanceCommon * const module_inst,
|
||||||
const char *name,
|
const char *name,
|
||||||
const char *signature)
|
const char *signature)
|
||||||
{
|
{
|
||||||
|
@ -339,7 +382,7 @@ wasm_runtime_get_custom_data(WASMModuleInstanceCommon *module_inst)
|
||||||
#if WASM_ENABLE_INTERP != 0
|
#if WASM_ENABLE_INTERP != 0
|
||||||
if (module_inst->module_type == Wasm_Module_Bytecode)
|
if (module_inst->module_type == Wasm_Module_Bytecode)
|
||||||
return ((WASMModuleInstance*)module_inst)->custom_data;
|
return ((WASMModuleInstance*)module_inst)->custom_data;
|
||||||
#endif
|
#endif
|
||||||
#if WASM_ENABLE_AOT != 0
|
#if WASM_ENABLE_AOT != 0
|
||||||
if (module_inst->module_type == Wasm_Module_AoT)
|
if (module_inst->module_type == Wasm_Module_AoT)
|
||||||
return ((AOTModuleInstance*)module_inst)->custom_data.ptr;
|
return ((AOTModuleInstance*)module_inst)->custom_data.ptr;
|
||||||
|
@ -619,7 +662,7 @@ wasm_runtime_set_wasi_args(WASMModuleCommon *module,
|
||||||
const char *dir_list[], uint32 dir_count,
|
const char *dir_list[], uint32 dir_count,
|
||||||
const char *map_dir_list[], uint32 map_dir_count,
|
const char *map_dir_list[], uint32 map_dir_count,
|
||||||
const char *env_list[], uint32 env_count,
|
const char *env_list[], uint32 env_count,
|
||||||
const char *argv[], uint32 argc)
|
char *argv[], int argc)
|
||||||
{
|
{
|
||||||
WASIArguments *wasi_args = NULL;
|
WASIArguments *wasi_args = NULL;
|
||||||
|
|
||||||
|
@ -649,7 +692,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||||
const char *dir_list[], uint32 dir_count,
|
const char *dir_list[], uint32 dir_count,
|
||||||
const char *map_dir_list[], uint32 map_dir_count,
|
const char *map_dir_list[], uint32 map_dir_count,
|
||||||
const char *env[], uint32 env_count,
|
const char *env[], uint32 env_count,
|
||||||
const char *argv[], uint32 argc,
|
char *argv[], uint32 argc,
|
||||||
char *error_buf, uint32 error_buf_size)
|
char *error_buf, uint32 error_buf_size)
|
||||||
{
|
{
|
||||||
WASIContext *wasi_ctx;
|
WASIContext *wasi_ctx;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "bh_thread.h"
|
#include "bh_thread.h"
|
||||||
#include "wasm_exec_env.h"
|
#include "wasm_exec_env.h"
|
||||||
#include "wasm_native.h"
|
#include "wasm_native.h"
|
||||||
|
#include "../include/wasm_export.h"
|
||||||
#include "../interpreter/wasm.h"
|
#include "../interpreter/wasm.h"
|
||||||
#if WASM_ENABLE_LIBC_WASI != 0
|
#if WASM_ENABLE_LIBC_WASI != 0
|
||||||
#include "wasmtime_ssp.h"
|
#include "wasmtime_ssp.h"
|
||||||
|
@ -24,13 +25,6 @@ extern "C" {
|
||||||
#define wasm_malloc bh_malloc
|
#define wasm_malloc bh_malloc
|
||||||
#define wasm_free bh_free
|
#define wasm_free bh_free
|
||||||
|
|
||||||
/* Package Type */
|
|
||||||
typedef enum {
|
|
||||||
Wasm_Module_Bytecode = 0,
|
|
||||||
Wasm_Module_AoT,
|
|
||||||
Package_Type_Unknown = 0xFFFF
|
|
||||||
} PackageType;
|
|
||||||
|
|
||||||
typedef struct WASMModuleCommon {
|
typedef struct WASMModuleCommon {
|
||||||
/* Module type, for module loaded from WASM bytecode binary,
|
/* Module type, for module loaded from WASM bytecode binary,
|
||||||
this field is Wasm_Module_Bytecode, and this structure should
|
this field is Wasm_Module_Bytecode, and this structure should
|
||||||
|
@ -53,19 +47,6 @@ typedef struct WASMModuleInstanceCommon {
|
||||||
uint8 module_inst_data[1];
|
uint8 module_inst_data[1];
|
||||||
} WASMModuleInstanceCommon;
|
} WASMModuleInstanceCommon;
|
||||||
|
|
||||||
typedef void WASMFunctionInstanceCommon;
|
|
||||||
|
|
||||||
/* WASM section */
|
|
||||||
typedef struct WASMSection {
|
|
||||||
struct WASMSection *next;
|
|
||||||
/* section type */
|
|
||||||
int section_type;
|
|
||||||
/* section body, not include type and size */
|
|
||||||
const uint8 *section_body;
|
|
||||||
/* section body size */
|
|
||||||
uint32 section_body_size;
|
|
||||||
} WASMSection, AOTSection;
|
|
||||||
|
|
||||||
#if WASM_ENABLE_LIBC_WASI != 0
|
#if WASM_ENABLE_LIBC_WASI != 0
|
||||||
typedef struct WASIContext {
|
typedef struct WASIContext {
|
||||||
struct fd_table *curfds;
|
struct fd_table *curfds;
|
||||||
|
@ -74,6 +55,9 @@ typedef struct WASIContext {
|
||||||
} WASIContext;
|
} WASIContext;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef package_type_t PackageType;
|
||||||
|
typedef wasm_section_t WASMSection, AOTSection;
|
||||||
|
|
||||||
/* See wasm_export.h for description */
|
/* See wasm_export.h for description */
|
||||||
bool
|
bool
|
||||||
wasm_runtime_init();
|
wasm_runtime_init();
|
||||||
|
@ -82,6 +66,14 @@ wasm_runtime_init();
|
||||||
void
|
void
|
||||||
wasm_runtime_destroy();
|
wasm_runtime_destroy();
|
||||||
|
|
||||||
|
/* See wasm_export.h for description */
|
||||||
|
bool
|
||||||
|
wasm_runtime_full_init(RuntimeInitArgs *init_args);
|
||||||
|
|
||||||
|
/* See wasm_export.h for description */
|
||||||
|
void
|
||||||
|
wasm_runtime_full_destroy();
|
||||||
|
|
||||||
/* See wasm_export.h for description */
|
/* See wasm_export.h for description */
|
||||||
PackageType
|
PackageType
|
||||||
get_package_type(const uint8 *buf, uint32 size);
|
get_package_type(const uint8 *buf, uint32 size);
|
||||||
|
@ -112,7 +104,7 @@ wasm_runtime_deinstantiate(WASMModuleInstanceCommon *module_inst);
|
||||||
|
|
||||||
/* See wasm_export.h for description */
|
/* See wasm_export.h for description */
|
||||||
WASMFunctionInstanceCommon *
|
WASMFunctionInstanceCommon *
|
||||||
wasm_runtime_lookup_function(const WASMModuleInstanceCommon *module_inst,
|
wasm_runtime_lookup_function(WASMModuleInstanceCommon * const module_inst,
|
||||||
const char *name, const char *signature);
|
const char *name, const char *signature);
|
||||||
|
|
||||||
/* See wasm_export.h for description */
|
/* See wasm_export.h for description */
|
||||||
|
@ -245,7 +237,7 @@ wasm_runtime_set_wasi_args(WASMModuleCommon *module,
|
||||||
const char *dir_list[], uint32 dir_count,
|
const char *dir_list[], uint32 dir_count,
|
||||||
const char *map_dir_list[], uint32 map_dir_count,
|
const char *map_dir_list[], uint32 map_dir_count,
|
||||||
const char *env_list[], uint32 env_count,
|
const char *env_list[], uint32 env_count,
|
||||||
const char *argv[], uint32 argc);
|
char *argv[], int argc);
|
||||||
|
|
||||||
/* See wasm_export.h for description */
|
/* See wasm_export.h for description */
|
||||||
bool
|
bool
|
||||||
|
@ -260,7 +252,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
|
||||||
const char *dir_list[], uint32 dir_count,
|
const char *dir_list[], uint32 dir_count,
|
||||||
const char *map_dir_list[], uint32 map_dir_count,
|
const char *map_dir_list[], uint32 map_dir_count,
|
||||||
const char *env[], uint32 env_count,
|
const char *env[], uint32 env_count,
|
||||||
const char *argv[], uint32 argc,
|
char *argv[], uint32 argc,
|
||||||
char *error_buf, uint32 error_buf_size);
|
char *error_buf, uint32 error_buf_size);
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#ifndef _LIB_EXPORT_H_
|
#ifndef _LIB_EXPORT_H_
|
||||||
#define _LIB_EXPORT_H_
|
#define _LIB_EXPORT_H_
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,25 +33,9 @@ typedef struct NativeSymbol {
|
||||||
*
|
*
|
||||||
* @return the number of the exported API
|
* @return the number of the exported API
|
||||||
*/
|
*/
|
||||||
int
|
uint32_t
|
||||||
get_base_lib_export_apis(NativeSymbol **p_base_lib_apis);
|
get_base_lib_export_apis(NativeSymbol **p_base_lib_apis);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the exported APIs of extended lib, this API isn't provided by WASM VM,
|
|
||||||
* it must be provided by developer to register the extended native APIs,
|
|
||||||
* for example, developer can register his native APIs to extended_native_symbol_defs,
|
|
||||||
* array, and include file ext_lib_export.h which implements this API.
|
|
||||||
* And if developer hasn't any native API to register, he can define an empty
|
|
||||||
* extended_native_symbol_defs array, and then include file ext_lib_export.h to
|
|
||||||
* implements this API.
|
|
||||||
*
|
|
||||||
* @param p_base_lib_apis return the exported API array of extend lib
|
|
||||||
*
|
|
||||||
* @return the number of the exported API
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
get_extend_lib_export_apis(NativeSymbol **p_base_lib_apis);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "lib_export.h"
|
#include "lib_export.h"
|
||||||
|
#include "bh_memory.h"
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -25,21 +26,19 @@ struct WASMModuleInstanceCommon;
|
||||||
typedef struct WASMModuleInstanceCommon *wasm_module_inst_t;
|
typedef struct WASMModuleInstanceCommon *wasm_module_inst_t;
|
||||||
|
|
||||||
/* Function instance */
|
/* Function instance */
|
||||||
struct WASMFunctionInstanceCommon;
|
typedef void WASMFunctionInstanceCommon;
|
||||||
typedef struct WASMFunctionInstanceCommon *wasm_function_inst_t;
|
typedef WASMFunctionInstanceCommon *wasm_function_inst_t;
|
||||||
|
|
||||||
/* WASM section */
|
/* WASM section */
|
||||||
typedef struct wasm_section {
|
typedef struct wasm_section_t {
|
||||||
struct wasm_section *next;
|
struct wasm_section_t *next;
|
||||||
/* section type */
|
/* section type */
|
||||||
int section_type;
|
int section_type;
|
||||||
/* section body, not include type and size */
|
/* section body, not include type and size */
|
||||||
uint8_t *section_body;
|
uint8_t *section_body;
|
||||||
/* section body size */
|
/* section body size */
|
||||||
uint32_t section_body_size;
|
uint32_t section_body_size;
|
||||||
} wasm_section_t, *wasm_section_list_t;
|
} wasm_section_t, aot_section_t, *wasm_section_list_t, *aot_section_list_t;
|
||||||
|
|
||||||
typedef wasm_section_t aot_section_t, *aot_section_list_t;
|
|
||||||
|
|
||||||
/* Execution environment, e.g. stack info */
|
/* Execution environment, e.g. stack info */
|
||||||
struct WASMExecEnv;
|
struct WASMExecEnv;
|
||||||
|
@ -52,6 +51,31 @@ typedef enum {
|
||||||
Package_Type_Unknown = 0xFFFF
|
Package_Type_Unknown = 0xFFFF
|
||||||
} package_type_t;
|
} package_type_t;
|
||||||
|
|
||||||
|
/* Memory allocator type */
|
||||||
|
typedef enum {
|
||||||
|
Alloc_With_Pool = 0,
|
||||||
|
Alloc_With_Allocator
|
||||||
|
} mem_alloc_type_t;
|
||||||
|
|
||||||
|
/* WASM runtime initialize arguments */
|
||||||
|
typedef struct RuntimeInitArgs {
|
||||||
|
mem_alloc_type_t mem_alloc_type;
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
void *heap_buf;
|
||||||
|
uint32_t heap_size;
|
||||||
|
} pool;
|
||||||
|
struct {
|
||||||
|
void *malloc_func;
|
||||||
|
void *free_func;
|
||||||
|
} allocator;
|
||||||
|
} mem_alloc;
|
||||||
|
|
||||||
|
const char *native_module_name;
|
||||||
|
NativeSymbol *native_symbols;
|
||||||
|
uint32_t n_native_symbols;
|
||||||
|
} RuntimeInitArgs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the WASM runtime environment.
|
* Initialize the WASM runtime environment.
|
||||||
*
|
*
|
||||||
|
@ -66,6 +90,25 @@ wasm_runtime_init();
|
||||||
void
|
void
|
||||||
wasm_runtime_destroy();
|
wasm_runtime_destroy();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the WASM runtime environment, and also initialize
|
||||||
|
* the memory allocator and register native symbols, which are specified
|
||||||
|
* with init arguments
|
||||||
|
*
|
||||||
|
* @param init_args specifies the init arguments
|
||||||
|
*
|
||||||
|
* @return return true if success, false otherwise
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
wasm_runtime_full_init(RuntimeInitArgs *init_args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destroy the wasm runtime environment, and also destroy
|
||||||
|
* the memory allocator and registered native symbols
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
wasm_runtime_full_destroy();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the package type of a buffer.
|
* Get the package type of a buffer.
|
||||||
*
|
*
|
||||||
|
@ -167,7 +210,7 @@ wasm_runtime_lookup_wasi_start_function(wasm_module_inst_t module_inst);
|
||||||
* @return the function instance found
|
* @return the function instance found
|
||||||
*/
|
*/
|
||||||
wasm_function_inst_t
|
wasm_function_inst_t
|
||||||
wasm_runtime_lookup_function(const wasm_module_inst_t 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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,7 +7,17 @@ add_definitions (-DWASM_ENABLE_INTERP=1)
|
||||||
|
|
||||||
include_directories(${IWASM_INTERP_DIR})
|
include_directories(${IWASM_INTERP_DIR})
|
||||||
|
|
||||||
file (GLOB_RECURSE source_all ${IWASM_INTERP_DIR}/*.c)
|
if (WAMR_BUILD_FAST_INTERP EQUAL 1)
|
||||||
|
set (INTERPRETER "wasm_interp_fast.c")
|
||||||
|
else ()
|
||||||
|
set (INTERPRETER "wasm_interp.c")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
file (GLOB_RECURSE source_all
|
||||||
|
${IWASM_INTERP_DIR}/wasm_loader.c
|
||||||
|
${IWASM_INTERP_DIR}/wasm_runtime.c
|
||||||
|
${IWASM_INTERP_DIR}/${INTERPRETER}
|
||||||
|
)
|
||||||
|
|
||||||
set (IWASM_INTERP_SOURCE ${source_all})
|
set (IWASM_INTERP_SOURCE ${source_all})
|
||||||
|
|
||||||
|
|
|
@ -189,6 +189,12 @@ typedef struct WASMFunction {
|
||||||
bool has_op_func_call;
|
bool has_op_func_call;
|
||||||
uint32 code_size;
|
uint32 code_size;
|
||||||
uint8 *code;
|
uint8 *code;
|
||||||
|
#if WASM_ENABLE_FAST_INTERP != 0
|
||||||
|
uint32 code_compiled_size;
|
||||||
|
uint8 *code_compiled;
|
||||||
|
uint8 *consts;
|
||||||
|
uint32 const_cell_num;
|
||||||
|
#endif
|
||||||
} WASMFunction;
|
} WASMFunction;
|
||||||
|
|
||||||
typedef struct WASMGlobal {
|
typedef struct WASMGlobal {
|
||||||
|
@ -231,7 +237,7 @@ typedef struct WASIArguments {
|
||||||
uint32 map_dir_count;
|
uint32 map_dir_count;
|
||||||
const char **env;
|
const char **env;
|
||||||
uint32 env_count;
|
uint32 env_count;
|
||||||
const char **argv;
|
char **argv;
|
||||||
uint32 argc;
|
uint32 argc;
|
||||||
} WASIArguments;
|
} WASIArguments;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -225,27 +225,24 @@ LOAD_I16(void *addr)
|
||||||
#endif /* WASM_CPU_SUPPORTS_UNALIGNED_64BIT_ACCESS != 0 */
|
#endif /* WASM_CPU_SUPPORTS_UNALIGNED_64BIT_ACCESS != 0 */
|
||||||
|
|
||||||
#define CHECK_MEMORY_OVERFLOW() do { \
|
#define CHECK_MEMORY_OVERFLOW() do { \
|
||||||
uint32 offset1 = offset + addr; \
|
uint64 offset1 = offset + addr; \
|
||||||
/* if (flags != 2) \
|
/* if (flags != 2) \
|
||||||
LOG_VERBOSE("unaligned load/store in wasm interp, flag: %d.\n", flags); */\
|
LOG_VERBOSE("unaligned load/store in wasm interp, flag: %d.\n", flags); */\
|
||||||
/* The WASM spec doesn't require that the dynamic address operand must be \
|
/* The WASM spec doesn't require that the dynamic address operand must be \
|
||||||
unsigned, so we don't check whether integer overflow or not here. */ \
|
unsigned, so we don't check whether integer overflow or not here. */ \
|
||||||
/* if (offset1 < offset) \
|
/* if (offset1 < offset) \
|
||||||
goto out_of_bounds; */ \
|
goto out_of_bounds; */ \
|
||||||
if (offset1 < memory_data_size) { \
|
if (offset1 + LOAD_SIZE[opcode - WASM_OP_I32_LOAD] <= memory_data_size) { \
|
||||||
/* If offset1 is in valid range, maddr must also be in valid range, \
|
/* If offset1 is in valid range, maddr must also be in valid range, \
|
||||||
no need to check it again. */ \
|
no need to check it again. */ \
|
||||||
maddr = memory->memory_data + offset1; \
|
maddr = memory->memory_data + offset1; \
|
||||||
if (maddr + LOAD_SIZE[opcode - WASM_OP_I32_LOAD] > memory->end_addr) \
|
|
||||||
goto out_of_bounds; \
|
|
||||||
} \
|
} \
|
||||||
else if (offset1 > heap_base_offset \
|
else if (offset1 > DEFAULT_APP_HEAP_BASE_OFFSET \
|
||||||
&& offset1 < heap_base_offset + heap_data_size) { \
|
&& (offset1 + LOAD_SIZE[opcode - WASM_OP_I32_LOAD] <= \
|
||||||
|
DEFAULT_APP_HEAP_BASE_OFFSET + heap_data_size)) { \
|
||||||
/* If offset1 is in valid range, maddr must also be in valid range, \
|
/* If offset1 is in valid range, maddr must also be in valid range, \
|
||||||
no need to check it again. */ \
|
no need to check it again. */ \
|
||||||
maddr = memory->heap_data + offset1 - memory->heap_base_offset; \
|
maddr = memory->heap_data + offset1 - memory->heap_base_offset; \
|
||||||
if (maddr + LOAD_SIZE[opcode - WASM_OP_I32_LOAD] > memory->heap_data_end) \
|
|
||||||
goto out_of_bounds; \
|
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
goto out_of_bounds; \
|
goto out_of_bounds; \
|
||||||
|
@ -795,7 +792,6 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||||
WASMMemoryInstance *memory = module->default_memory;
|
WASMMemoryInstance *memory = module->default_memory;
|
||||||
uint32 num_bytes_per_page = memory ? memory->num_bytes_per_page : 0;
|
uint32 num_bytes_per_page = memory ? memory->num_bytes_per_page : 0;
|
||||||
uint32 memory_data_size = memory ? num_bytes_per_page * memory->cur_page_count : 0;
|
uint32 memory_data_size = memory ? num_bytes_per_page * memory->cur_page_count : 0;
|
||||||
uint32 heap_base_offset = memory ? (uint32)memory->heap_base_offset : 0;
|
|
||||||
uint32 heap_data_size = memory ? (uint32)(memory->heap_data_end - memory->heap_data) : 0;
|
uint32 heap_data_size = memory ? (uint32)(memory->heap_data_end - memory->heap_data) : 0;
|
||||||
uint8 *global_data = memory ? memory->global_data : NULL;
|
uint8 *global_data = memory ? memory->global_data : NULL;
|
||||||
WASMTableInstance *table = module->default_table;
|
WASMTableInstance *table = module->default_table;
|
||||||
|
@ -1080,7 +1076,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||||
HANDLE_OP_END ();
|
HANDLE_OP_END ();
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE_OP (WASM_OP_GET_LOCAL_FAST):
|
HANDLE_OP (EXT_OP_GET_LOCAL_FAST):
|
||||||
{
|
{
|
||||||
local_offset = *frame_ip++;
|
local_offset = *frame_ip++;
|
||||||
if (local_offset & 0x80)
|
if (local_offset & 0x80)
|
||||||
|
@ -1111,7 +1107,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||||
HANDLE_OP_END ();
|
HANDLE_OP_END ();
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE_OP (WASM_OP_SET_LOCAL_FAST):
|
HANDLE_OP (EXT_OP_SET_LOCAL_FAST):
|
||||||
{
|
{
|
||||||
local_offset = *frame_ip++;
|
local_offset = *frame_ip++;
|
||||||
if (local_offset & 0x80)
|
if (local_offset & 0x80)
|
||||||
|
@ -1143,7 +1139,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||||
HANDLE_OP_END ();
|
HANDLE_OP_END ();
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE_OP (WASM_OP_TEE_LOCAL_FAST):
|
HANDLE_OP (EXT_OP_TEE_LOCAL_FAST):
|
||||||
{
|
{
|
||||||
local_offset = *frame_ip++;
|
local_offset = *frame_ip++;
|
||||||
if (local_offset & 0x80)
|
if (local_offset & 0x80)
|
||||||
|
@ -2225,6 +2221,11 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||||
HANDLE_OP (WASM_OP_UNUSED_0x25):
|
HANDLE_OP (WASM_OP_UNUSED_0x25):
|
||||||
HANDLE_OP (WASM_OP_UNUSED_0x26):
|
HANDLE_OP (WASM_OP_UNUSED_0x26):
|
||||||
HANDLE_OP (WASM_OP_UNUSED_0x27):
|
HANDLE_OP (WASM_OP_UNUSED_0x27):
|
||||||
|
/* Used by fast interpreter */
|
||||||
|
HANDLE_OP (EXT_OP_SET_LOCAL_FAST_I64):
|
||||||
|
HANDLE_OP (EXT_OP_TEE_LOCAL_FAST_I64):
|
||||||
|
HANDLE_OP (EXT_OP_COPY_STACK_TOP):
|
||||||
|
HANDLE_OP (EXT_OP_COPY_STACK_TOP_I64):
|
||||||
{
|
{
|
||||||
wasm_set_exception(module, "WASM interp failed: unsupported opcode.");
|
wasm_set_exception(module, "WASM interp failed: unsupported opcode.");
|
||||||
goto got_exception;
|
goto got_exception;
|
||||||
|
|
|
@ -26,6 +26,13 @@ typedef struct WASMInterpFrame {
|
||||||
/* Instruction pointer of the bytecode array. */
|
/* Instruction pointer of the bytecode array. */
|
||||||
uint8 *ip;
|
uint8 *ip;
|
||||||
|
|
||||||
|
#if WASM_ENABLE_FAST_INTERP != 0
|
||||||
|
/* return offset of current frame.
|
||||||
|
the callee will put return value here */
|
||||||
|
uint32 ret_offset;
|
||||||
|
uint32 *lp;
|
||||||
|
uint32 operand[1];
|
||||||
|
#else
|
||||||
/* Operand stack top pointer of the current frame. The bottom of
|
/* Operand stack top pointer of the current frame. The bottom of
|
||||||
the stack is the next cell after the last local variable. */
|
the stack is the next cell after the last local variable. */
|
||||||
uint32 *sp_bottom;
|
uint32 *sp_bottom;
|
||||||
|
@ -43,6 +50,7 @@ typedef struct WASMInterpFrame {
|
||||||
ref to frame end: data types of local vairables and stack data
|
ref to frame end: data types of local vairables and stack data
|
||||||
*/
|
*/
|
||||||
uint32 lp[1];
|
uint32 lp[1];
|
||||||
|
#endif
|
||||||
} WASMInterpFrame;
|
} WASMInterpFrame;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
2276
core/iwasm/interpreter/wasm_interp_fast.c
Normal file
2276
core/iwasm/interpreter/wasm_interp_fast.c
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -238,13 +238,19 @@ typedef enum WASMOpcode {
|
||||||
WASM_OP_F64_REINTERPRET_I64 = 0xbf, /* f64.reinterpret/i64 */
|
WASM_OP_F64_REINTERPRET_I64 = 0xbf, /* f64.reinterpret/i64 */
|
||||||
|
|
||||||
/* drop/select specified types*/
|
/* drop/select specified types*/
|
||||||
WASM_OP_DROP_64 = 0xc0,
|
WASM_OP_DROP_64 = 0xc0,
|
||||||
WASM_OP_SELECT_64 = 0xc1,
|
WASM_OP_SELECT_64 = 0xc1,
|
||||||
WASM_OP_GET_LOCAL_FAST = 0xc2,
|
|
||||||
WASM_OP_SET_LOCAL_FAST = 0xc3,
|
|
||||||
WASM_OP_TEE_LOCAL_FAST = 0xc4,
|
|
||||||
|
|
||||||
WASM_OP_IMPDEP = 0xc5
|
/* extend op code */
|
||||||
|
EXT_OP_GET_LOCAL_FAST = 0xc2,
|
||||||
|
EXT_OP_SET_LOCAL_FAST_I64 = 0xc3,
|
||||||
|
EXT_OP_SET_LOCAL_FAST = 0xc4,
|
||||||
|
EXT_OP_TEE_LOCAL_FAST = 0xc5,
|
||||||
|
EXT_OP_TEE_LOCAL_FAST_I64 = 0xc6,
|
||||||
|
EXT_OP_COPY_STACK_TOP = 0xc7,
|
||||||
|
EXT_OP_COPY_STACK_TOP_I64 = 0xc8,
|
||||||
|
|
||||||
|
WASM_OP_IMPDEP = 0xc9
|
||||||
} WASMOpcode;
|
} WASMOpcode;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -450,12 +456,16 @@ static const void *_name[WASM_INSTRUCTION_NUM] = { \
|
||||||
HANDLE_OPCODE (WASM_OP_I64_REINTERPRET_F64), /* 0xbd */ \
|
HANDLE_OPCODE (WASM_OP_I64_REINTERPRET_F64), /* 0xbd */ \
|
||||||
HANDLE_OPCODE (WASM_OP_F32_REINTERPRET_I32), /* 0xbe */ \
|
HANDLE_OPCODE (WASM_OP_F32_REINTERPRET_I32), /* 0xbe */ \
|
||||||
HANDLE_OPCODE (WASM_OP_F64_REINTERPRET_I64), /* 0xbf */ \
|
HANDLE_OPCODE (WASM_OP_F64_REINTERPRET_I64), /* 0xbf */ \
|
||||||
HANDLE_OPCODE (WASM_OP_DROP_64), /* 0xc0 */ \
|
HANDLE_OPCODE (WASM_OP_DROP_64), /* 0xc0 */ \
|
||||||
HANDLE_OPCODE (WASM_OP_SELECT_64), /* 0xc1 */ \
|
HANDLE_OPCODE (WASM_OP_SELECT_64), /* 0xc1 */ \
|
||||||
HANDLE_OPCODE (WASM_OP_GET_LOCAL_FAST),/* 0xc2 */ \
|
HANDLE_OPCODE (EXT_OP_GET_LOCAL_FAST), /* 0xc2 */ \
|
||||||
HANDLE_OPCODE (WASM_OP_SET_LOCAL_FAST),/* 0xc3 */ \
|
HANDLE_OPCODE (EXT_OP_SET_LOCAL_FAST_I64), /* 0xc3 */ \
|
||||||
HANDLE_OPCODE (WASM_OP_TEE_LOCAL_FAST),/* 0xc4 */ \
|
HANDLE_OPCODE (EXT_OP_SET_LOCAL_FAST), /* 0xc4 */ \
|
||||||
HANDLE_OPCODE (WASM_OP_IMPDEP), /* 0xc5 */ \
|
HANDLE_OPCODE (EXT_OP_TEE_LOCAL_FAST), /* 0xc5 */ \
|
||||||
|
HANDLE_OPCODE (EXT_OP_TEE_LOCAL_FAST_I64), /* 0xc6 */ \
|
||||||
|
HANDLE_OPCODE (EXT_OP_COPY_STACK_TOP), /* 0xc7 */ \
|
||||||
|
HANDLE_OPCODE (EXT_OP_COPY_STACK_TOP_I64), /* 0xc8 */ \
|
||||||
|
HANDLE_OPCODE (WASM_OP_IMPDEP), /* 0xc9 */ \
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* end of _WASM_OPCODE_H */
|
#endif /* end of _WASM_OPCODE_H */
|
||||||
|
|
|
@ -355,6 +355,10 @@ functions_instantiate(const WASMModule *module,
|
||||||
|
|
||||||
function->local_offsets = function->u.func->local_offsets;
|
function->local_offsets = function->u.func->local_offsets;
|
||||||
|
|
||||||
|
#if WASM_ENABLE_FAST_INTERP != 0
|
||||||
|
function->const_cell_num = function->u.func->const_cell_num;
|
||||||
|
#endif
|
||||||
|
|
||||||
function++;
|
function++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,10 @@ typedef struct WASMFunctionInstance {
|
||||||
uint16 ret_cell_num;
|
uint16 ret_cell_num;
|
||||||
/* cell num of local variables, 0 for import function */
|
/* cell num of local variables, 0 for import function */
|
||||||
uint16 local_cell_num;
|
uint16 local_cell_num;
|
||||||
|
#if WASM_ENABLE_FAST_INTERP != 0
|
||||||
|
/* cell num of consts */
|
||||||
|
uint16 const_cell_num;
|
||||||
|
#endif
|
||||||
uint16 *local_offsets;
|
uint16 *local_offsets;
|
||||||
/* parameter types */
|
/* parameter types */
|
||||||
uint8 *param_types;
|
uint8 *param_types;
|
||||||
|
@ -165,7 +169,11 @@ typedef struct WASMInterpFrame WASMRuntimeFrame;
|
||||||
static inline uint8*
|
static inline uint8*
|
||||||
wasm_get_func_code(WASMFunctionInstance *func)
|
wasm_get_func_code(WASMFunctionInstance *func)
|
||||||
{
|
{
|
||||||
|
#if WASM_ENABLE_FAST_INTERP == 0
|
||||||
return func->is_import_func ? NULL : func->u.func->code;
|
return func->is_import_func ? NULL : func->u.func->code;
|
||||||
|
#else
|
||||||
|
return func->is_import_func ? NULL : func->u.func->code_compiled;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -178,8 +186,13 @@ wasm_get_func_code(WASMFunctionInstance *func)
|
||||||
static inline uint8*
|
static inline uint8*
|
||||||
wasm_get_func_code_end(WASMFunctionInstance *func)
|
wasm_get_func_code_end(WASMFunctionInstance *func)
|
||||||
{
|
{
|
||||||
|
#if WASM_ENABLE_FAST_INTERP == 0
|
||||||
return func->is_import_func
|
return func->is_import_func
|
||||||
? NULL : func->u.func->code + func->u.func->code_size;
|
? NULL : func->u.func->code + func->u.func->code_size;
|
||||||
|
#else
|
||||||
|
return func->is_import_func
|
||||||
|
? NULL : func->u.func->code_compiled + func->u.func->code_compiled_size;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
WASMModule *
|
WASMModule *
|
||||||
|
|
|
@ -98,6 +98,13 @@ enum {
|
||||||
/* WASM Interpreter labels-as-values feature */
|
/* WASM Interpreter labels-as-values feature */
|
||||||
#define WASM_ENABLE_LABELS_AS_VALUES 1
|
#define WASM_ENABLE_LABELS_AS_VALUES 1
|
||||||
|
|
||||||
|
#if WASM_ENABLE_FAST_INTERP != 0
|
||||||
|
#define WASM_ENABLE_ABS_LABEL_ADDR 1
|
||||||
|
#define WASM_DEBUG_PREPROCESSOR 0
|
||||||
|
#else
|
||||||
|
#define WASM_ENABLE_ABS_LABEL_ADDR 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Heap and stack profiling */
|
/* Heap and stack profiling */
|
||||||
#define BEIHAI_ENABLE_MEMORY_PROFILING 0
|
#define BEIHAI_ENABLE_MEMORY_PROFILING 0
|
||||||
|
|
||||||
|
|
|
@ -9,20 +9,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
char *bh_strdup(const char *s)
|
int
|
||||||
{
|
bh_platform_init()
|
||||||
uint32 size;
|
|
||||||
char *s1 = NULL;
|
|
||||||
|
|
||||||
if (s) {
|
|
||||||
size = (uint32)(strlen(s) + 1);
|
|
||||||
if ((s1 = bh_malloc(size)))
|
|
||||||
bh_memcpy_s(s1, size, s, size);
|
|
||||||
}
|
|
||||||
return s1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bh_platform_init()
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
||||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "bh_platform.h"
|
|
||||||
|
|
||||||
#define RSIZE_MAX 0x7FFFFFFF
|
|
||||||
|
|
||||||
int b_memcpy_s(void * s1, unsigned int s1max, const void * s2, unsigned int n)
|
|
||||||
{
|
|
||||||
char *dest = (char*) s1;
|
|
||||||
char *src = (char*) s2;
|
|
||||||
if (n == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s1 == NULL || s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (s2 == NULL || n > s1max) {
|
|
||||||
memset(dest, 0, s1max);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
memcpy(dest, src, n);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int b_strcat_s(char * s1, size_t s1max, const char * s2)
|
|
||||||
{
|
|
||||||
if (NULL == s1 || NULL == s2
|
|
||||||
|| s1max < (strlen(s1) + strlen(s2) + 1)
|
|
||||||
|| s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcat(s1, s2);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int b_strcpy_s(char * s1, size_t s1max, const char * s2)
|
|
||||||
{
|
|
||||||
if (NULL == s1 || NULL == s2
|
|
||||||
|| s1max < (strlen(s2) + 1)
|
|
||||||
|| s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(s1, s2);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fopen_s(FILE ** pFile, const char *filename, const char *mode)
|
|
||||||
{
|
|
||||||
if (NULL == pFile || NULL == filename || NULL == mode) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
*pFile = fopen(filename, mode);
|
|
||||||
|
|
||||||
if (NULL == *pFile)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -12,20 +12,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
char *bh_strdup(const char *s)
|
int
|
||||||
{
|
bh_platform_init()
|
||||||
uint32 size;
|
|
||||||
char *s1 = NULL;
|
|
||||||
|
|
||||||
if (s) {
|
|
||||||
size = (uint32)(strlen(s) + 1);
|
|
||||||
if ((s1 = bh_malloc(size)))
|
|
||||||
bh_memcpy_s(s1, size, s, size);
|
|
||||||
}
|
|
||||||
return s1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bh_platform_init()
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,8 +104,6 @@ int b_memcpy_s(void * s1, unsigned int s1max, const void * s2,
|
||||||
int b_strcat_s(char * s1, size_t s1max, const char * s2);
|
int b_strcat_s(char * s1, size_t s1max, const char * s2);
|
||||||
int b_strcpy_s(char * s1, size_t s1max, const char * s2);
|
int b_strcpy_s(char * s1, size_t s1max, const char * s2);
|
||||||
|
|
||||||
int fopen_s(FILE ** pFile, const char *filename, const char *mode);
|
|
||||||
|
|
||||||
char *bh_read_file_to_buffer(const char *filename, uint32 *ret_size);
|
char *bh_read_file_to_buffer(const char *filename, uint32 *ret_size);
|
||||||
|
|
||||||
char *bh_strdup(const char *s);
|
char *bh_strdup(const char *s);
|
||||||
|
|
|
@ -1,71 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
||||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "bh_platform.h"
|
|
||||||
|
|
||||||
#ifdef RSIZE_MAX
|
|
||||||
#undef RSIZE_MAX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define RSIZE_MAX 0x7FFFFFFF
|
|
||||||
|
|
||||||
int b_memcpy_s(void * s1, unsigned int s1max, const void * s2, unsigned int n)
|
|
||||||
{
|
|
||||||
char *dest = (char*) s1;
|
|
||||||
char *src = (char*) s2;
|
|
||||||
if (n == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s1 == NULL || s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (s2 == NULL || n > s1max) {
|
|
||||||
memset(dest, 0, s1max);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
memcpy(dest, src, n);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int b_strcat_s(char * s1, size_t s1max, const char * s2)
|
|
||||||
{
|
|
||||||
if (NULL == s1 || NULL == s2
|
|
||||||
|| s1max < (strlen(s1) + strlen(s2) + 1)
|
|
||||||
|| s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcat(s1, s2);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int b_strcpy_s(char * s1, size_t s1max, const char * s2)
|
|
||||||
{
|
|
||||||
if (NULL == s1 || NULL == s2
|
|
||||||
|| s1max < (strlen(s2) + 1)
|
|
||||||
|| s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(s1, s2);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fopen_s(FILE ** pFile, const char *filename, const char *mode)
|
|
||||||
{
|
|
||||||
if (NULL == pFile || NULL == filename || NULL == mode) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
*pFile = fopen(filename, mode);
|
|
||||||
|
|
||||||
if (NULL == *pFile)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -12,20 +12,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
char *bh_strdup(const char *s)
|
int
|
||||||
{
|
bh_platform_init()
|
||||||
uint32 size;
|
|
||||||
char *s1 = NULL;
|
|
||||||
|
|
||||||
if (s) {
|
|
||||||
size = (uint32)(strlen(s) + 1);
|
|
||||||
if ((s1 = bh_malloc(size)))
|
|
||||||
bh_memcpy_s(s1, size, s, size);
|
|
||||||
}
|
|
||||||
return s1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bh_platform_init()
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,8 +101,6 @@ int b_memcpy_s(void * s1, unsigned int s1max, const void * s2,
|
||||||
int b_strcat_s(char * s1, size_t s1max, const char * s2);
|
int b_strcat_s(char * s1, size_t s1max, const char * s2);
|
||||||
int b_strcpy_s(char * s1, size_t s1max, const char * s2);
|
int b_strcpy_s(char * s1, size_t s1max, const char * s2);
|
||||||
|
|
||||||
int fopen_s(FILE ** pFile, const char *filename, const char *mode);
|
|
||||||
|
|
||||||
char *bh_read_file_to_buffer(const char *filename, uint32 *ret_size);
|
char *bh_read_file_to_buffer(const char *filename, uint32 *ret_size);
|
||||||
|
|
||||||
char *bh_strdup(const char *s);
|
char *bh_strdup(const char *s);
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
||||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "bh_platform.h"
|
|
||||||
|
|
||||||
#define RSIZE_MAX 0x7FFFFFFF
|
|
||||||
|
|
||||||
int b_memcpy_s(void * s1, unsigned int s1max, const void * s2, unsigned int n)
|
|
||||||
{
|
|
||||||
char *dest = (char*) s1;
|
|
||||||
char *src = (char*) s2;
|
|
||||||
if (n == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s1 == NULL || s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (s2 == NULL || n > s1max) {
|
|
||||||
memset(dest, 0, s1max);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
memcpy(dest, src, n);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int b_strcat_s(char * s1, size_t s1max, const char * s2)
|
|
||||||
{
|
|
||||||
if (NULL == s1 || NULL == s2
|
|
||||||
|| s1max < (strlen(s1) + strlen(s2) + 1)
|
|
||||||
|| s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
strncat(s1, s2, strlen(s2));
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int b_strcpy_s(char * s1, size_t s1max, const char * s2)
|
|
||||||
{
|
|
||||||
if (NULL == s1 || NULL == s2
|
|
||||||
|| s1max < (strlen(s2) + 1)
|
|
||||||
|| s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
strncpy(s1, s2, s1max);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -14,19 +14,6 @@
|
||||||
#define FIXED_BUFFER_SIZE (1<<9)
|
#define FIXED_BUFFER_SIZE (1<<9)
|
||||||
static bh_print_function_t print_function = NULL;
|
static bh_print_function_t print_function = NULL;
|
||||||
|
|
||||||
char *bh_strdup(const char *s)
|
|
||||||
{
|
|
||||||
uint32 size;
|
|
||||||
char *s1 = NULL;
|
|
||||||
|
|
||||||
if (s) {
|
|
||||||
size = (uint32)(strlen(s) + 1);
|
|
||||||
if ((s1 = bh_malloc(size)))
|
|
||||||
bh_memcpy_s(s1, size, s, size);
|
|
||||||
}
|
|
||||||
return s1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bh_platform_init()
|
int bh_platform_init()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
||||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "bh_platform.h"
|
|
||||||
|
|
||||||
#define RSIZE_MAX 0x7FFFFFFF
|
|
||||||
|
|
||||||
int b_memcpy_s(void * s1, unsigned int s1max, const void * s2, unsigned int n)
|
|
||||||
{
|
|
||||||
char *dest = (char*) s1;
|
|
||||||
char *src = (char*) s2;
|
|
||||||
if (n == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s1 == NULL || s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (s2 == NULL || n > s1max) {
|
|
||||||
memset(dest, 0, s1max);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
memcpy(dest, src, n);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int b_strcat_s(char * s1, size_t s1max, const char * s2)
|
|
||||||
{
|
|
||||||
if (NULL == s1 || NULL == s2
|
|
||||||
|| s1max < (strlen(s1) + strlen(s2) + 1)
|
|
||||||
|| s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcat(s1, s2);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int b_strcpy_s(char * s1, size_t s1max, const char * s2)
|
|
||||||
{
|
|
||||||
if (NULL == s1 || NULL == s2
|
|
||||||
|| s1max < (strlen(s2) + 1)
|
|
||||||
|| s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(s1, s2);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fopen_s(FILE ** pFile, const char *filename, const char *mode)
|
|
||||||
{
|
|
||||||
if (NULL == pFile || NULL == filename || NULL == mode) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
*pFile = fopen(filename, mode);
|
|
||||||
|
|
||||||
if (NULL == *pFile)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -12,20 +12,8 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
char *bh_strdup(const char *s)
|
int
|
||||||
{
|
bh_platform_init()
|
||||||
uint32 size;
|
|
||||||
char *s1 = NULL;
|
|
||||||
|
|
||||||
if (s) {
|
|
||||||
size = (uint32)(strlen(s) + 1);
|
|
||||||
if ((s1 = bh_malloc(size)))
|
|
||||||
bh_memcpy_s(s1, size, s, size);
|
|
||||||
}
|
|
||||||
return s1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bh_platform_init()
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,8 +102,6 @@ int b_memcpy_s(void * s1, unsigned int s1max, const void * s2,
|
||||||
int b_strcat_s(char * s1, size_t s1max, const char * s2);
|
int b_strcat_s(char * s1, size_t s1max, const char * s2);
|
||||||
int b_strcpy_s(char * s1, size_t s1max, const char * s2);
|
int b_strcpy_s(char * s1, size_t s1max, const char * s2);
|
||||||
|
|
||||||
int fopen_s(FILE ** pFile, const char *filename, const char *mode);
|
|
||||||
|
|
||||||
char *bh_read_file_to_buffer(const char *filename, uint32 *ret_size);
|
char *bh_read_file_to_buffer(const char *filename, uint32 *ret_size);
|
||||||
|
|
||||||
char *bh_strdup(const char *s);
|
char *bh_strdup(const char *s);
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
||||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "bh_platform.h"
|
|
||||||
|
|
||||||
#define RSIZE_MAX 0x7FFFFFFF
|
|
||||||
|
|
||||||
int b_memcpy_s(void * s1, unsigned int s1max, const void * s2, unsigned int n)
|
|
||||||
{
|
|
||||||
char *dest = (char*) s1;
|
|
||||||
char *src = (char*) s2;
|
|
||||||
if (n == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s1 == NULL || s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (s2 == NULL || n > s1max) {
|
|
||||||
memset(dest, 0, s1max);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
memcpy(dest, src, n);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int b_strcat_s(char * s1, size_t s1max, const char * s2)
|
|
||||||
{
|
|
||||||
if (NULL == s1 || NULL == s2
|
|
||||||
|| s1max < (strlen(s1) + strlen(s2) + 1)
|
|
||||||
|| s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcat(s1, s2);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int b_strcpy_s(char * s1, size_t s1max, const char * s2)
|
|
||||||
{
|
|
||||||
if (NULL == s1 || NULL == s2
|
|
||||||
|| s1max < (strlen(s2) + 1)
|
|
||||||
|| s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(s1, s2);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -16,21 +16,8 @@
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
int
|
||||||
char *bh_strdup(const char *s)
|
bh_platform_init()
|
||||||
{
|
|
||||||
uint32 size;
|
|
||||||
char *s1 = NULL;
|
|
||||||
|
|
||||||
if (s) {
|
|
||||||
size = (uint32)(strlen(s) + 1);
|
|
||||||
if ((s1 = bh_malloc(size)))
|
|
||||||
bh_memcpy_s(s1, size, s, size);
|
|
||||||
}
|
|
||||||
return s1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int bh_platform_init()
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
||||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "bh_platform.h"
|
|
||||||
|
|
||||||
#define RSIZE_MAX 0x7FFFFFFF
|
|
||||||
|
|
||||||
int b_memcpy_s(void * s1, unsigned int s1max, const void * s2, unsigned int n)
|
|
||||||
{
|
|
||||||
char *dest = (char*) s1;
|
|
||||||
char *src = (char*) s2;
|
|
||||||
if (n == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s1 == NULL || s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (s2 == NULL || n > s1max) {
|
|
||||||
memset(dest, 0, s1max);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
memcpy(dest, src, n);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int b_strcat_s(char * s1, size_t s1max, const char * s2)
|
|
||||||
{
|
|
||||||
if (NULL == s1 || NULL == s2
|
|
||||||
|| s1max < (strlen(s1) + strlen(s2) + 1)
|
|
||||||
|| s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcat(s1, s2);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int b_strcpy_s(char * s1, size_t s1max, const char * s2)
|
|
||||||
{
|
|
||||||
if (NULL == s1|| NULL == s2
|
|
||||||
|| s1max < (strlen(s2) + 1) || s1max > RSIZE_MAX) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
strcpy(s1, s2);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -12,19 +12,6 @@
|
||||||
#include <arch/arm/aarch32/cortex_m/cmsis.h>
|
#include <arch/arm/aarch32/cortex_m/cmsis.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char *bh_strdup(const char *s)
|
|
||||||
{
|
|
||||||
uint32 size;
|
|
||||||
char *s1 = NULL;
|
|
||||||
|
|
||||||
if (s) {
|
|
||||||
size = (uint32)(strlen(s) + 1);
|
|
||||||
if ((s1 = bh_malloc(size)))
|
|
||||||
bh_memcpy_s(s1, size, s, size);
|
|
||||||
}
|
|
||||||
return s1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CONFIG_ARM_MPU
|
#ifdef CONFIG_ARM_MPU
|
||||||
/**
|
/**
|
||||||
* This function will allow execute from sram region.
|
* This function will allow execute from sram region.
|
||||||
|
@ -54,7 +41,8 @@ _stdout_hook_iwasm(int c)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bh_platform_init()
|
int
|
||||||
|
bh_platform_init()
|
||||||
{
|
{
|
||||||
extern void __stdout_hook_install(int (*hook)(int));
|
extern void __stdout_hook_install(int (*hook)(int));
|
||||||
/* Enable printf() in Zephyr */
|
/* Enable printf() in Zephyr */
|
||||||
|
|
|
@ -4,11 +4,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "bh_platform.h"
|
#include "bh_platform.h"
|
||||||
|
#include "bh_common.h"
|
||||||
|
|
||||||
|
#ifdef RSIZE_MAX
|
||||||
|
#undef RSIZE_MAX
|
||||||
|
#endif
|
||||||
|
|
||||||
#define RSIZE_MAX 0x7FFFFFFF
|
#define RSIZE_MAX 0x7FFFFFFF
|
||||||
|
|
||||||
int b_memcpy_s(void * s1, unsigned int s1max,
|
int
|
||||||
const void * s2, unsigned int n)
|
b_memcpy_s(void * s1, unsigned int s1max,
|
||||||
|
const void * s2, unsigned int n)
|
||||||
{
|
{
|
||||||
char *dest = (char*)s1;
|
char *dest = (char*)s1;
|
||||||
char *src = (char*)s2;
|
char *src = (char*)s2;
|
||||||
|
@ -27,7 +33,8 @@ int b_memcpy_s(void * s1, unsigned int s1max,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int b_strcat_s(char * s1, size_t s1max, const char * s2)
|
int
|
||||||
|
b_strcat_s(char * s1, size_t s1max, const char * s2)
|
||||||
{
|
{
|
||||||
if (NULL == s1 || NULL == s2
|
if (NULL == s1 || NULL == s2
|
||||||
|| s1max < (strlen(s1) + strlen(s2) + 1)
|
|| s1max < (strlen(s1) + strlen(s2) + 1)
|
||||||
|
@ -35,11 +42,12 @@ int b_strcat_s(char * s1, size_t s1max, const char * s2)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcat(s1, s2);
|
memcpy(s1 + strlen(s1), s2, strlen(s2) + 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int b_strcpy_s(char * s1, size_t s1max, const char * s2)
|
int
|
||||||
|
b_strcpy_s(char * s1, size_t s1max, const char * s2)
|
||||||
{
|
{
|
||||||
if (NULL == s1 || NULL == s2
|
if (NULL == s1 || NULL == s2
|
||||||
|| s1max < (strlen(s2) + 1)
|
|| s1max < (strlen(s2) + 1)
|
||||||
|
@ -47,7 +55,21 @@ int b_strcpy_s(char * s1, size_t s1max, const char * s2)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(s1, s2);
|
memcpy(s1, s2, strlen(s2) + 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
bh_strdup(const char *s)
|
||||||
|
{
|
||||||
|
uint32 size;
|
||||||
|
char *s1 = NULL;
|
||||||
|
|
||||||
|
if (s) {
|
||||||
|
size = (uint32)(strlen(s) + 1);
|
||||||
|
if ((s1 = bh_malloc(size)))
|
||||||
|
bh_memcpy_s(s1, size, s, size);
|
||||||
|
}
|
||||||
|
return s1;
|
||||||
|
}
|
||||||
|
|
|
@ -1,12 +1,72 @@
|
||||||
|
|
||||||
Build WAMR core (iwasm)
|
Build WAMR core (iwasm)
|
||||||
=========================
|
=========================
|
||||||
Please follow the instructions below to build the WAMR VM core on different platforms.
|
It is recommended to use the [WAMR SDK](../wamr-sdk) tools to build a project that embedes the WAMR. This document introduces how to build the WAMR minimal product which is vmcore only (no app-framework and app-mgr) for multiple platforms.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## iwasm VM core CMake building configurations
|
||||||
|
|
||||||
|
By including the cmake scripts under folder [build-scripts](../build-scripts), it is easy to build minimal product with CMake. WAMR provides a number of features which can be easily configured through cmake variables:
|
||||||
|
|
||||||
|
``` Bash
|
||||||
|
cmake -DWAMR_BUILD_INTERP=1/0 to enable or disable WASM intepreter
|
||||||
|
cmake -DWAMR_BUILD_FAST_INTERP=1/0 to build fast (default) or classic WASM intepreter.
|
||||||
|
cmake -DWAMR_BUILD_AOT=1/0 to enable or disable WASM AOT
|
||||||
|
cmake -DWAMR_BUILD_JIT=1/0 to enable or disable WASM JIT. (Disabled by default)
|
||||||
|
cmake -DWAMR_BUILD_LIBC_BUILTIN=1/0 enable or disable Libc builtin API's. (Enabled by default)
|
||||||
|
cmake -DWAMR_BUILD_LIBC_WASI=1/0 enable or disable Libc WASI API's
|
||||||
|
cmake -DWAMR_BUILD_TARGET=<arch> to set the building target, including:
|
||||||
|
X86_64, X86_32, ARM, THUMB, XTENSA and MIPS
|
||||||
|
For ARM and THUMB, the format is <arch>[<sub-arch>][_VFP] where <sub-arch> is the ARM sub-architecture and the "_VFP" suffix means VFP coprocessor registers s0-s15 (d0-d7) are used for passing arguments or returning results in standard procedure-call. Both <sub-arch> and [_VFP] are optional. e.g. ARMV7, ARMV7_VFP, THUMBV7, THUMBV7_VFP and so on.
|
||||||
|
```
|
||||||
|
|
||||||
|
For example, if we want to enable classic interpreter, we can:
|
||||||
|
|
||||||
|
``` Bash
|
||||||
|
cmake .. -DWAMR_BUILD_FAST_INTERP=0
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note** the fast interpreter will run ~2X faster than classic interpreter, but it consumes about 2X memory to hold the WASM bytecode code.
|
||||||
|
|
||||||
|
If we want to disable interpreter, enable AOT and WASI, we can:
|
||||||
|
|
||||||
|
``` Bash
|
||||||
|
cmake .. -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_LIBC_WASI=0
|
||||||
|
```
|
||||||
|
|
||||||
|
Or if we want to enable inerpreter, disable AOT and WASI, and build as X86_32, we can:
|
||||||
|
|
||||||
|
``` Bash
|
||||||
|
cmake .. -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_AOT=0 -DWAMR_BUILD_LIBC_WASI=0 -DWAMR_BUILD_TARGET=X86_32
|
||||||
|
```
|
||||||
|
|
||||||
|
By default in Linux, the interpreter, AOT and WASI are enabled, and JIT is disabled. And the build target is
|
||||||
|
set to X86_64 or X86_32 depending on the platform's bitwidth.
|
||||||
|
|
||||||
|
To enable WASM JIT, firstly we should build LLVM:
|
||||||
|
|
||||||
|
``` Bash
|
||||||
|
cd product-mini/platforms/linux/
|
||||||
|
./build_llvm.sh (The llvm source code is cloned under <wamr_root_dir>/core/deps/llvm and auto built)
|
||||||
|
```
|
||||||
|
|
||||||
|
Then pass option -DWAMR_BUILD_JIT=1 to cmake to enable WASM JIT:
|
||||||
|
|
||||||
|
``` Bash
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake .. -DWAMR_BUILD_JIT=1
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Linux
|
Linux
|
||||||
-------------------------
|
-------------------------
|
||||||
First of all please install the dependent packages.
|
First of all please install the dependent packages.
|
||||||
Run command below in Ubuntu-18.04:
|
Run command below in Ubuntu-18.04:
|
||||||
|
|
||||||
``` Bash
|
``` Bash
|
||||||
sudo apt install build-essential cmake g++-multilib libgcc-8-dev lib32gcc-8-dev
|
sudo apt install build-essential cmake g++-multilib libgcc-8-dev lib32gcc-8-dev
|
||||||
```
|
```
|
||||||
|
@ -29,46 +89,13 @@ make
|
||||||
```
|
```
|
||||||
The binary file iwasm will be generated under build folder.
|
The binary file iwasm will be generated under build folder.
|
||||||
|
|
||||||
Note:
|
|
||||||
WAMR provides some features which can be easily configured by passing options to cmake:
|
|
||||||
``` Bash
|
|
||||||
cmake -DWAMR_BUILD_INTERP=1/0 to enable or disable WASM intepreter
|
|
||||||
cmake -DWAMR_BUILD_AOT=1/0 to enable or disable WASM AOT
|
|
||||||
cmake -DWAMR_BUILD_JIT=1/0 to enable or disable WASM JIT
|
|
||||||
cmake -DWAMR_BUILD_LIBC_BUILTIN=1/0 enable or disable Libc builtin API's
|
|
||||||
cmake -DWAMR_BUILD_LIBC_WASI=1/0 enable or disable Libc WASI API's
|
|
||||||
cmake -DWAMR_BUILD_TARGET=<arch> to set the building target, including:
|
|
||||||
X86_64, X86_32, ARM, THUMB, XTENSA and MIPS
|
|
||||||
For ARM and THUMB, the format is <arch>[<sub-arch>][_VFP] where <sub-arch> is the ARM sub-architecture and the "_VFP" suffix means VFP coprocessor registers s0-s15 (d0-d7) are used for passing arguments or returning results in standard procedure-call. Both <sub-arch> and [_VFP] are optional. e.g. ARMV7, ARMV7_VFP, THUMBV7, THUMBV7_VFP and so on.
|
|
||||||
```
|
|
||||||
|
|
||||||
For example, if we want to disable interpreter, enable AOT and WASI, we can:
|
|
||||||
``` Bash
|
|
||||||
cmake .. -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_AOT=1 -DWAMR_BUILD_LIBC_WASI=0
|
|
||||||
```
|
|
||||||
Or if we want to enable inerpreter, disable AOT and WASI, and build as X86_32, we can:
|
|
||||||
``` Bash
|
|
||||||
cmake .. -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_AOT=0 -DWAMR_BUILD_LIBC_WASI=0 -DWAMR_BUILD_TARGET=X86_32
|
|
||||||
```
|
|
||||||
|
|
||||||
By default in Linux, the interpreter, AOT and WASI are enabled, and JIT is disabled. And the build target is
|
|
||||||
set to X86_64 or X86_32 depending on the platform's bitwidth.
|
|
||||||
|
|
||||||
To enable WASM JIT, firstly we should build LLVM:
|
|
||||||
``` Bash
|
|
||||||
cd product-mini/platforms/linux/
|
|
||||||
./build_llvm.sh (The llvm source code is cloned under <wamr_root_dir>/core/deps/llvm and auto built)
|
|
||||||
```
|
|
||||||
Then pass option -DWAMR_BUILD_JIT=1 to cmake to enable WASM JIT:
|
|
||||||
``` Bash
|
|
||||||
mkdir build
|
|
||||||
cd build
|
|
||||||
cmake .. -DWAMR_BUILD_JIT=1
|
|
||||||
make
|
|
||||||
```
|
|
||||||
|
|
||||||
Linux SGX (Intel Software Guard Extention)
|
Linux SGX (Intel Software Guard Extention)
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
First of all please install the [Intel SGX SDK](https://software.intel.com/en-us/sgx/sdk).
|
First of all please install the [Intel SGX SDK](https://software.intel.com/en-us/sgx/sdk).
|
||||||
|
|
||||||
After installing dependencies, build the source code:
|
After installing dependencies, build the source code:
|
||||||
|
@ -122,11 +149,11 @@ VxWorks 7 SR0620 release is validated.
|
||||||
|
|
||||||
First you need to build a VSB. Make sure *UTILS_UNIX* layer is added in the VSB.
|
First you need to build a VSB. Make sure *UTILS_UNIX* layer is added in the VSB.
|
||||||
After the VSB is built, export the VxWorks toolchain path by:
|
After the VSB is built, export the VxWorks toolchain path by:
|
||||||
```
|
```bash
|
||||||
export <vsb_dir_path>/host/vx-compiler/bin:$PATH
|
export <vsb_dir_path>/host/vx-compiler/bin:$PATH
|
||||||
```
|
```
|
||||||
Now switch to iwasm source tree to build the source code:
|
Now switch to iwasm source tree to build the source code:
|
||||||
```
|
```bash
|
||||||
cd product-mini/platforms/vxworks/
|
cd product-mini/platforms/vxworks/
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
|
|
|
@ -20,20 +20,20 @@ Embedding WAMR guideline
|
||||||
|
|
||||||
// all the WAMR heap and WASM applications are limited in this buffer
|
// all the WAMR heap and WASM applications are limited in this buffer
|
||||||
bh_memory_init_with_pool(global_heap_buf, sizeof(global_heap_buf));
|
bh_memory_init_with_pool(global_heap_buf, sizeof(global_heap_buf));
|
||||||
|
|
||||||
wasm_runtime_init();
|
wasm_runtime_init();
|
||||||
|
|
||||||
// read WASM file into a memory buffer
|
// read WASM file into a memory buffer
|
||||||
buffer = read_wasm_binary_to_buffer(…, &size);
|
buffer = read_wasm_binary_to_buffer(…, &size);
|
||||||
|
|
||||||
// parse the WASM file from buffer and create a WASM module
|
// parse the WASM file from buffer and create a WASM module
|
||||||
module = wasm_runtime_load(buffer, size, error_buf, sizeof(error_buf));
|
module = wasm_runtime_load(buffer, size, error_buf, sizeof(error_buf));
|
||||||
|
|
||||||
// create an instance of the WASM module (WASM linear memory is ready)
|
// create an instance of the WASM module (WASM linear memory is ready)
|
||||||
module_inst = wasm_runtime_instantiate(module,
|
module_inst = wasm_runtime_instantiate(module,
|
||||||
stack_size,
|
stack_size,
|
||||||
heap_size,
|
heap_size,
|
||||||
error_buf,
|
error_buf,
|
||||||
sizeof(error_buf));
|
sizeof(error_buf));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -59,7 +59,6 @@ After a module is instantiated, the runtime native can lookup WASM functions by
|
||||||
|
|
||||||
// call the WASM function
|
// call the WASM function
|
||||||
if (wasm_runtime_call_wasm(exec_env, func, 1, argv) ) {
|
if (wasm_runtime_call_wasm(exec_env, func, 1, argv) ) {
|
||||||
|
|
||||||
/* the return value is stored in argv[0] */
|
/* the return value is stored in argv[0] */
|
||||||
printf("fib function return: %d\n", argv[0]);
|
printf("fib function return: %d\n", argv[0]);
|
||||||
}
|
}
|
||||||
|
@ -79,25 +78,24 @@ The parameters are transferred in an array of 32 bits elements. For parameters t
|
||||||
double arg3 = 1.0;
|
double arg3 = 1.0;
|
||||||
int 64 arg4 = 100;
|
int 64 arg4 = 100;
|
||||||
double ret;
|
double ret;
|
||||||
|
|
||||||
argv[0] = arg1;
|
argv[0] = arg1;
|
||||||
argv[1] = arg2;
|
argv[1] = arg2;
|
||||||
|
|
||||||
// use memory copy for 8 bytes parameters rather than
|
// use memory copy for 8 bytes parameters rather than
|
||||||
// *(double*)(&argv[2]) = arg3 here because some archs
|
// *(double*)(&argv[2]) = arg3 here because some archs
|
||||||
// like ARM, MIPS requires address is 8 aligned.
|
// like ARM, MIPS requires address is 8 aligned.
|
||||||
// Or use the aligned malloc or compiler align attribute
|
// Or use the aligned malloc or compiler align attribute
|
||||||
// to ensure the array address is 8 bytes aligned
|
// to ensure the array address is 8 bytes aligned
|
||||||
memcpy(&argv[2], &arg3, sizeof(arg3));
|
memcpy(&argv[2], &arg3, sizeof(arg3));
|
||||||
memcpy(&argv[4], &arg4, sizeof(arg4));
|
memcpy(&argv[4], &arg4, sizeof(arg4));
|
||||||
|
//
|
||||||
//
|
|
||||||
// attention: the arg number is 6 here since both
|
// attention: the arg number is 6 here since both
|
||||||
// arg3 and arg4 each takes 2 elements
|
// arg3 and arg4 each takes 2 elements
|
||||||
//
|
//
|
||||||
wasm_runtime_call_wasm(exec_env, func, 6, argv);
|
wasm_runtime_call_wasm(exec_env, func, 6, argv);
|
||||||
|
|
||||||
// if the return value is type of 8 bytes, it takes
|
// if the return value is type of 8 bytes, it takes
|
||||||
// the first two array elements
|
// the first two array elements
|
||||||
memcpy(&ret, &argv[0], sizeof(ret));
|
memcpy(&ret, &argv[0], sizeof(ret));
|
||||||
|
|
||||||
|
@ -109,7 +107,7 @@ The parameters are transferred in an array of 32 bits elements. For parameters t
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
If we need to transfer a buffer to WASM function, we can pass the buffer address through a parameter. **Attention**: The sandbox will forbid the WASM code to access outside memory, we must **allocate the buffer from WASM instance's own memory space and pass the buffer address in instance's space (not the runtime native address)**.
|
If we need to transfer a buffer to WASM function, we can pass the buffer address through a parameter. **Attention**: The sandbox will forbid the WASM code to access outside memory, we must **allocate the buffer from WASM instance's own memory space and pass the buffer address in instance's space (not the runtime native address)**.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -124,10 +122,10 @@ There are two runtime APIs available for this purpose.
|
||||||
* size: the buffer size to allocate
|
* size: the buffer size to allocate
|
||||||
*/
|
*/
|
||||||
int32_t
|
int32_t
|
||||||
wasm_runtime_module_malloc(wasm_module_inst_t module_inst,
|
wasm_runtime_module_malloc(wasm_module_inst_t module_inst,
|
||||||
uint32_t size,
|
uint32_t size,
|
||||||
void **p_native_addr);
|
void **p_native_addr);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* description: malloc a buffer from instance's private memory space,
|
* description: malloc a buffer from instance's private memory space,
|
||||||
* and copy the data from another native buffer to it.
|
* and copy the data from another native buffer to it.
|
||||||
|
@ -137,8 +135,8 @@ wasm_runtime_module_malloc(wasm_module_inst_t module_inst,
|
||||||
*/
|
*/
|
||||||
int32
|
int32
|
||||||
wasm_runtime_module_dup_data(WASMModuleInstanceCommon *module_inst,
|
wasm_runtime_module_dup_data(WASMModuleInstanceCommon *module_inst,
|
||||||
const char *src,
|
const char *src,
|
||||||
uint32 size);
|
uint32 size);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,7 +152,7 @@ if(buffer_for_wasm != 0)
|
||||||
{
|
{
|
||||||
unit32 argv[2];
|
unit32 argv[2];
|
||||||
strncpy(buffer, "hello", 100); // use native address for accessing in runtime
|
strncpy(buffer, "hello", 100); // use native address for accessing in runtime
|
||||||
argv[0] = buffer_for_wasm; // pass the buffer address for WASM space.
|
argv[0] = buffer_for_wasm; // pass the buffer address for WASM space.
|
||||||
argv[1] = 100; // the size of buffer
|
argv[1] = 100; // the size of buffer
|
||||||
wasm_runtime_call_wasm(exec_env, func, 2, argv);
|
wasm_runtime_call_wasm(exec_env, func, 2, argv);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,6 @@ Create folders:
|
||||||
Implement folder core/shared/platform/super-os. Normally in this folder you should implement the following files:
|
Implement folder core/shared/platform/super-os. Normally in this folder you should implement the following files:
|
||||||
- bh_platform.h and bh_platform.c: define the platform related macros, data types and APIs.
|
- bh_platform.h and bh_platform.c: define the platform related macros, data types and APIs.
|
||||||
- bh_assert.c: implement function bh_assert_internal() and bh_debug_internal().
|
- bh_assert.c: implement function bh_assert_internal() and bh_debug_internal().
|
||||||
- bh_definition.c: implement function b_memcpy_s, b_strcat_s and b_strcpy_s. And implement fopen_s
|
|
||||||
if we need to read wasm file from file system.
|
|
||||||
- bh_platform_log.c: implement function bh_log_emit, bh_fprintf and bh_fflush.
|
- bh_platform_log.c: implement function bh_log_emit, bh_fprintf and bh_fflush.
|
||||||
- bh_time.c: implement several time related functions.
|
- bh_time.c: implement several time related functions.
|
||||||
- bh_thread.c: implement thread, mutex, condition related functions.
|
- bh_thread.c: implement thread, mutex, condition related functions.
|
||||||
|
|
|
@ -71,7 +71,6 @@ GLOBAL_INCLUDES += ${IWASM_ROOT}/aot
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(NAME)_SOURCES := ${SHARED_ROOT}/platform/alios/bh_assert.c \
|
$(NAME)_SOURCES := ${SHARED_ROOT}/platform/alios/bh_assert.c \
|
||||||
${SHARED_ROOT}/platform/alios/bh_definition.c \
|
|
||||||
${SHARED_ROOT}/platform/alios/bh_math.c \
|
${SHARED_ROOT}/platform/alios/bh_math.c \
|
||||||
${SHARED_ROOT}/platform/alios/bh_platform.c \
|
${SHARED_ROOT}/platform/alios/bh_platform.c \
|
||||||
${SHARED_ROOT}/platform/alios/bh_platform_log.c \
|
${SHARED_ROOT}/platform/alios/bh_platform_log.c \
|
||||||
|
@ -82,6 +81,7 @@ $(NAME)_SOURCES := ${SHARED_ROOT}/platform/alios/bh_assert.c \
|
||||||
${SHARED_ROOT}/mem-alloc/ems/ems_kfc.c \
|
${SHARED_ROOT}/mem-alloc/ems/ems_kfc.c \
|
||||||
${SHARED_ROOT}/mem-alloc/ems/ems_alloc.c \
|
${SHARED_ROOT}/mem-alloc/ems/ems_alloc.c \
|
||||||
${SHARED_ROOT}/mem-alloc/ems/ems_hmu.c \
|
${SHARED_ROOT}/mem-alloc/ems/ems_hmu.c \
|
||||||
|
${SHARED_ROOT}/utils/bh_definition.c \
|
||||||
${SHARED_ROOT}/utils/bh_hashmap.c \
|
${SHARED_ROOT}/utils/bh_hashmap.c \
|
||||||
${SHARED_ROOT}/utils/bh_list.c \
|
${SHARED_ROOT}/utils/bh_list.c \
|
||||||
${SHARED_ROOT}/utils/bh_log.c \
|
${SHARED_ROOT}/utils/bh_log.c \
|
||||||
|
|
|
@ -52,6 +52,11 @@ if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
|
||||||
set (WAMR_BUILD_LIBC_WASI 1)
|
set (WAMR_BUILD_LIBC_WASI 1)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
|
||||||
|
# Enable fast interpreter
|
||||||
|
set (WAMR_BUILD_FAST_INTERP 1)
|
||||||
|
endif ()
|
||||||
|
|
||||||
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
|
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
|
||||||
|
|
||||||
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
||||||
|
|
|
@ -155,6 +155,7 @@ int main(int argc, char *argv[])
|
||||||
uint32 wasm_file_size;
|
uint32 wasm_file_size;
|
||||||
wasm_module_t wasm_module = NULL;
|
wasm_module_t wasm_module = NULL;
|
||||||
wasm_module_inst_t wasm_module_inst = NULL;
|
wasm_module_inst_t wasm_module_inst = NULL;
|
||||||
|
RuntimeInitArgs init_args;
|
||||||
char error_buf[128] = { 0 };
|
char error_buf[128] = { 0 };
|
||||||
#if WASM_ENABLE_LOG != 0
|
#if WASM_ENABLE_LOG != 0
|
||||||
int log_verbose_level = 2;
|
int log_verbose_level = 2;
|
||||||
|
@ -228,35 +229,35 @@ int main(int argc, char *argv[])
|
||||||
app_argc = argc;
|
app_argc = argc;
|
||||||
app_argv = argv;
|
app_argv = argv;
|
||||||
|
|
||||||
|
memset(&init_args, 0, sizeof(RuntimeInitArgs));
|
||||||
|
|
||||||
#if USE_GLOBAL_HEAP_BUF != 0
|
#if USE_GLOBAL_HEAP_BUF != 0
|
||||||
if (bh_memory_init_with_pool(global_heap_buf, sizeof(global_heap_buf))
|
init_args.mem_alloc_type = Alloc_With_Pool;
|
||||||
!= 0) {
|
init_args.mem_alloc.pool.heap_buf = global_heap_buf;
|
||||||
bh_printf("Init memory with global heap buffer failed.\n");
|
init_args.mem_alloc.pool.heap_size = sizeof(global_heap_buf);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
if (bh_memory_init_with_allocator(malloc, free)) {
|
init_args.mem_alloc_type = Alloc_With_Allocator;
|
||||||
bh_printf("Init memory with memory allocator failed.\n");
|
init_args.mem_alloc.allocator.malloc_func = malloc;
|
||||||
return -1;
|
init_args.mem_alloc.allocator.free_func = free;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* initialize runtime environment */
|
if (!wasm_runtime_full_init(&init_args)) {
|
||||||
if (!wasm_runtime_init())
|
bh_printf("Init runtime environment failed.\n");
|
||||||
goto fail1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
bh_log_set_verbose_level(log_verbose_level);
|
bh_log_set_verbose_level(log_verbose_level);
|
||||||
|
|
||||||
/* load WASM byte buffer from WASM bin file */
|
/* load WASM byte buffer from WASM bin file */
|
||||||
if (!(wasm_file_buf = (uint8*) bh_read_file_to_buffer(wasm_file,
|
if (!(wasm_file_buf = (uint8*) bh_read_file_to_buffer(wasm_file,
|
||||||
&wasm_file_size)))
|
&wasm_file_size)))
|
||||||
goto fail2;
|
goto fail1;
|
||||||
|
|
||||||
/* load WASM module */
|
/* load WASM module */
|
||||||
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
|
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
|
||||||
error_buf, sizeof(error_buf)))) {
|
error_buf, sizeof(error_buf)))) {
|
||||||
bh_printf("%s\n", error_buf);
|
bh_printf("%s\n", error_buf);
|
||||||
goto fail3;
|
goto fail2;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WASM_ENABLE_LIBC_WASI != 0
|
#if WASM_ENABLE_LIBC_WASI != 0
|
||||||
|
@ -274,7 +275,7 @@ int main(int argc, char *argv[])
|
||||||
error_buf,
|
error_buf,
|
||||||
sizeof(error_buf)))) {
|
sizeof(error_buf)))) {
|
||||||
bh_printf("%s\n", error_buf);
|
bh_printf("%s\n", error_buf);
|
||||||
goto fail4;
|
goto fail3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_repl_mode)
|
if (is_repl_mode)
|
||||||
|
@ -287,20 +288,17 @@ int main(int argc, char *argv[])
|
||||||
/* destroy the module instance */
|
/* destroy the module instance */
|
||||||
wasm_runtime_deinstantiate(wasm_module_inst);
|
wasm_runtime_deinstantiate(wasm_module_inst);
|
||||||
|
|
||||||
fail4:
|
fail3:
|
||||||
/* unload the module */
|
/* unload the module */
|
||||||
wasm_runtime_unload(wasm_module);
|
wasm_runtime_unload(wasm_module);
|
||||||
|
|
||||||
fail3:
|
fail2:
|
||||||
/* free the file buffer */
|
/* free the file buffer */
|
||||||
bh_free(wasm_file_buf);
|
bh_free(wasm_file_buf);
|
||||||
|
|
||||||
fail2:
|
|
||||||
/* destroy runtime environment */
|
|
||||||
wasm_runtime_destroy();
|
|
||||||
|
|
||||||
fail1:
|
fail1:
|
||||||
bh_memory_destroy();
|
/* destroy runtime environment */
|
||||||
|
wasm_runtime_full_destroy();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user