Update README, change wasi primitive lib position and add some exception checks (#146)
Add exception throw when some initial checks fail in executing main or specific function
This commit is contained in:
198
doc/build_wamr.md
Normal file
198
doc/build_wamr.md
Normal file
@ -0,0 +1,198 @@
|
||||
|
||||
Build WAMR Core
|
||||
=========================
|
||||
Please follow the instructions below to build the WAMR core on different platforms.
|
||||
|
||||
Linux
|
||||
-------------------------
|
||||
First of all please install library dependencies of lib gcc.
|
||||
Use installation commands below for Ubuntu Linux:
|
||||
``` Bash
|
||||
sudo apt install lib32gcc-5-dev g++-multilib
|
||||
```
|
||||
Or in Fedora:
|
||||
``` Bash
|
||||
sudo dnf install glibc-devel.i686
|
||||
```
|
||||
|
||||
After installing dependencies, build the source code:
|
||||
``` Bash
|
||||
cd core/iwasm/products/linux/
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
Note:
|
||||
The WASI feature is enabled by default, if we want to disable it, please run:
|
||||
``` Bash
|
||||
cmake .. -DWASM_ENALBE_WASI=0
|
||||
```
|
||||
|
||||
Linux SGX (Intel Software Guard Extention)
|
||||
-------------------------
|
||||
First of all please install library dependencies of lib gcc.
|
||||
Use installation commands below for Ubuntu Linux:
|
||||
``` Bash
|
||||
sudo apt install lib32gcc-5-dev g++-multilib
|
||||
```
|
||||
Or in Fedora:
|
||||
``` Bash
|
||||
sudo dnf install glibc-devel.i686
|
||||
```
|
||||
|
||||
And then install the [Intel SGX SDK](https://software.intel.com/en-us/sgx/sdk).
|
||||
|
||||
After installing dependencies, build the source code:
|
||||
``` Bash
|
||||
source <SGX_SDK dir>/environment
|
||||
cd core/iwasm/products/linux-sgx/
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
This builds the libraries used by SGX enclave sample, the generated file libvmlib.a and libextlib.a will be copied to enclave-sample folder.
|
||||
|
||||
Then build the enclave sample:
|
||||
``` Bash
|
||||
source <SGX_SDK dir>/environment
|
||||
cd enclave-sample
|
||||
make
|
||||
```
|
||||
The binary file app will be generated.
|
||||
|
||||
To run the sample:
|
||||
``` Bash
|
||||
source <SGX_SDK dir>/environment
|
||||
./app
|
||||
```
|
||||
|
||||
Mac
|
||||
-------------------------
|
||||
Make sure to install Xcode from App Store firstly, and install cmake.
|
||||
|
||||
If you use Homebrew, install cmake from the command line:
|
||||
``` Bash
|
||||
brew install cmake
|
||||
```
|
||||
|
||||
Then build the source codes:
|
||||
```
|
||||
cd core/iwasm/products/darwin/
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
|
||||
VxWorks
|
||||
-------------------------
|
||||
VxWorks 7 SR0620 release is validated.
|
||||
|
||||
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:
|
||||
```
|
||||
export <vsb_dir_path>/host/vx-compiler/bin:$PATH
|
||||
```
|
||||
Now switch to iwasm source tree to build the source code:
|
||||
```
|
||||
cd core/iwasm/products/vxworks/
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
Create a VIP based on the VSB. Make sure the following components are added:
|
||||
* INCLUDE_POSIX_PTHREADS
|
||||
* INCLUDE_POSIX_PTHREAD_SCHEDULER
|
||||
* INCLUDE_SHARED_DATA
|
||||
* INCLUDE_SHL
|
||||
|
||||
Copy the generated iwasm executable, the test WASM binary as well as the needed
|
||||
shared libraries (libc.so.1, libllvm.so.1 or libgnu.so.1 depending on the VSB,
|
||||
libunix.so.1) to a supported file system (eg: romfs).
|
||||
|
||||
WASI
|
||||
-------------------------
|
||||
On Linux, WASI is enabled by default. To build iwasm without wasi support, pass an option when you run cmake:
|
||||
```
|
||||
cmake .. -DWASM_ENABLE_WASI=0
|
||||
make
|
||||
```
|
||||
|
||||
Zephyr
|
||||
-------------------------
|
||||
You need to download the Zephyr source code first and embed WAMR into it.
|
||||
``` Bash
|
||||
git clone https://github.com/zephyrproject-rtos/zephyr.git
|
||||
cd zephyr/samples/
|
||||
cp -a <iwasm_dir>/products/zephyr/simple .
|
||||
cd simple
|
||||
ln -s <iwam_dir> iwasm
|
||||
ln -s <shared_lib_dir> shared-lib
|
||||
mkdir build && cd build
|
||||
source ../../../zephyr-env.sh
|
||||
cmake -GNinja -DBOARD=qemu_x86 ..
|
||||
ninja
|
||||
```
|
||||
|
||||
AliOS-Things
|
||||
-------------------------
|
||||
1. a developerkit board id needed for testing
|
||||
2. download the AliOS-Things code
|
||||
``` Bash
|
||||
git clone https://github.com/alibaba/AliOS-Things.git
|
||||
```
|
||||
3. copy <iwasm_root_dir>/products/alios-things directory to AliOS-Things/middleware, and rename it as iwasm
|
||||
``` Bash
|
||||
cp -a <iwasm_root_dir>/products/alios-things middleware/iwasm
|
||||
```
|
||||
4. create a link to <iwasm_root_dir> in middleware/iwasm/ and rename it to iwasm
|
||||
``` Bash
|
||||
ln -s <iwasm_root_dir> middleware/iwasm/iwasm
|
||||
```
|
||||
5. create a link to <shared-lib_root_dir> in middleware/iwasm/ and rename it to shared-lib
|
||||
``` Bash
|
||||
ln -s <shared-lib_root_dir> middle/iwasm/shared-lib
|
||||
```
|
||||
6. modify file app/example/helloworld/helloworld.c, patch as:
|
||||
``` C
|
||||
#include <stdbool.h>
|
||||
#include <aos/kernel.h>
|
||||
extern bool iwasm_init();
|
||||
int application_start(int argc, char *argv[])
|
||||
{
|
||||
int count = 0;
|
||||
iwasm_init();
|
||||
...
|
||||
}
|
||||
```
|
||||
7. modify file app/example/helloworld/aos.mk
|
||||
``` C
|
||||
$(NAME)_COMPONENTS := osal_aos iwasm
|
||||
```
|
||||
8. build source code
|
||||
``` Bash
|
||||
aos make helloworld@developerkit -c config
|
||||
aos make
|
||||
```
|
||||
9. download the binary to developerkit board, check the output from serial port
|
||||
|
||||
Docker
|
||||
-------------------------
|
||||
[Docker](https://www.docker.com/) will download all the dependencies and build WAMR Core on your behalf.
|
||||
|
||||
Make sure you have Docker installed on your machine: [macOS](https://docs.docker.com/docker-for-mac/install/), [Windows](https://docs.docker.com/docker-for-windows/install/) or [Linux](https://docs.docker.com/install/linux/docker-ce/ubuntu/).
|
||||
|
||||
Build the Docker image:
|
||||
|
||||
``` Bash
|
||||
docker build --rm -f "Dockerfile" -t wamr:latest .
|
||||
```
|
||||
Run the image in interactive mode:
|
||||
``` Bash
|
||||
docker run --rm -it wamr:latest
|
||||
```
|
||||
You'll now enter the container at `/root`.
|
||||
|
||||
@ -1,201 +1,4 @@
|
||||
|
||||
Build WAMR Core
|
||||
=========================
|
||||
Please follow the instructions below to build the WAMR core on different platforms.
|
||||
|
||||
Linux
|
||||
-------------------------
|
||||
First of all please install library dependencies of lib gcc.
|
||||
Use installation commands below for Ubuntu Linux:
|
||||
``` Bash
|
||||
sudo apt install lib32gcc-5-dev g++-multilib
|
||||
```
|
||||
Or in Fedora:
|
||||
``` Bash
|
||||
sudo dnf install glibc-devel.i686
|
||||
```
|
||||
|
||||
After installing dependencies, build the source code:
|
||||
``` Bash
|
||||
cd core/iwasm/products/linux/
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
Note:
|
||||
The WASI feature is enabled by default, if we want to disable it, please run:
|
||||
``` Bash
|
||||
cmake .. -DWASM_ENALBE_WASI=0
|
||||
```
|
||||
|
||||
Linux SGX (Intel Software Guard Extention)
|
||||
-------------------------
|
||||
First of all please install library dependencies of lib gcc.
|
||||
Use installation commands below for Ubuntu Linux:
|
||||
``` Bash
|
||||
sudo apt install lib32gcc-5-dev g++-multilib
|
||||
```
|
||||
Or in Fedora:
|
||||
``` Bash
|
||||
sudo dnf install glibc-devel.i686
|
||||
```
|
||||
|
||||
And then install the [Intel SGX SDK](https://software.intel.com/en-us/sgx/sdk).
|
||||
|
||||
After installing dependencies, build the source code:
|
||||
``` Bash
|
||||
source <SGX_SDK dir>/environment
|
||||
cd core/iwasm/products/linux-sgx/
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
This builds the libraries used by SGX enclave sample, the generated file libvmlib.a and libextlib.a will be copied to enclave-sample folder.
|
||||
|
||||
Then build the enclave sample:
|
||||
``` Bash
|
||||
source <SGX_SDK dir>/environment
|
||||
cd enclave-sample
|
||||
make
|
||||
```
|
||||
The binary file app will be generated.
|
||||
|
||||
To run the sample:
|
||||
``` Bash
|
||||
source <SGX_SDK dir>/environment
|
||||
./app
|
||||
```
|
||||
|
||||
Mac
|
||||
-------------------------
|
||||
Make sure to install Xcode from App Store firstly, and install cmake.
|
||||
|
||||
If you use Homebrew, install cmake from the command line:
|
||||
``` Bash
|
||||
brew install cmake
|
||||
```
|
||||
|
||||
Then build the source codes:
|
||||
```
|
||||
cd core/iwasm/products/darwin/
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
|
||||
VxWorks
|
||||
-------------------------
|
||||
VxWorks 7 SR0620 release is validated.
|
||||
|
||||
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:
|
||||
```
|
||||
export <vsb_dir_path>/host/vx-compiler/bin:$PATH
|
||||
```
|
||||
Now switch to iwasm source tree to build the source code:
|
||||
```
|
||||
cd core/iwasm/products/vxworks/
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
Create a VIP based on the VSB. Make sure the following components are added:
|
||||
* INCLUDE_POSIX_PTHREADS
|
||||
* INCLUDE_POSIX_PTHREAD_SCHEDULER
|
||||
* INCLUDE_SHARED_DATA
|
||||
* INCLUDE_SHL
|
||||
|
||||
Copy the generated iwasm executable, the test WASM binary as well as the needed
|
||||
shared libraries (libc.so.1, libllvm.so.1 or libgnu.so.1 depending on the VSB,
|
||||
libunix.so.1) to a supported file system (eg: romfs).
|
||||
|
||||
WASI
|
||||
-------------------------
|
||||
On Linux / Mac / VxWorks platforms, WASI is enabled by default. To build iwasm without wasi support, pass an option when you run cmake:
|
||||
```
|
||||
cmake .. -DWASM_ENABLE_WASI=0
|
||||
make
|
||||
```
|
||||
|
||||
Zephyr
|
||||
-------------------------
|
||||
You need to download the Zephyr source code first and embed WAMR into it.
|
||||
``` Bash
|
||||
git clone https://github.com/zephyrproject-rtos/zephyr.git
|
||||
cd zephyr/samples/
|
||||
cp -a <iwasm_dir>/products/zephyr/simple .
|
||||
cd simple
|
||||
ln -s <iwam_dir> iwasm
|
||||
ln -s <shared_lib_dir> shared-lib
|
||||
mkdir build && cd build
|
||||
source ../../../zephyr-env.sh
|
||||
cmake -GNinja -DBOARD=qemu_x86 ..
|
||||
ninja
|
||||
```
|
||||
|
||||
AliOS-Things
|
||||
-------------------------
|
||||
1. a developerkit board id needed for testing
|
||||
2. download the AliOS-Things code
|
||||
``` Bash
|
||||
git clone https://github.com/alibaba/AliOS-Things.git
|
||||
```
|
||||
3. copy <iwasm_root_dir>/products/alios-things directory to AliOS-Things/middleware, and rename it as iwasm
|
||||
``` Bash
|
||||
cp -a <iwasm_root_dir>/products/alios-things middleware/iwasm
|
||||
```
|
||||
4. create a link to <iwasm_root_dir> in middleware/iwasm/ and rename it to iwasm
|
||||
``` Bash
|
||||
ln -s <iwasm_root_dir> middleware/iwasm/iwasm
|
||||
```
|
||||
5. create a link to <shared-lib_root_dir> in middleware/iwasm/ and rename it to shared-lib
|
||||
``` Bash
|
||||
ln -s <shared-lib_root_dir> middle/iwasm/shared-lib
|
||||
```
|
||||
6. modify file app/example/helloworld/helloworld.c, patch as:
|
||||
``` C
|
||||
#include <stdbool.h>
|
||||
#include <aos/kernel.h>
|
||||
extern bool iwasm_init();
|
||||
int application_start(int argc, char *argv[])
|
||||
{
|
||||
int count = 0;
|
||||
iwasm_init();
|
||||
...
|
||||
}
|
||||
```
|
||||
7. modify file app/example/helloworld/aos.mk
|
||||
``` C
|
||||
$(NAME)_COMPONENTS := osal_aos iwasm
|
||||
```
|
||||
8. build source code
|
||||
``` Bash
|
||||
aos make helloworld@developerkit -c config
|
||||
aos make
|
||||
```
|
||||
9. download the binary to developerkit board, check the output from serial port
|
||||
|
||||
Docker
|
||||
-------------------------
|
||||
[Docker](https://www.docker.com/) will download all the dependencies and build WAMR Core on your behalf.
|
||||
|
||||
Make sure you have Docker installed on your machine: [macOS](https://docs.docker.com/docker-for-mac/install/), [Windows](https://docs.docker.com/docker-for-windows/install/) or [Linux](https://docs.docker.com/install/linux/docker-ce/ubuntu/).
|
||||
|
||||
Build the Docker image:
|
||||
|
||||
``` Bash
|
||||
docker build --rm -f "Dockerfile" -t wamr:latest .
|
||||
```
|
||||
Run the image in interactive mode:
|
||||
``` Bash
|
||||
docker run --rm -it wamr:latest
|
||||
```
|
||||
You'll now enter the container at `/root`.
|
||||
|
||||
|
||||
Build WASM app
|
||||
=========================
|
||||
116
doc/export_native_api.md
Normal file
116
doc/export_native_api.md
Normal file
@ -0,0 +1,116 @@
|
||||
|
||||
The mechanism of exporting native API to WASM application
|
||||
=======================================================
|
||||
|
||||
The basic working flow for WASM application calling into the native API is shown in the following diagram:
|
||||
|
||||

|
||||
|
||||
|
||||
WAMR provides the macro `EXPORT_WASM_API` to enable users to export a native API to a WASM application. WAMR has implemented a base API for the timer and messaging by using `EXPORT_WASM_API`. This can be a point of reference for extending your own library.
|
||||
``` C
|
||||
static NativeSymbol extended_native_symbol_defs[] = {
|
||||
EXPORT_WASM_API(wasm_register_resource),
|
||||
EXPORT_WASM_API(wasm_response_send),
|
||||
EXPORT_WASM_API(wasm_post_request),
|
||||
EXPORT_WASM_API(wasm_sub_event),
|
||||
EXPORT_WASM_API(wasm_create_timer),
|
||||
EXPORT_WASM_API(wasm_timer_set_interval),
|
||||
EXPORT_WASM_API(wasm_timer_cancel),
|
||||
EXPORT_WASM_API(wasm_timer_restart)
|
||||
};
|
||||
```
|
||||
|
||||
 **Security attention:** A WebAssembly application should only have access to its own memory space. As a result, the integrator should carefully design the native function to ensure that the memory accesses are safe. The native API to be exported to the WASM application must:
|
||||
- Only use 32 bits number for parameters
|
||||
- Should not pass data to the structure pointer (do data serialization instead)
|
||||
- Should do the pointer address conversion in the native API
|
||||
- Should not pass function pointer as callback
|
||||
|
||||
Below is a sample of a library extension. All code invoked across WASM and native world must be serialized and de-serialized, and the native world must do a boundary check for every incoming address from the WASM world.
|
||||
|
||||
|
||||
<img src="./pics/safe.PNG" width="90%">
|
||||
|
||||
|
||||
Steps for exporting native API
|
||||
==========================
|
||||
|
||||
WAMR implemented a framework for developers to export API's. Below is the procedure to expose the platform API's in three steps:
|
||||
|
||||
**Step 1. Create a header file**<br/>
|
||||
Declare the API's for your WASM application source project to include.
|
||||
|
||||
**Step 2. Create a source file**<br/>
|
||||
Export the platform API's, for example in ``` products/linux/ext_lib_export.c ```
|
||||
``` C
|
||||
#include "lib_export.h"
|
||||
|
||||
static NativeSymbol extended_native_symbol_defs[] =
|
||||
{
|
||||
};
|
||||
|
||||
#include "ext_lib_export.h"
|
||||
```
|
||||
|
||||
**Step 3. Register new API's**<br/>
|
||||
Use the macro `EXPORT_WASM_API` and `EXPORT_WASM_API2` to add exported API's into the array of ```extended_native_symbol_defs```.
|
||||
The pre-defined MACRO `EXPORT_WASM_API` should be used to declare a function export:
|
||||
``` c
|
||||
#define EXPORT_WASM_API(symbol) {#symbol, symbol}
|
||||
```
|
||||
|
||||
Below code example shows how to extend the library to support `customized()`:
|
||||
|
||||
```
|
||||
//lib_export_impl.c
|
||||
void customized()
|
||||
{
|
||||
// your code
|
||||
}
|
||||
|
||||
|
||||
// lib_export_dec.h
|
||||
#ifndef _LIB_EXPORT_DEC_H_
|
||||
#define _LIB_EXPORT_DEC_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void customized();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// ext_lib_export.c
|
||||
#include "lib_export.h"
|
||||
#include "lib_export_dec.h"
|
||||
|
||||
static NativeSymbol extended_native_symbol_defs[] =
|
||||
{
|
||||
EXPORT_WASM_API(customized)
|
||||
};
|
||||
|
||||
#include "ext_lib_export.h"
|
||||
```
|
||||
|
||||
Use extended library
|
||||
------------------------
|
||||
In the application source project, it will include the WAMR built-in API's header file and platform extension header files. Assuming the board vendor extends the library which added an API called customized(), the WASM application would be like this:
|
||||
``` C
|
||||
#include <stdio.h>
|
||||
#include "lib_export_dec.h" // provided by the platform vendor
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int I;
|
||||
char *buf = “abcd”;
|
||||
customized(); // customized API provided by the platform vendor
|
||||
return i;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
118
doc/wamr_api.md
118
doc/wamr_api.md
@ -1,5 +1,5 @@
|
||||
|
||||
WASM application library
|
||||
WAMR application library
|
||||
========================
|
||||
|
||||
WAMR APP API includes built-in Libc API's, Base library and Extension library reference.
|
||||
@ -89,120 +89,6 @@ bool api_config_connection(connection_t *conn, attr_container_t *cfg);
|
||||
```
|
||||
GUI API: The API's is list in header file ```lib/app-libs/extension/gui/wgl.h``` which is implemented based open soure 2D graphic library [LittlevGL](https://docs.littlevgl.com/en/html/index.html). Currently supported widgets include button, label, list and check box and more wigdet would be provided in future.
|
||||
|
||||
The mechanism of exporting native API to WASM application
|
||||
=======================================================
|
||||
|
||||
The basic working flow for WASM application calling into the native API is shown in the following diagram:
|
||||
|
||||

|
||||
|
||||
|
||||
WAMR provides the macro `EXPORT_WASM_API` to enable users to export a native API to a WASM application. WAMR has implemented a base API for the timer and messaging by using `EXPORT_WASM_API`. This can be a point of reference for extending your own library.
|
||||
``` C
|
||||
static NativeSymbol extended_native_symbol_defs[] = {
|
||||
EXPORT_WASM_API(wasm_register_resource),
|
||||
EXPORT_WASM_API(wasm_response_send),
|
||||
EXPORT_WASM_API(wasm_post_request),
|
||||
EXPORT_WASM_API(wasm_sub_event),
|
||||
EXPORT_WASM_API(wasm_create_timer),
|
||||
EXPORT_WASM_API(wasm_timer_set_interval),
|
||||
EXPORT_WASM_API(wasm_timer_cancel),
|
||||
EXPORT_WASM_API(wasm_timer_restart)
|
||||
};
|
||||
```
|
||||
|
||||
 **Security attention:** A WebAssembly application should only have access to its own memory space. As a result, the integrator should carefully design the native function to ensure that the memory accesses are safe. The native API to be exported to the WASM application must:
|
||||
- Only use 32 bits number for parameters
|
||||
- Should not pass data to the structure pointer (do data serialization instead)
|
||||
- Should do the pointer address conversion in the native API
|
||||
- Should not pass function pointer as callback
|
||||
|
||||
Below is a sample of a library extension. All code invoked across WASM and native world must be serialized and de-serialized, and the native world must do a boundary check for every incoming address from the WASM world.
|
||||
|
||||
|
||||
<img src="./pics/safe.PNG" width="90%">
|
||||
|
||||
|
||||
Steps for exporting native API
|
||||
==========================
|
||||
|
||||
WAMR implemented a framework for developers to export API's. Below is the procedure to expose the platform API's in three steps:
|
||||
|
||||
**Step 1. Create a header file**<br/>
|
||||
Declare the API's for your WASM application source project to include.
|
||||
|
||||
**Step 2. Create a source file**<br/>
|
||||
Export the platform API's, for example in ``` products/linux/ext_lib_export.c ```
|
||||
``` C
|
||||
#include "lib_export.h"
|
||||
|
||||
static NativeSymbol extended_native_symbol_defs[] =
|
||||
{
|
||||
};
|
||||
|
||||
#include "ext_lib_export.h"
|
||||
```
|
||||
|
||||
**Step 3. Register new API's**<br/>
|
||||
Use the macro `EXPORT_WASM_API` and `EXPORT_WASM_API2` to add exported API's into the array of ```extended_native_symbol_defs```.
|
||||
The pre-defined MACRO `EXPORT_WASM_API` should be used to declare a function export:
|
||||
``` c
|
||||
#define EXPORT_WASM_API(symbol) {#symbol, symbol}
|
||||
```
|
||||
|
||||
Below code example shows how to extend the library to support `customized()`:
|
||||
|
||||
```
|
||||
//lib_export_impl.c
|
||||
void customized()
|
||||
{
|
||||
// your code
|
||||
}
|
||||
|
||||
|
||||
// lib_export_dec.h
|
||||
#ifndef _LIB_EXPORT_DEC_H_
|
||||
#define _LIB_EXPORT_DEC_H_
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void customized();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// ext_lib_export.c
|
||||
#include "lib_export.h"
|
||||
#include "lib_export_dec.h"
|
||||
|
||||
static NativeSymbol extended_native_symbol_defs[] =
|
||||
{
|
||||
EXPORT_WASM_API(customized)
|
||||
};
|
||||
|
||||
#include "ext_lib_export.h"
|
||||
```
|
||||
|
||||
Use extended library
|
||||
------------------------
|
||||
In the application source project, it will include the WAMR built-in API's header file and platform extension header files. Assuming the board vendor extends the library which added an API called customized(), the WASM application would be like this:
|
||||
``` C
|
||||
#include <stdio.h>
|
||||
#include "lib_export_dec.h" // provided by the platform vendor
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int I;
|
||||
char *buf = “abcd”;
|
||||
customized(); // customized API provided by the platform vendor
|
||||
return i;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Communication programming models
|
||||
=========================
|
||||
@ -307,4 +193,4 @@ void on_destroy()
|
||||
{
|
||||
}
|
||||
```
|
||||
**Note:** You can also subscribe this event from host side by using host tool. Please refer `samples/simple` project for deail usage.
|
||||
**Note:** You can also subscribe this event from host side by using host tool. Please refer `samples/simple` project for deail usage.
|
||||
|
||||
Reference in New Issue
Block a user