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:
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user