2019-09-06 08:51:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
2019-11-11 23:45:21 +00:00
|
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-09-06 08:51:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2020-06-02 06:53:06 +00:00
|
|
|
|
2019-09-06 08:51:36 +00:00
|
|
|
#include "bh_platform.h"
|
2020-03-16 08:43:57 +00:00
|
|
|
#include "bh_read_file.h"
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
#include "wasm_export.h"
|
2019-09-06 08:51:36 +00:00
|
|
|
|
|
|
|
static int app_argc;
|
|
|
|
static char **app_argv;
|
|
|
|
|
2020-06-02 06:53:06 +00:00
|
|
|
#define MODULE_PATH ("--module-path=")
|
|
|
|
|
|
|
|
static int
|
|
|
|
print_help()
|
2019-09-06 08:51:36 +00:00
|
|
|
{
|
2020-03-16 08:43:57 +00:00
|
|
|
printf("Usage: iwasm [-options] wasm_file [args...]\n");
|
|
|
|
printf("options:\n");
|
2020-06-02 06:53:06 +00:00
|
|
|
printf(" -f|--function name Specify a function name of the module to run rather\n"
|
|
|
|
" than main\n");
|
2019-09-06 08:51:36 +00:00
|
|
|
#if WASM_ENABLE_LOG != 0
|
2020-06-02 06:53:06 +00:00
|
|
|
printf(" -v=n Set log verbose level (0 to 5, default is 2) larger\n"
|
|
|
|
" level with more log\n");
|
2019-09-06 08:51:36 +00:00
|
|
|
#endif
|
2020-03-16 08:43:57 +00:00
|
|
|
printf(" --stack-size=n Set maximum stack size in bytes, default is 16 KB\n");
|
|
|
|
printf(" --heap-size=n Set maximum heap size in bytes, default is 16 KB\n");
|
|
|
|
printf(" --repl Start a very simple REPL (read-eval-print-loop) mode\n"
|
|
|
|
" that runs commands in the form of `FUNC ARG...`\n");
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
#if WASM_ENABLE_LIBC_WASI != 0
|
2020-03-16 08:43:57 +00:00
|
|
|
printf(" --env=<env> Pass wasi environment variables with \"key=value\"\n");
|
|
|
|
printf(" to the program, for example:\n");
|
|
|
|
printf(" --env=\"key1=value1\" --env=\"key2=value2\"\n");
|
|
|
|
printf(" --dir=<dir> Grant wasi access to the given host directories\n");
|
|
|
|
printf(" to the program, for example:\n");
|
|
|
|
printf(" --dir=<dir1> --dir=<dir2>\n");
|
2019-11-20 13:16:36 +00:00
|
|
|
#endif
|
2020-06-02 06:53:06 +00:00
|
|
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
|
|
|
printf(" --module-path= Indicate a module search path. default is current\n"
|
|
|
|
" directory('./')\n");
|
2020-06-15 11:04:04 +00:00
|
|
|
#endif
|
|
|
|
#if WASM_ENABLE_LIB_PTHREAD != 0
|
|
|
|
printf(" --max-threads=n Set maximum thread number per cluster, default is 4\n");
|
2020-06-02 06:53:06 +00:00
|
|
|
#endif
|
2019-09-06 08:51:36 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-06-02 06:53:06 +00:00
|
|
|
static void *
|
2019-09-06 08:51:36 +00:00
|
|
|
app_instance_main(wasm_module_inst_t module_inst)
|
|
|
|
{
|
|
|
|
const char *exception;
|
|
|
|
|
|
|
|
wasm_application_execute_main(module_inst, app_argc, app_argv);
|
|
|
|
if ((exception = wasm_runtime_get_exception(module_inst)))
|
2020-03-16 08:43:57 +00:00
|
|
|
printf("%s\n", exception);
|
2019-09-06 08:51:36 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-06-02 06:53:06 +00:00
|
|
|
static void *
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
app_instance_func(wasm_module_inst_t module_inst, const char *func_name)
|
2019-09-06 08:51:36 +00:00
|
|
|
{
|
|
|
|
wasm_application_execute_func(module_inst, func_name, app_argc - 1,
|
|
|
|
app_argv + 1);
|
2019-12-18 03:53:43 +00:00
|
|
|
/* The result of wasm function or exception info was output inside
|
|
|
|
wasm_application_execute_func(), here we don't output them again. */
|
2019-09-06 08:51:36 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Split a space separated strings into an array of strings
|
|
|
|
* Returns NULL on failure
|
|
|
|
* Memory must be freed by caller
|
|
|
|
* Based on: http://stackoverflow.com/a/11198630/471795
|
|
|
|
*/
|
|
|
|
static char **
|
|
|
|
split_string(char *str, int *count)
|
|
|
|
{
|
|
|
|
char **res = NULL;
|
|
|
|
char *p;
|
|
|
|
int idx = 0;
|
|
|
|
|
|
|
|
/* split string and append tokens to 'res' */
|
|
|
|
do {
|
|
|
|
p = strtok(str, " ");
|
|
|
|
str = NULL;
|
2020-06-02 06:53:06 +00:00
|
|
|
res = (char **)realloc(res, sizeof(char *) * (uint32)(idx + 1));
|
2019-09-06 08:51:36 +00:00
|
|
|
if (res == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
res[idx++] = p;
|
|
|
|
} while (p);
|
|
|
|
|
2020-06-02 06:53:06 +00:00
|
|
|
/**
|
|
|
|
* since the function name,
|
|
|
|
* res[0] might be contains a '\' to indicate a space
|
|
|
|
* func\name -> func name
|
|
|
|
*/
|
|
|
|
p = strchr(res[0], '\\');
|
|
|
|
while (p) {
|
|
|
|
*p = ' ';
|
|
|
|
p = strchr(p, '\\');
|
|
|
|
}
|
|
|
|
|
2019-09-06 08:51:36 +00:00
|
|
|
if (count) {
|
|
|
|
*count = idx - 1;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-06-02 06:53:06 +00:00
|
|
|
static void *
|
2019-09-06 08:51:36 +00:00
|
|
|
app_instance_repl(wasm_module_inst_t module_inst)
|
|
|
|
{
|
|
|
|
char *cmd = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
ssize_t n;
|
|
|
|
|
2020-03-16 08:43:57 +00:00
|
|
|
while ((printf("webassembly> "), n = getline(&cmd, &len, stdin)) != -1) {
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
bh_assert(n > 0);
|
2019-09-06 08:51:36 +00:00
|
|
|
if (cmd[n - 1] == '\n') {
|
|
|
|
if (n == 1)
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
cmd[n - 1] = '\0';
|
|
|
|
}
|
2020-06-15 11:04:04 +00:00
|
|
|
if (!strcmp(cmd, "__exit__")) {
|
|
|
|
printf("exit repl mode\n");
|
|
|
|
break;
|
|
|
|
}
|
2019-09-06 08:51:36 +00:00
|
|
|
app_argv = split_string(cmd, &app_argc);
|
|
|
|
if (app_argv == NULL) {
|
|
|
|
LOG_ERROR("Wasm prepare param failed: split string failed.\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (app_argc != 0) {
|
|
|
|
wasm_application_execute_func(module_inst, app_argv[0],
|
|
|
|
app_argc - 1, app_argv + 1);
|
|
|
|
}
|
|
|
|
free(app_argv);
|
|
|
|
}
|
|
|
|
free(cmd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
#if WASM_ENABLE_LIBC_WASI != 0
|
2019-11-20 13:16:36 +00:00
|
|
|
static bool
|
|
|
|
validate_env_str(char *env)
|
|
|
|
{
|
|
|
|
char *p = env;
|
|
|
|
int key_len = 0;
|
|
|
|
|
|
|
|
while (*p != '\0' && *p != '=') {
|
|
|
|
key_len++;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*p != '=' || key_len == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2019-11-25 15:16:40 +00:00
|
|
|
#endif
|
2019-11-20 13:16:36 +00:00
|
|
|
|
2019-09-06 08:51:36 +00:00
|
|
|
#define USE_GLOBAL_HEAP_BUF 0
|
|
|
|
|
|
|
|
#if USE_GLOBAL_HEAP_BUF != 0
|
|
|
|
static char global_heap_buf[10 * 1024 * 1024] = { 0 };
|
|
|
|
#endif
|
|
|
|
|
2020-06-02 06:53:06 +00:00
|
|
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
|
|
|
static char *
|
|
|
|
handle_module_path(const char *module_path)
|
|
|
|
{
|
2020-09-20 00:20:45 +00:00
|
|
|
/* next character after = */
|
2020-06-02 06:53:06 +00:00
|
|
|
return (strchr(module_path, '=')) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *module_search_path = ".";
|
2020-09-20 00:20:45 +00:00
|
|
|
|
2020-06-02 06:53:06 +00:00
|
|
|
static bool
|
|
|
|
module_reader_callback(const char *module_name, uint8 **p_buffer,
|
|
|
|
uint32 *p_size)
|
|
|
|
{
|
|
|
|
const char *format = "%s/%s.wasm";
|
|
|
|
int sz = strlen(module_search_path) + strlen("/") + strlen(module_name) +
|
|
|
|
strlen(".wasm") + 1;
|
|
|
|
char *wasm_file_name = BH_MALLOC(sz);
|
|
|
|
if (!wasm_file_name) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(wasm_file_name, sz, format, module_search_path, module_name);
|
|
|
|
|
|
|
|
*p_buffer = (uint8_t *)bh_read_file_to_buffer(wasm_file_name, p_size);
|
|
|
|
|
|
|
|
wasm_runtime_free(wasm_file_name);
|
|
|
|
return *p_buffer != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
moudle_destroyer(uint8 *buffer, uint32 size)
|
|
|
|
{
|
|
|
|
if (!buffer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wasm_runtime_free(buffer);
|
|
|
|
buffer = NULL;
|
|
|
|
}
|
|
|
|
#endif /* WASM_ENABLE_MULTI_MODULE */
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
2019-09-06 08:51:36 +00:00
|
|
|
{
|
|
|
|
char *wasm_file = NULL;
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
const char *func_name = NULL;
|
2019-09-06 08:51:36 +00:00
|
|
|
uint8 *wasm_file_buf = NULL;
|
2019-11-20 13:16:36 +00:00
|
|
|
uint32 wasm_file_size;
|
2020-03-10 11:54:44 +00:00
|
|
|
uint32 stack_size = 16 * 1024, heap_size = 16 * 1024;
|
2019-09-06 08:51:36 +00:00
|
|
|
wasm_module_t wasm_module = NULL;
|
|
|
|
wasm_module_inst_t wasm_module_inst = NULL;
|
2020-03-07 14:20:38 +00:00
|
|
|
RuntimeInitArgs init_args;
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
char error_buf[128] = { 0 };
|
2019-09-06 08:51:36 +00:00
|
|
|
#if WASM_ENABLE_LOG != 0
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
int log_verbose_level = 2;
|
2019-09-06 08:51:36 +00:00
|
|
|
#endif
|
|
|
|
bool is_repl_mode = false;
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
#if WASM_ENABLE_LIBC_WASI != 0
|
2019-11-20 13:16:36 +00:00
|
|
|
const char *dir_list[8] = { NULL };
|
|
|
|
uint32 dir_list_size = 0;
|
|
|
|
const char *env_list[8] = { NULL };
|
|
|
|
uint32 env_list_size = 0;
|
|
|
|
#endif
|
2019-09-06 08:51:36 +00:00
|
|
|
|
|
|
|
/* Process options. */
|
|
|
|
for (argc--, argv++; argc > 0 && argv[0][0] == '-'; argc--, argv++) {
|
|
|
|
if (!strcmp(argv[0], "-f") || !strcmp(argv[0], "--function")) {
|
|
|
|
argc--, argv++;
|
|
|
|
if (argc < 2) {
|
|
|
|
print_help();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
func_name = argv[0];
|
|
|
|
}
|
|
|
|
#if WASM_ENABLE_LOG != 0
|
|
|
|
else if (!strncmp(argv[0], "-v=", 3)) {
|
|
|
|
log_verbose_level = atoi(argv[0] + 3);
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
if (log_verbose_level < 0 || log_verbose_level > 5)
|
2019-09-06 08:51:36 +00:00
|
|
|
return print_help();
|
|
|
|
}
|
|
|
|
#endif
|
2020-06-02 06:53:06 +00:00
|
|
|
else if (!strcmp(argv[0], "--repl")) {
|
2019-09-06 08:51:36 +00:00
|
|
|
is_repl_mode = true;
|
2020-06-02 06:53:06 +00:00
|
|
|
}
|
2020-03-10 11:54:44 +00:00
|
|
|
else if (!strncmp(argv[0], "--stack-size=", 13)) {
|
|
|
|
if (argv[0][13] == '\0')
|
|
|
|
return print_help();
|
|
|
|
stack_size = atoi(argv[0] + 13);
|
|
|
|
}
|
|
|
|
else if (!strncmp(argv[0], "--heap-size=", 12)) {
|
|
|
|
if (argv[0][12] == '\0')
|
|
|
|
return print_help();
|
|
|
|
heap_size = atoi(argv[0] + 12);
|
|
|
|
}
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
#if WASM_ENABLE_LIBC_WASI != 0
|
2019-11-20 13:16:36 +00:00
|
|
|
else if (!strncmp(argv[0], "--dir=", 6)) {
|
|
|
|
if (argv[0][6] == '\0')
|
|
|
|
return print_help();
|
2020-06-02 06:53:06 +00:00
|
|
|
if (dir_list_size >= sizeof(dir_list) / sizeof(char *)) {
|
2020-03-16 08:43:57 +00:00
|
|
|
printf("Only allow max dir number %d\n",
|
2020-06-02 06:53:06 +00:00
|
|
|
(int)(sizeof(dir_list) / sizeof(char *)));
|
2019-11-20 13:16:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
dir_list[dir_list_size++] = argv[0] + 6;
|
|
|
|
}
|
|
|
|
else if (!strncmp(argv[0], "--env=", 6)) {
|
|
|
|
char *tmp_env;
|
|
|
|
|
|
|
|
if (argv[0][6] == '\0')
|
|
|
|
return print_help();
|
2020-06-02 06:53:06 +00:00
|
|
|
if (env_list_size >= sizeof(env_list) / sizeof(char *)) {
|
2020-03-16 08:43:57 +00:00
|
|
|
printf("Only allow max env number %d\n",
|
2020-06-02 06:53:06 +00:00
|
|
|
(int)(sizeof(env_list) / sizeof(char *)));
|
2019-11-20 13:16:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
tmp_env = argv[0] + 6;
|
|
|
|
if (validate_env_str(tmp_env))
|
|
|
|
env_list[env_list_size++] = tmp_env;
|
|
|
|
else {
|
2020-06-02 06:53:06 +00:00
|
|
|
printf("Wasm parse env string failed: expect \"key=value\", "
|
|
|
|
"got \"%s\"\n",
|
2020-03-16 08:43:57 +00:00
|
|
|
tmp_env);
|
2019-11-20 13:16:36 +00:00
|
|
|
return print_help();
|
|
|
|
}
|
|
|
|
}
|
2020-06-02 06:53:06 +00:00
|
|
|
#endif /* WASM_ENABLE_LIBC_WASI */
|
|
|
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
|
|
|
else if (!strncmp(argv[0], MODULE_PATH, strlen(MODULE_PATH))) {
|
|
|
|
module_search_path = handle_module_path(argv[0]);
|
|
|
|
if (!strlen(module_search_path)) {
|
|
|
|
return print_help();
|
|
|
|
}
|
|
|
|
}
|
2020-06-15 11:04:04 +00:00
|
|
|
#endif
|
|
|
|
#if WASM_ENABLE_LIB_PTHREAD != 0
|
|
|
|
else if (!strncmp(argv[0], "--max-threads=", 14)) {
|
|
|
|
if (argv[0][14] == '\0')
|
|
|
|
return print_help();
|
|
|
|
wasm_runtime_set_max_thread_num(atoi(argv[0] + 14));
|
|
|
|
}
|
2019-11-20 13:16:36 +00:00
|
|
|
#endif
|
2019-09-06 08:51:36 +00:00
|
|
|
else
|
|
|
|
return print_help();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc == 0)
|
|
|
|
return print_help();
|
|
|
|
|
|
|
|
wasm_file = argv[0];
|
|
|
|
app_argc = argc;
|
|
|
|
app_argv = argv;
|
|
|
|
|
2020-03-07 14:20:38 +00:00
|
|
|
memset(&init_args, 0, sizeof(RuntimeInitArgs));
|
|
|
|
|
2019-09-06 08:51:36 +00:00
|
|
|
#if USE_GLOBAL_HEAP_BUF != 0
|
2020-03-07 14:20:38 +00:00
|
|
|
init_args.mem_alloc_type = Alloc_With_Pool;
|
2020-03-10 11:54:44 +00:00
|
|
|
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
|
|
|
|
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
|
2019-09-06 08:51:36 +00:00
|
|
|
#else
|
2020-03-07 14:20:38 +00:00
|
|
|
init_args.mem_alloc_type = Alloc_With_Allocator;
|
2020-03-10 11:54:44 +00:00
|
|
|
init_args.mem_alloc_option.allocator.malloc_func = malloc;
|
|
|
|
init_args.mem_alloc_option.allocator.realloc_func = realloc;
|
|
|
|
init_args.mem_alloc_option.allocator.free_func = free;
|
2019-09-06 08:51:36 +00:00
|
|
|
#endif
|
|
|
|
|
2020-03-10 11:54:44 +00:00
|
|
|
/* initialize runtime environment */
|
2020-03-07 14:20:38 +00:00
|
|
|
if (!wasm_runtime_full_init(&init_args)) {
|
2020-03-16 08:43:57 +00:00
|
|
|
printf("Init runtime environment failed.\n");
|
2020-03-07 14:20:38 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2019-09-06 08:51:36 +00:00
|
|
|
|
2020-06-02 06:53:06 +00:00
|
|
|
#if WASM_ENABLE_LOG != 0
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
bh_log_set_verbose_level(log_verbose_level);
|
2020-06-02 06:53:06 +00:00
|
|
|
#endif
|
2019-09-06 08:51:36 +00:00
|
|
|
|
|
|
|
/* load WASM byte buffer from WASM bin file */
|
2020-06-02 06:53:06 +00:00
|
|
|
if (!(wasm_file_buf =
|
|
|
|
(uint8 *)bh_read_file_to_buffer(wasm_file, &wasm_file_size)))
|
2020-03-07 14:20:38 +00:00
|
|
|
goto fail1;
|
2019-09-06 08:51:36 +00:00
|
|
|
|
2020-06-02 06:53:06 +00:00
|
|
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
|
|
|
wasm_runtime_set_module_reader(module_reader_callback, moudle_destroyer);
|
|
|
|
#endif
|
|
|
|
|
2019-09-06 08:51:36 +00:00
|
|
|
/* load WASM module */
|
|
|
|
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
|
|
|
|
error_buf, sizeof(error_buf)))) {
|
2020-03-16 08:43:57 +00:00
|
|
|
printf("%s\n", error_buf);
|
2020-03-07 14:20:38 +00:00
|
|
|
goto fail2;
|
2019-09-06 08:51:36 +00:00
|
|
|
}
|
|
|
|
|
Enable AoT and wamr-sdk, and change arguments of call wasm API (#157)
* Implement memory profiler, optimize memory usage, modify code indent
* Implement memory.grow and limit heap space base offset to 1G; modify iwasm build type to Release and 64 bit by default
* Add a new extension library: connection
* Fix bug of reading magic number and version in big endian platform
* Re-org platform APIs: move most platform APIs from iwasm to shared-lib
* Enhance wasm loader to fix some security issues
* Fix issue about illegal load of EXC_RETURN into PC on stm32 board
* Updates that let a restricted version of the interpreter run in SGX
* Enable native/app address validation and conversion for wasm app
* Remove wasm_application_exectue_* APIs from wasm_export.h which makes confused
* Refine binary size and fix several minor issues
Optimize interpreter LOAD/STORE opcodes to decrease the binary size
Fix issues when using iwasm library: _bh_log undefined, bh_memory.h not found
Remove unused _stdin/_stdout/_stderr global variables resolve in libc wrapper
Add macros of global heap size, stack size, heap size for Zephyr main.c
Clear compile warning of wasm_application.c
* Add more strict security checks for libc wrapper API's
* Use one libc wrapper copy for sgx and other platforms; remove bh_printf macro for other platform header files
* Enhance security of libc strcpy/sprintf wrapper function
* Fix issue of call native for x86_64/arm/mips, add module inst parameter for native wrapper functions
* Remove get_module_inst() and fix issue of call native
* Refine wgl lib: remove module_inst parameter from widget functions; move function index check to runtime instantiate
* Refine interpreter call native process, refine memory boudary check
* Fix issues of invokeNative function of arm/mips/general version
* Add a switch to build simple sample without gui support
* Add BUILD_TARGET setting in makefile to replace cpu compiler flags in source code
* Re-org shared lib header files, remove unused info; fix compile issues of vxworks
* Add build target general
* Remove unused files
* Update license header
* test push
* Restore file
* Sync up with internal/feature
* Sync up with internal/feature
* Rename build_wamr_app to build_wasm_app
* Fix small issues of README
* Enhance malformed wasm file checking
Fix issue of print hex int and implement utf8 string check
Fix wasi file read/write right issue
Fix minor issue of build wasm app doc
* Sync up with internal/feature
* Sync up with internal/feature: fix interpreter arm issue, fix read leb issue
* Sync up with internal/feature
* Fix bug of config.h and rename wasi config.h to ssp_config.h
* Sync up with internal/feature
* Import wamr aot
* update document
* update document
* Update document, disable WASI in 32bit
* update document
* remove files
* update document
* Update document
* update document
* update document
* update samples
* Sync up with internal repo
2020-01-21 05:26:14 +00:00
|
|
|
#if WASM_ENABLE_LIBC_WASI != 0
|
2020-06-02 06:53:06 +00:00
|
|
|
wasm_runtime_set_wasi_args(wasm_module, dir_list, dir_list_size, NULL, 0,
|
|
|
|
env_list, env_list_size, argv, argc);
|
2019-11-20 13:16:36 +00:00
|
|
|
#endif
|
|
|
|
|
2019-09-06 08:51:36 +00:00
|
|
|
/* instantiate the module */
|
2020-06-02 06:53:06 +00:00
|
|
|
if (!(wasm_module_inst =
|
|
|
|
wasm_runtime_instantiate(wasm_module, stack_size, heap_size,
|
|
|
|
error_buf, sizeof(error_buf)))) {
|
2020-03-16 08:43:57 +00:00
|
|
|
printf("%s\n", error_buf);
|
2020-03-07 14:20:38 +00:00
|
|
|
goto fail3;
|
2019-09-06 08:51:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_repl_mode)
|
|
|
|
app_instance_repl(wasm_module_inst);
|
|
|
|
else if (func_name)
|
|
|
|
app_instance_func(wasm_module_inst, func_name);
|
|
|
|
else
|
|
|
|
app_instance_main(wasm_module_inst);
|
|
|
|
|
|
|
|
/* destroy the module instance */
|
|
|
|
wasm_runtime_deinstantiate(wasm_module_inst);
|
|
|
|
|
2020-03-07 14:20:38 +00:00
|
|
|
fail3:
|
2019-09-06 08:51:36 +00:00
|
|
|
/* unload the module */
|
|
|
|
wasm_runtime_unload(wasm_module);
|
|
|
|
|
2020-03-07 14:20:38 +00:00
|
|
|
fail2:
|
2019-09-06 08:51:36 +00:00
|
|
|
/* free the file buffer */
|
2020-03-10 11:54:44 +00:00
|
|
|
wasm_runtime_free(wasm_file_buf);
|
2019-09-06 08:51:36 +00:00
|
|
|
|
|
|
|
fail1:
|
2020-03-07 14:20:38 +00:00
|
|
|
/* destroy runtime environment */
|
2020-03-10 11:54:44 +00:00
|
|
|
wasm_runtime_destroy();
|
2019-09-06 08:51:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|