Implement native function pointer check, addr conversion and register, update documents (#185)

Modified WASM runtime API:
- wasm_runtime_module_malloc()
- wasm_runtime_lookup_function()
Introduced runtime API
- wasm_runtime_register_natives()
This commit is contained in:
wenyongh
2020-03-04 20:12:38 +08:00
committed by GitHub
parent 2e36149e32
commit 0d3f304191
96 changed files with 2293 additions and 2317 deletions

View File

@ -32,6 +32,10 @@
#include "bi-inc/attr_container.h"
#include "module_wasm_app.h"
#include "wasm_export.h"
#include "sensor_native_api.h"
#include "connection_native_api.h"
#include "display_indev.h"
#define MAX 2048
#ifndef CONNECTION_UART
@ -389,7 +393,9 @@ static bool parse_args(int argc, char *argv[])
{ "uart", required_argument, NULL, 'u' },
{ "baudrate", required_argument, NULL, 'b' },
#endif
#if WASM_ENABLE_LIBC_WASI != 0
{ "wasi_root", required_argument, NULL, 'w' },
#endif
{ "help", required_argument, NULL, 'h' },
{ 0, 0, 0, 0 }
};
@ -421,12 +427,14 @@ static bool parse_args(int argc, char *argv[])
printf("uart baudrate: %s\n", optarg);
break;
#endif
#if WASM_ENABLE_LIBC_WASI != 0
case 'w':
if (!wasm_set_wasi_root_dir(optarg)) {
printf("Fail to set wasi root dir: %s\n", optarg);
return false;
}
break;
#endif
case 'h':
showUsage();
return false;
@ -439,10 +447,22 @@ static bool parse_args(int argc, char *argv[])
return true;
}
static NativeSymbol native_symbols[] = {
#include "runtime_sensor.inl"
#include "connection.inl"
EXPORT_WASM_API_WITH_SIG(display_input_read, "(*)i"),
EXPORT_WASM_API_WITH_SIG(display_flush, "(iiii*)"),
EXPORT_WASM_API_WITH_SIG(display_fill, "(iiii*)"),
EXPORT_WASM_API_WITH_SIG(display_vdb_write, "(*iii*i)"),
EXPORT_WASM_API_WITH_SIG(display_map, "(iiii*)"),
EXPORT_WASM_API_WITH_SIG(time_get_ms, "()i")
};
// Driver function
int iwasm_main(int argc, char *argv[])
{
korp_thread tid;
uint32 n_native_symbols;
if (!parse_args(argc, argv))
return -1;
@ -457,6 +477,13 @@ int iwasm_main(int argc, char *argv[])
goto fail1;
}
/* Register native functions */
n_native_symbols = sizeof(native_symbols) / sizeof(NativeSymbol);
if (!wasm_runtime_register_natives("env",
native_symbols, n_native_symbols)) {
goto fail1;
}
if (!init_connection_framework()) {
vm_thread_sys_destroy();
goto fail1;