Updates to the Readme (#15)

Update README.md
This commit is contained in:
Johnnie Birch 2019-05-11 06:05:43 -07:00 committed by Wang Xin
parent 31de47bd92
commit 62605cfb2e

View File

@ -1,22 +1,25 @@
WebAssembly Micro Runtime
=========================
WebAssembly Micro Runtime (WAMR) is standalone WebAssembly (WASM) runtime with a small footprint. It includes a few components:
- WebAssembly VM core
- WASM application programming API (code available, but compilation depends on the app manager component)
- Dynamic WASM application management (Not available on Github yet. It will be released soon)
WebAssembly Micro Runtime (WAMR) is standalone WebAssembly (WASM) runtime designed for a small footprint. It includes:
- A WebAssembly (WASM) VM core
- The supporting APIs for the WASM applications (code is available but compilation depends on the app manager component)
- A mechanism for dynamic management of the WASM application (Not available on Github yet. To be released soon)
Why should you use a WASM runtime out of your browser? There are a few points where this might be meaningful:
1. WASM is already a LLVM official backend target. That means WASM can run any programming languages which can be compiled to LLVM IR. It is a huge advantage compared to language bound runtimes like JS or Lua.
2. WASM is an open standard and it is fast becoming supported by the whole web ecosystem.
3. WASM is designed to be very friendly for compiling to native binaries and gaining the native speed.
4. It can potentially change the development practices. Imagine we can do both the WASM application development and validation in a browser, then just download the WASM binary code onto the target device.
Why should you use a WASM runtime out of your browser? There are a few points where this might be meaningful:
1. WASM is already a LLVM official backend target. That means WASM can run any programming languages which can be compiled to LLVM IR. It is a huge advantage compared to language bound runtimes like JS or Lua.
2. WASM is an open standard and it is fast becoming supported by the whole web ecosystem.
3. WASM is designed to be very friendly for compiling to native binaries and gaining the native speed.
4. It can potentially change the development practices. Imagine we can do both the WASM application development and validation in a browser, then just download the WASM binary code onto the target device.
5. WASM can work without garbage collection. It is designed to support execution determinics for the time sensitive requirement.
6. Maintain the safety goals WASM has of providing a sandboxed execution enviornment for untrusted code. In addition, because WASM is a compilation target, this implies a benefit of being able to target both an execution and security profile that is consistent across popular high-level programming languages.
Features
Current Features of WAMR
=========================
- WASM interpreter (AOT is planned)
- Provides built-in Libc subset, supports "side_module=1" EMCC compilation option
- Provides support for a subset of Lib.
- Supports "side_module=1" EMCC compilation option
- Provides API's for embedding runtime into production software
- Provides a mechanism for exporting native API's to WASM applications
- Supports the programming of firmware apps in a large range of languages (C/C++/Java/Rust/Go/TypeScript etc.)
@ -28,17 +31,17 @@ Features
Architecture
=========================
The application manager component handles the packets that the platform receives from external sources through any communication buses such as socket, serial port or PSI. A packet type can be either a request, response or event. The app manager will serve the requests with URI "/applet" and call the runtime glue layer interfaces for installing/uninstalling the application. For other URI's, it will filter the resource registration table and route the request to the internal queue of the responsible application.
The application manager component handles the packets that the platform receives from external sources through any communication buses such as a socket, serial port or PSI. A packet type can be either a request, response or an event. The app manager will serve the requests with URI "/applet" and call the runtime glue layer interfaces for installing/uninstalling the application. For other URI's, it will filter the resource registration table and route the request to the internal queue of the responsible application.
The WebAssembly runtime is the execution environment for WASM applications.
- The WebAssembly runtime provides the execution environment for WASM applications.
The messaging layer can support the API for WASM applications to communicate to each other and also the host environment.
- The messaging layer can support the API for WASM applications to communicate to each other and also the host environment.
When Ahead of Time compilation is enabled, the WASM application can be either bytecode or a compiled native binary.
- When ahead of time (AOT) compilation is enabled (TODO), the WASM application could be either WASM or a compiled native binary.
<img src="./doc/pics/architecture.PNG" width="80%" height="80%">
Build WAMR Core
=========================
@ -47,7 +50,7 @@ Please follow the instructions below to build the WAMR core on different platfor
Linux
-------------------------
First of all please install library dependencies of lib gcc.
Use installation commands below for Ubuntu Linux:
Use installation commands below for Ubuntu Linux:
``` Bash
sudo apt install lib32gcc-5-dev
sudo apt-get install g++-multilib
@ -78,17 +81,18 @@ ninja
Build WASM app
=========================
A popular method to build out WASM binary is to use ```emcc```.
Assuming you are using Linux, please install emcc from Emscripten EMSDK following the steps below:
A popular method to build a WASM binary is to use ```emcc```.
Assuming you are using Linux, you may install emcc from Emscripten EMSDK following the steps below:
```
git clone https://github.com/emscripten-core/emsdk.git
emsdk install latest
emsdk activate latest
```
add ```./emsdk_env.sh``` into the path to ease future use, or source it everytime.
The Emscripten website provides other installation methods beyond Linux.
todo: user should copy the app-libs folder into project and include and build.
(TODO) The user should copy the app-libs folder into project and include and build.
You can write a simple ```test.c``` as the first sample.
``` C
@ -143,12 +147,12 @@ ninja run
Embed WAMR into software production
=====================================
WAMR can be built into a standalone executable which takes WASM application file name as input, and then execute it. To use it in the embedded environment, you should embed WAMR into your own software product. WASM provides a set of API's for embedded code to load WASM module, instantiate the module and invoke the WASM function from a native call.
WAMR can be built into a standalone executable which takes the WASM application file name as input, and then executes it. To use it in the embedded environment you should embed WAMR into your own software product. WASM provides a set of API's for embedded code to load the WASM module, instantiate the module and invoke a WASM function from a native call.
<img src="./doc/pics/embed.PNG" width="60%" height="60%">
A typical WAMR API usage is as described below:
A typical WAMR API usage is shown below:
``` C
wasm_module_t module;
wasm_module_inst_t inst;
@ -171,12 +175,12 @@ A typical WAMR API usage is as described below:
```
WASM application library
WASM application library
========================
In general, there are 3 kinds of API's for programming the WASM application:
- Built-in API's: WAMR has already provided a minimal API set for developers.
- 3rd party API's: Programmer can download and include any 3rd party C source code, and add it into their own WASM app source tree.
- Platform native API's: WAMR provides a mechanism to export the native API to the WASM application.
In general, there are 3 classes of API's important for the WASM application:
- Built-in API's: WAMR provides a minimal API set for developers.
- 3rd party API's: Programmer can download and include any 3rd party C source code and add it into their own WASM app source tree.
- Platform native API's: WAMR provides a mechanism to export a native API to the WASM application.
Built-in application library
@ -184,8 +188,7 @@ Built-in application library
Built-in API's include Libc APIs, Base library and Extension library reference.
**Libc APIs**<br/>
This is the minimal Libc APIs like memory allocation and string copy etc.
The header file is ```lib/app-libs/libc/lib-base.h```. The API set is listed as below:
This is a minimal set of Libc APIs for memory allocation, string manipulation and printing. The header file is located at ```lib/app-libs/libc/lib-base.h```. The current supported API set is listed here:
``` C
void *malloc(size_t size);
void *calloc(size_t n, size_t size);
@ -206,8 +209,8 @@ char *strncpy(char *dest, const char *src, unsigned long n);
```
**Base library**<br/>
The basic support for communication, timers etc is already available. You can refer to the header file ```lib/app-libs/base/wasm-app.h``` which contains the definitions for request and response API's, event pub/sub APIs and timer APIs. Please note that these API's require the native implementations.
The API set is listed as below:
Basic support for communication, timers, etc is available. You can refer to the header file ```lib/app-libs/base/wasm-app.h``` which contains the definitions for request and response API's, event pub/sub APIs and timer APIs. Please note that these API's require the native implementations.
The API set is listed below:
``` C
typedef void(*request_handler_f)(request_t *) ;
typedef void(*response_handler_f)(response_t *, void *) ;
@ -245,11 +248,12 @@ bool sensor_close(sensor_t sensor);
The mechanism of exporting Native API to WASM application
=======================================================
The basic working flow for WASM application calling into the native API is described in the following diagram.
The basic working flow for WASM application calling into the native API is shown in the following diagram:
<img src="./doc/pics/extend_library.PNG" width="60%" height="60%">
WAMR provides the macro `EXPORT_WASM_API` to enable users to export native API to a WASM application. WAMR implemented a base API for the timer and messaging by using `EXPORT_WASM_API`. They can be a reference point for extending your own library.
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),
@ -263,12 +267,11 @@ static NativeSymbol extended_native_symbol_defs[] = {
};
```
![#f03c15](https://placehold.it/15/f03c15/000000?text=+) **Security attention:** The WebAssembly application is supposed to access its own memory space, the integrator should carefully design the native function to ensure that the memory is safe. The native API to be exported to the WASM application must follow these rules:
![#f03c15](https://placehold.it/15/f03c15/000000?text=+) **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
- Don't pass data to the structure pointer (do data serialization instead)
- Do the pointer address conversion in the native API
- Dont pass function pointer as callback
- 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.
@ -338,8 +341,7 @@ static NativeSymbol extended_native_symbol_defs[] =
```
Use extended library
------------------------
In the application source project, it will include the WAMR built-in APIs header file and platform extension header files.
This is assuming the board vendor extends the library which added an API called customized(). The WASM application would be like this:
In the application source project, it will include the WAMR built-in APIs 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
@ -353,11 +355,10 @@ int main(int argc, char **argv)
}
```
Coming soon...
Future Goals
========================
We are preparing the open source code for the application manager and related code samples like inter-application communication, application life cycle management, 2D graphic demo and more. This will get updated soon.
The application manager and related code samples like inter-application communication, application life cycle management, 2D graphic demo and more ...
Submit issues and request
=========================
[Click here to submit. Your feedback is always welcome!](https://github.com/intel/wasm-micro-runtime/issues/new)