re-org platform APIs, simplify porting process (#201)

Co-authored-by: Xu Jun <jun1.xu@intel.com>
This commit is contained in:
Xu Jun
2020-03-16 16:43:57 +08:00
committed by GitHub
parent ef5ceffe71
commit f1a0e75ab7
177 changed files with 2954 additions and 7904 deletions

View File

@ -2,6 +2,7 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
NAME := iwasm
CORE_ROOT := wamr/core
IWASM_ROOT := wamr/core/iwasm
SHARED_ROOT := wamr/core/shared
@ -59,10 +60,13 @@ endif
GLOBAL_DEFINES += WASM_ENABLE_LIBC_BUILTIN=1
GLOBAL_INCLUDES += ${IWASM_ROOT}/include \
GLOBAL_INCLUDES += ${CORE_ROOT} \
${IWASM_ROOT}/include \
${IWASM_ROOT}/common \
${SHARED_ROOT}/include \
${SHARED_ROOT}/platform/include \
${SHARED_ROOT}/utils \
${SHARED_ROOT}/mem-alloc \
${SHARED_ROOT}/platform/alios
ifeq (${WAMR_BUILD_INTERP}, 1)
@ -73,17 +77,16 @@ ifeq (${WAMR_BUILD_AOT}, 1)
GLOBAL_INCLUDES += ${IWASM_ROOT}/aot
endif
$(NAME)_SOURCES := ${SHARED_ROOT}/platform/alios/bh_assert.c \
${SHARED_ROOT}/platform/alios/bh_math.c \
${SHARED_ROOT}/platform/alios/bh_platform.c \
${SHARED_ROOT}/platform/alios/bh_platform_log.c \
${SHARED_ROOT}/platform/alios/bh_thread.c \
${SHARED_ROOT}/platform/alios/bh_time.c \
$(NAME)_SOURCES := ${SHARED_ROOT}/platform/alios/alios_platform.c \
${SHARED_ROOT}/platform/alios/alios_thread.c \
${SHARED_ROOT}/platform/alios/alios_time.c \
${SHARED_ROOT}/platform/common/math/math.c \
${SHARED_ROOT}/mem-alloc/mem_alloc.c \
${SHARED_ROOT}/mem-alloc/ems/ems_kfc.c \
${SHARED_ROOT}/mem-alloc/ems/ems_alloc.c \
${SHARED_ROOT}/mem-alloc/ems/ems_hmu.c \
${SHARED_ROOT}/utils/bh_definition.c \
${SHARED_ROOT}/utils/bh_assert.c \
${SHARED_ROOT}/utils/bh_common.c \
${SHARED_ROOT}/utils/bh_hashmap.c \
${SHARED_ROOT}/utils/bh_list.c \
${SHARED_ROOT}/utils/bh_log.c \

View File

@ -7,7 +7,6 @@
#include <string.h>
#include "bh_platform.h"
#include "bh_log.h"
#include "bh_platform_log.h"
#include "wasm_export.h"
#include "test_wasm.h"
@ -35,7 +34,7 @@ app_instance_main(wasm_module_inst_t module_inst)
wasm_application_execute_main(module_inst, app_argc, app_argv);
if ((exception = wasm_runtime_get_exception(module_inst)))
bh_printf("%s\n", exception);
printf("%s\n", exception);
return NULL;
}
@ -63,7 +62,7 @@ void iwasm_main(void *arg1)
/* initialize runtime environment */
if (!wasm_runtime_full_init(&init_args)) {
bh_printf("Init runtime environment failed.\n");
printf("Init runtime environment failed.\n");
return;
}
@ -78,7 +77,7 @@ void iwasm_main(void *arg1)
/* load WASM module */
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
error_buf, sizeof(error_buf)))) {
bh_printf("%s\n", error_buf);
printf("%s\n", error_buf);
goto fail1;
}
@ -88,7 +87,7 @@ void iwasm_main(void *arg1)
8 * 1024,
error_buf,
sizeof(error_buf)))) {
bh_printf("%s\n", error_buf);
printf("%s\n", error_buf);
goto fail2;
}

View File

@ -101,7 +101,5 @@ set (distribution_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build/distribution)
set_target_properties (iwasm PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${distribution_DIR}/wasm/lib")
add_custom_command (TARGET iwasm POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_directory "${WAMR_ROOT_DIR}/core/shared/include" "${distribution_DIR}/wasm/include/"
COMMAND "${CMAKE_COMMAND}" -E copy_directory "${WAMR_ROOT_DIR}/core/shared/platform/include" "${distribution_DIR}/wasm/include/platform/"
COMMAND "${CMAKE_COMMAND}" -E copy "${WAMR_ROOT_DIR}/core/shared/platform/android/bh_platform.h" "${distribution_DIR}/wasm/include/platform/"
COMMAND "${CMAKE_COMMAND}" -E copy_directory "${WAMR_ROOT_DIR}/core/iwasm/include" "${distribution_DIR}/wasm/include/"
COMMENT "Copying iwasm to output directory")

View File

@ -3,9 +3,7 @@
#include <jni.h>
#include <cinttypes>
#include <android/log.h>
#include <bh_log.h>
#include <string>
#include <bh_platform.h>
#include <wasm_export.h>
#define LOGI(...) \
@ -23,54 +21,54 @@ app_instance_main(wasm_module_inst_t module_inst) {
// WARNING! CAN NOT BE READ ONLY!!!
static unsigned char wasm_test_file[] = { 0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00,
0x00, 0x00, 0x0D, 0x06, 0x64, 0x79, 0x6C, 0x69, 0x6E, 0x6B, 0xC0, 0x80,
0x04, 0x04, 0x00, 0x00, 0x01, 0x13, 0x04, 0x60, 0x01, 0x7F, 0x00, 0x60,
0x01, 0x7F, 0x01, 0x7F, 0x60, 0x02, 0x7F, 0x7F, 0x01, 0x7F, 0x60, 0x00,
0x00, 0x02, 0x58, 0x06, 0x03, 0x65, 0x6E, 0x76, 0x05, 0x5F, 0x66, 0x72,
0x65, 0x65, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x07, 0x5F, 0x6D, 0x61,
0x6C, 0x6C, 0x6F, 0x63, 0x00, 0x01, 0x03, 0x65, 0x6E, 0x76, 0x07, 0x5F,
0x70, 0x72, 0x69, 0x6E, 0x74, 0x66, 0x00, 0x02, 0x03, 0x65, 0x6E, 0x76,
0x05, 0x5F, 0x70, 0x75, 0x74, 0x73, 0x00, 0x01, 0x03, 0x65, 0x6E, 0x76,
0x0D, 0x5F, 0x5F, 0x6D, 0x65, 0x6D, 0x6F, 0x72, 0x79, 0x5F, 0x62, 0x61,
0x73, 0x65, 0x03, 0x7F, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x6D, 0x65,
0x6D, 0x6F, 0x72, 0x79, 0x02, 0x00, 0x01, 0x03, 0x04, 0x03, 0x02, 0x03,
0x03, 0x06, 0x10, 0x03, 0x7F, 0x01, 0x41, 0x00, 0x0B, 0x7F, 0x01, 0x41,
0x00, 0x0B, 0x7F, 0x00, 0x41, 0x1B, 0x0B, 0x07, 0x33, 0x04, 0x12, 0x5F,
0x5F, 0x70, 0x6F, 0x73, 0x74, 0x5F, 0x69, 0x6E, 0x73, 0x74, 0x61, 0x6E,
0x74, 0x69, 0x61, 0x74, 0x65, 0x00, 0x06, 0x05, 0x5F, 0x6D, 0x61, 0x69,
0x6E, 0x00, 0x04, 0x0B, 0x72, 0x75, 0x6E, 0x50, 0x6F, 0x73, 0x74, 0x53,
0x65, 0x74, 0x73, 0x00, 0x05, 0x04, 0x5F, 0x73, 0x74, 0x72, 0x03, 0x03,
0x0A, 0xBA, 0x01, 0x03, 0x9E, 0x01, 0x01, 0x01, 0x7F, 0x23, 0x01, 0x21,
0x00, 0x23, 0x01, 0x41, 0x10, 0x6A, 0x24, 0x01, 0x20, 0x00, 0x41, 0x08,
0x6A, 0x21, 0x02, 0x23, 0x00, 0x41, 0x1B, 0x6A, 0x10, 0x03, 0x1A, 0x41,
0x80, 0x08, 0x10, 0x01, 0x21, 0x01, 0x20, 0x01, 0x04, 0x7F, 0x20, 0x00,
0x20, 0x01, 0x36, 0x02, 0x00, 0x23, 0x00, 0x20, 0x00, 0x10, 0x02, 0x1A,
0x20, 0x01, 0x23, 0x00, 0x2C, 0x00, 0x0D, 0x3A, 0x00, 0x00, 0x20, 0x01,
0x23, 0x00, 0x2C, 0x00, 0x0E, 0x3A, 0x00, 0x01, 0x20, 0x01, 0x23, 0x00,
0x2C, 0x00, 0x0F, 0x3A, 0x00, 0x02, 0x20, 0x01, 0x23, 0x00, 0x2C, 0x00,
0x10, 0x3A, 0x00, 0x03, 0x20, 0x01, 0x23, 0x00, 0x2C, 0x00, 0x11, 0x3A,
0x00, 0x04, 0x20, 0x01, 0x23, 0x00, 0x2C, 0x00, 0x12, 0x3A, 0x00, 0x05,
0x20, 0x02, 0x20, 0x01, 0x36, 0x02, 0x00, 0x23, 0x00, 0x41, 0x13, 0x6A,
0x20, 0x02, 0x10, 0x02, 0x1A, 0x20, 0x01, 0x10, 0x00, 0x20, 0x00, 0x24,
0x01, 0x41, 0x00, 0x05, 0x23, 0x00, 0x41, 0x28, 0x6A, 0x10, 0x03, 0x1A,
0x20, 0x00, 0x24, 0x01, 0x41, 0x7F, 0x0B, 0x0B, 0x03, 0x00, 0x01, 0x0B,
0x14, 0x00, 0x23, 0x00, 0x41, 0x40, 0x6B, 0x24, 0x01, 0x23, 0x01, 0x41,
0x80, 0x80, 0x04, 0x6A, 0x24, 0x02, 0x10, 0x05, 0x0B, 0x0B, 0x3F, 0x01,
0x00, 0x23, 0x00, 0x0B, 0x39, 0x62, 0x75, 0x66, 0x20, 0x70, 0x74, 0x72,
0x3A, 0x20, 0x25, 0x70, 0x0A, 0x00, 0x31, 0x32, 0x33, 0x34, 0x0A, 0x00,
0x62, 0x75, 0x66, 0x3A, 0x20, 0x25, 0x73, 0x00, 0x48, 0x65, 0x6C, 0x6C,
0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21, 0x00, 0x6D, 0x61, 0x6C,
0x6C, 0x6F, 0x63, 0x20, 0x62, 0x75, 0x66, 0x20, 0x66, 0x61, 0x69, 0x6C,
0x65, 0x64, 0x00, 0x50, 0x04, 0x6E, 0x61, 0x6D, 0x65, 0x01, 0x49, 0x07,
0x00, 0x05, 0x5F, 0x66, 0x72, 0x65, 0x65, 0x01, 0x07, 0x5F, 0x6D, 0x61,
0x6C, 0x6C, 0x6F, 0x63, 0x02, 0x07, 0x5F, 0x70, 0x72, 0x69, 0x6E, 0x74,
0x66, 0x03, 0x05, 0x5F, 0x70, 0x75, 0x74, 0x73, 0x04, 0x05, 0x5F, 0x6D,
0x61, 0x69, 0x6E, 0x05, 0x0B, 0x72, 0x75, 0x6E, 0x50, 0x6F, 0x73, 0x74,
0x53, 0x65, 0x74, 0x73, 0x06, 0x12, 0x5F, 0x5F, 0x70, 0x6F, 0x73, 0x74,
0x5F, 0x69, 0x6E, 0x73, 0x74, 0x61, 0x6E, 0x74, 0x69, 0x61, 0x74, 0x65,
0x00, 0x20, 0x10, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x4D, 0x61, 0x70,
0x70, 0x69, 0x6E, 0x67, 0x55, 0x52, 0x4C, 0x0E, 0x61, 0x2E, 0x6F, 0x75,
0x74, 0x2E, 0x77, 0x61, 0x73, 0x6D, 0x2E, 0x6D, 0x61, 0x70 };
0x00, 0x00, 0x0D, 0x06, 0x64, 0x79, 0x6C, 0x69, 0x6E, 0x6B, 0xC0, 0x80,
0x04, 0x04, 0x00, 0x00, 0x01, 0x13, 0x04, 0x60, 0x01, 0x7F, 0x00, 0x60,
0x01, 0x7F, 0x01, 0x7F, 0x60, 0x02, 0x7F, 0x7F, 0x01, 0x7F, 0x60, 0x00,
0x00, 0x02, 0x58, 0x06, 0x03, 0x65, 0x6E, 0x76, 0x05, 0x5F, 0x66, 0x72,
0x65, 0x65, 0x00, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x07, 0x5F, 0x6D, 0x61,
0x6C, 0x6C, 0x6F, 0x63, 0x00, 0x01, 0x03, 0x65, 0x6E, 0x76, 0x07, 0x5F,
0x70, 0x72, 0x69, 0x6E, 0x74, 0x66, 0x00, 0x02, 0x03, 0x65, 0x6E, 0x76,
0x05, 0x5F, 0x70, 0x75, 0x74, 0x73, 0x00, 0x01, 0x03, 0x65, 0x6E, 0x76,
0x0D, 0x5F, 0x5F, 0x6D, 0x65, 0x6D, 0x6F, 0x72, 0x79, 0x5F, 0x62, 0x61,
0x73, 0x65, 0x03, 0x7F, 0x00, 0x03, 0x65, 0x6E, 0x76, 0x06, 0x6D, 0x65,
0x6D, 0x6F, 0x72, 0x79, 0x02, 0x00, 0x01, 0x03, 0x04, 0x03, 0x02, 0x03,
0x03, 0x06, 0x10, 0x03, 0x7F, 0x01, 0x41, 0x00, 0x0B, 0x7F, 0x01, 0x41,
0x00, 0x0B, 0x7F, 0x00, 0x41, 0x1B, 0x0B, 0x07, 0x33, 0x04, 0x12, 0x5F,
0x5F, 0x70, 0x6F, 0x73, 0x74, 0x5F, 0x69, 0x6E, 0x73, 0x74, 0x61, 0x6E,
0x74, 0x69, 0x61, 0x74, 0x65, 0x00, 0x06, 0x05, 0x5F, 0x6D, 0x61, 0x69,
0x6E, 0x00, 0x04, 0x0B, 0x72, 0x75, 0x6E, 0x50, 0x6F, 0x73, 0x74, 0x53,
0x65, 0x74, 0x73, 0x00, 0x05, 0x04, 0x5F, 0x73, 0x74, 0x72, 0x03, 0x03,
0x0A, 0xBA, 0x01, 0x03, 0x9E, 0x01, 0x01, 0x01, 0x7F, 0x23, 0x01, 0x21,
0x00, 0x23, 0x01, 0x41, 0x10, 0x6A, 0x24, 0x01, 0x20, 0x00, 0x41, 0x08,
0x6A, 0x21, 0x02, 0x23, 0x00, 0x41, 0x1B, 0x6A, 0x10, 0x03, 0x1A, 0x41,
0x80, 0x08, 0x10, 0x01, 0x21, 0x01, 0x20, 0x01, 0x04, 0x7F, 0x20, 0x00,
0x20, 0x01, 0x36, 0x02, 0x00, 0x23, 0x00, 0x20, 0x00, 0x10, 0x02, 0x1A,
0x20, 0x01, 0x23, 0x00, 0x2C, 0x00, 0x0D, 0x3A, 0x00, 0x00, 0x20, 0x01,
0x23, 0x00, 0x2C, 0x00, 0x0E, 0x3A, 0x00, 0x01, 0x20, 0x01, 0x23, 0x00,
0x2C, 0x00, 0x0F, 0x3A, 0x00, 0x02, 0x20, 0x01, 0x23, 0x00, 0x2C, 0x00,
0x10, 0x3A, 0x00, 0x03, 0x20, 0x01, 0x23, 0x00, 0x2C, 0x00, 0x11, 0x3A,
0x00, 0x04, 0x20, 0x01, 0x23, 0x00, 0x2C, 0x00, 0x12, 0x3A, 0x00, 0x05,
0x20, 0x02, 0x20, 0x01, 0x36, 0x02, 0x00, 0x23, 0x00, 0x41, 0x13, 0x6A,
0x20, 0x02, 0x10, 0x02, 0x1A, 0x20, 0x01, 0x10, 0x00, 0x20, 0x00, 0x24,
0x01, 0x41, 0x00, 0x05, 0x23, 0x00, 0x41, 0x28, 0x6A, 0x10, 0x03, 0x1A,
0x20, 0x00, 0x24, 0x01, 0x41, 0x7F, 0x0B, 0x0B, 0x03, 0x00, 0x01, 0x0B,
0x14, 0x00, 0x23, 0x00, 0x41, 0x40, 0x6B, 0x24, 0x01, 0x23, 0x01, 0x41,
0x80, 0x80, 0x04, 0x6A, 0x24, 0x02, 0x10, 0x05, 0x0B, 0x0B, 0x3F, 0x01,
0x00, 0x23, 0x00, 0x0B, 0x39, 0x62, 0x75, 0x66, 0x20, 0x70, 0x74, 0x72,
0x3A, 0x20, 0x25, 0x70, 0x0A, 0x00, 0x31, 0x32, 0x33, 0x34, 0x0A, 0x00,
0x62, 0x75, 0x66, 0x3A, 0x20, 0x25, 0x73, 0x00, 0x48, 0x65, 0x6C, 0x6C,
0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21, 0x00, 0x6D, 0x61, 0x6C,
0x6C, 0x6F, 0x63, 0x20, 0x62, 0x75, 0x66, 0x20, 0x66, 0x61, 0x69, 0x6C,
0x65, 0x64, 0x00, 0x50, 0x04, 0x6E, 0x61, 0x6D, 0x65, 0x01, 0x49, 0x07,
0x00, 0x05, 0x5F, 0x66, 0x72, 0x65, 0x65, 0x01, 0x07, 0x5F, 0x6D, 0x61,
0x6C, 0x6C, 0x6F, 0x63, 0x02, 0x07, 0x5F, 0x70, 0x72, 0x69, 0x6E, 0x74,
0x66, 0x03, 0x05, 0x5F, 0x70, 0x75, 0x74, 0x73, 0x04, 0x05, 0x5F, 0x6D,
0x61, 0x69, 0x6E, 0x05, 0x0B, 0x72, 0x75, 0x6E, 0x50, 0x6F, 0x73, 0x74,
0x53, 0x65, 0x74, 0x73, 0x06, 0x12, 0x5F, 0x5F, 0x70, 0x6F, 0x73, 0x74,
0x5F, 0x69, 0x6E, 0x73, 0x74, 0x61, 0x6E, 0x74, 0x69, 0x61, 0x74, 0x65,
0x00, 0x20, 0x10, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x4D, 0x61, 0x70,
0x70, 0x69, 0x6E, 0x67, 0x55, 0x52, 0x4C, 0x0E, 0x61, 0x2E, 0x6F, 0x75,
0x74, 0x2E, 0x77, 0x61, 0x73, 0x6D, 0x2E, 0x6D, 0x61, 0x70 };
extern "C" JNIEXPORT void JNICALL
@ -96,10 +94,6 @@ Java_com_intel_wasm_api_Runtime_run(JNIEnv *env, jclass thiz) {
return;
}
// set log level to INFO
LOGI("set log level to INFO");
bh_log_set_verbose_level(3);
/* load WASM byte buffer from a preinstall WASM bin file */
LOGI("use an internal test file, gona to output Hello World in logcat\n");
wasm_file_buf = (uint8_t*) wasm_test_file;

View File

@ -62,7 +62,9 @@ set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
add_executable (iwasm main.c)
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
add_executable (iwasm main.c ${UNCOMMON_SHARED_SOURCE})
install (TARGETS iwasm DESTINATION bin)

View File

@ -11,6 +11,7 @@
#include "bh_platform.h"
#include "bh_assert.h"
#include "bh_log.h"
#include "bh_read_file.h"
#include "wasm_export.h"
static int app_argc;
@ -18,25 +19,25 @@ static char **app_argv;
static int print_help()
{
bh_printf("Usage: iwasm [-options] wasm_file [args...]\n");
bh_printf("options:\n");
bh_printf(" -f|--function name Specify function name to run in module\n"
" rather than main\n");
printf("Usage: iwasm [-options] wasm_file [args...]\n");
printf("options:\n");
printf(" -f|--function name Specify function name to run in module\n"
" rather than main\n");
#if WASM_ENABLE_LOG != 0
bh_printf(" -v=n Set log verbose level (0 to 5, default is 2),\n"
" larger level with more log\n");
printf(" -v=n Set log verbose level (0 to 5, default is 2),\n"
" larger level with more log\n");
#endif
bh_printf(" --stack-size=n Set maximum stack size in bytes, default is 16 KB\n");
bh_printf(" --heap-size=n Set maximum heap size in bytes, default is 16 KB\n");
bh_printf(" --repl Start a very simple REPL (read-eval-print-loop) mode\n"
" that runs commands in the form of `FUNC ARG...`\n");
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");
#if WASM_ENABLE_LIBC_WASI != 0
bh_printf(" --env=<env> Pass wasi environment variables with \"key=value\"\n");
bh_printf(" to the program, for example:\n");
bh_printf(" --env=\"key1=value1\" --env=\"key2=value2\"\n");
bh_printf(" --dir=<dir> Grant wasi access to the given host directories\n");
bh_printf(" to the program, for example:\n");
bh_printf(" --dir=<dir1> --dir=<dir2>\n");
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");
#endif
return 1;
@ -49,7 +50,7 @@ app_instance_main(wasm_module_inst_t module_inst)
wasm_application_execute_main(module_inst, app_argc, app_argv);
if ((exception = wasm_runtime_get_exception(module_inst)))
bh_printf("%s\n", exception);
printf("%s\n", exception);
return NULL;
}
@ -100,7 +101,7 @@ app_instance_repl(wasm_module_inst_t module_inst)
size_t len = 0;
ssize_t n;
while ((bh_printf("webassembly> "), n = getline(&cmd, &len, stdin)) != -1) {
while ((printf("webassembly> "), n = getline(&cmd, &len, stdin)) != -1) {
bh_assert(n > 0);
if (cmd[n - 1] == '\n') {
if (n == 1)
@ -204,8 +205,8 @@ int main(int argc, char *argv[])
if (argv[0][6] == '\0')
return print_help();
if (dir_list_size >= sizeof(dir_list) / sizeof(char*)) {
bh_printf("Only allow max dir number %d\n",
(int)(sizeof(dir_list) / sizeof(char*)));
printf("Only allow max dir number %d\n",
(int)(sizeof(dir_list) / sizeof(char*)));
return -1;
}
dir_list[dir_list_size++] = argv[0] + 6;
@ -216,16 +217,16 @@ int main(int argc, char *argv[])
if (argv[0][6] == '\0')
return print_help();
if (env_list_size >= sizeof(env_list) / sizeof(char*)) {
bh_printf("Only allow max env number %d\n",
(int)(sizeof(env_list) / sizeof(char*)));
printf("Only allow max env number %d\n",
(int)(sizeof(env_list) / sizeof(char*)));
return -1;
}
tmp_env = argv[0] + 6;
if (validate_env_str(tmp_env))
env_list[env_list_size++] = tmp_env;
else {
bh_printf("Wasm parse env string failed: expect \"key=value\", got \"%s\"\n",
tmp_env);
printf("Wasm parse env string failed: expect \"key=value\", got \"%s\"\n",
tmp_env);
return print_help();
}
}
@ -256,7 +257,7 @@ int main(int argc, char *argv[])
/* initialize runtime environment */
if (!wasm_runtime_full_init(&init_args)) {
bh_printf("Init runtime environment failed.\n");
printf("Init runtime environment failed.\n");
return -1;
}
@ -270,7 +271,7 @@ int main(int argc, char *argv[])
/* load WASM module */
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
error_buf, sizeof(error_buf)))) {
bh_printf("%s\n", error_buf);
printf("%s\n", error_buf);
goto fail2;
}
@ -288,7 +289,7 @@ int main(int argc, char *argv[])
heap_size,
error_buf,
sizeof(error_buf)))) {
bh_printf("%s\n", error_buf);
printf("%s\n", error_buf);
goto fail3;
}

View File

@ -29,10 +29,8 @@ app_instance_main(wasm_module_inst_t module_inst)
extern "C" {
int bh_printf(const char *message, ...);
typedef void (*bh_print_function_t)(const char* message);
extern void bh_set_print_function(bh_print_function_t pf);
typedef void (*os_print_function_t)(const char* message);
extern void os_set_print_function(os_print_function_t pf);
void enclave_print(const char *message)
{
@ -43,7 +41,7 @@ void enclave_print(const char *message)
void ecall_iwasm_main()
{
bh_set_print_function(enclave_print);
os_set_print_function(enclave_print);
uint8_t *wasm_file_buf = NULL;
int wasm_file_size;

View File

@ -81,7 +81,9 @@ endif ()
#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong --param ssp-buffer-size=4")
#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack,-z,relro,-z,now")
add_executable (iwasm main.c)
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
add_executable (iwasm main.c ${UNCOMMON_SHARED_SOURCE})
install (TARGETS iwasm DESTINATION bin)

View File

@ -11,6 +11,7 @@
#include "bh_platform.h"
#include "bh_assert.h"
#include "bh_log.h"
#include "bh_read_file.h"
#include "wasm_export.h"
static int app_argc;
@ -18,25 +19,25 @@ static char **app_argv;
static int print_help()
{
bh_printf("Usage: iwasm [-options] wasm_file [args...]\n");
bh_printf("options:\n");
bh_printf(" -f|--function name Specify function name to run in module\n"
" rather than main\n");
printf("Usage: iwasm [-options] wasm_file [args...]\n");
printf("options:\n");
printf(" -f|--function name Specify function name to run in module\n"
" rather than main\n");
#if WASM_ENABLE_LOG != 0
bh_printf(" -v=n Set log verbose level (0 to 5, default is 2),\n"
" larger level with more log\n");
printf(" -v=n Set log verbose level (0 to 5, default is 2),\n"
" larger level with more log\n");
#endif
bh_printf(" --stack-size=n Set maximum stack size in bytes, default is 16 KB\n");
bh_printf(" --heap-size=n Set maximum heap size in bytes, default is 16 KB\n");
bh_printf(" --repl Start a very simple REPL (read-eval-print-loop) mode\n"
" that runs commands in the form of `FUNC ARG...`\n");
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");
#if WASM_ENABLE_LIBC_WASI != 0
bh_printf(" --env=<env> Pass wasi environment variables with \"key=value\"\n");
bh_printf(" to the program, for example:\n");
bh_printf(" --env=\"key1=value1\" --env=\"key2=value2\"\n");
bh_printf(" --dir=<dir> Grant wasi access to the given host directories\n");
bh_printf(" to the program, for example:\n");
bh_printf(" --dir=<dir1> --dir=<dir2>\n");
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");
#endif
return 1;
@ -49,7 +50,7 @@ app_instance_main(wasm_module_inst_t module_inst)
wasm_application_execute_main(module_inst, app_argc, app_argv);
if ((exception = wasm_runtime_get_exception(module_inst)))
bh_printf("%s\n", exception);
printf("%s\n", exception);
return NULL;
}
@ -100,7 +101,7 @@ app_instance_repl(wasm_module_inst_t module_inst)
size_t len = 0;
ssize_t n;
while ((bh_printf("webassembly> "), n = getline(&cmd, &len, stdin)) != -1) {
while ((printf("webassembly> "), n = getline(&cmd, &len, stdin)) != -1) {
bh_assert(n > 0);
if (cmd[n - 1] == '\n') {
if (n == 1)
@ -204,8 +205,8 @@ int main(int argc, char *argv[])
if (argv[0][6] == '\0')
return print_help();
if (dir_list_size >= sizeof(dir_list) / sizeof(char*)) {
bh_printf("Only allow max dir number %d\n",
(int)(sizeof(dir_list) / sizeof(char*)));
printf("Only allow max dir number %d\n",
(int)(sizeof(dir_list) / sizeof(char*)));
return -1;
}
dir_list[dir_list_size++] = argv[0] + 6;
@ -216,16 +217,16 @@ int main(int argc, char *argv[])
if (argv[0][6] == '\0')
return print_help();
if (env_list_size >= sizeof(env_list) / sizeof(char*)) {
bh_printf("Only allow max env number %d\n",
(int)(sizeof(env_list) / sizeof(char*)));
printf("Only allow max env number %d\n",
(int)(sizeof(env_list) / sizeof(char*)));
return -1;
}
tmp_env = argv[0] + 6;
if (validate_env_str(tmp_env))
env_list[env_list_size++] = tmp_env;
else {
bh_printf("Wasm parse env string failed: expect \"key=value\", got \"%s\"\n",
tmp_env);
printf("Wasm parse env string failed: expect \"key=value\", got \"%s\"\n",
tmp_env);
return print_help();
}
}
@ -256,7 +257,7 @@ int main(int argc, char *argv[])
/* initialize runtime environment */
if (!wasm_runtime_full_init(&init_args)) {
bh_printf("Init runtime environment failed.\n");
printf("Init runtime environment failed.\n");
return -1;
}
@ -270,7 +271,7 @@ int main(int argc, char *argv[])
/* load WASM module */
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
error_buf, sizeof(error_buf)))) {
bh_printf("%s\n", error_buf);
printf("%s\n", error_buf);
goto fail2;
}
@ -288,7 +289,7 @@ int main(int argc, char *argv[])
heap_size,
error_buf,
sizeof(error_buf)))) {
bh_printf("%s\n", error_buf);
printf("%s\n", error_buf);
goto fail3;
}

View File

@ -66,7 +66,9 @@ set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
add_executable (iwasm main.c)
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
add_executable (iwasm main.c ${UNCOMMON_SHARED_SOURCE})
install (TARGETS iwasm DESTINATION bin)

View File

@ -11,6 +11,7 @@
#include "bh_platform.h"
#include "bh_assert.h"
#include "bh_log.h"
#include "bh_read_file.h"
#include "wasm_export.h"
static int app_argc;
@ -18,25 +19,25 @@ static char **app_argv;
static int print_help()
{
bh_printf("Usage: iwasm [-options] wasm_file [args...]\n");
bh_printf("options:\n");
bh_printf(" -f|--function name Specify function name to run in module\n"
" rather than main\n");
printf("Usage: iwasm [-options] wasm_file [args...]\n");
printf("options:\n");
printf(" -f|--function name Specify function name to run in module\n"
" rather than main\n");
#if WASM_ENABLE_LOG != 0
bh_printf(" -v=n Set log verbose level (0 to 5, default is 2),\n"
" larger level with more log\n");
printf(" -v=n Set log verbose level (0 to 5, default is 2),\n"
" larger level with more log\n");
#endif
bh_printf(" --stack-size=n Set maximum stack size in bytes, default is 16 KB\n");
bh_printf(" --heap-size=n Set maximum heap size in bytes, default is 16 KB\n");
bh_printf(" --repl Start a very simple REPL (read-eval-print-loop) mode\n"
" that runs commands in the form of `FUNC ARG...`\n");
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");
#if WASM_ENABLE_LIBC_WASI != 0
bh_printf(" --env=<env> Pass wasi environment variables with \"key=value\"\n");
bh_printf(" to the program, for example:\n");
bh_printf(" --env=\"key1=value1\" --env=\"key2=value2\"\n");
bh_printf(" --dir=<dir> Grant wasi access to the given host directories\n");
bh_printf(" to the program, for example:\n");
bh_printf(" --dir=<dir1> --dir=<dir2>\n");
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");
#endif
return 1;
@ -49,7 +50,7 @@ app_instance_main(wasm_module_inst_t module_inst)
wasm_application_execute_main(module_inst, app_argc, app_argv);
if ((exception = wasm_runtime_get_exception(module_inst)))
bh_printf("%s\n", exception);
printf("%s\n", exception);
return NULL;
}
@ -100,7 +101,7 @@ app_instance_repl(wasm_module_inst_t module_inst)
size_t len = 0;
ssize_t n;
while ((bh_printf("webassembly> "), n = getline(&cmd, &len, stdin)) != -1) {
while ((printf("webassembly> "), n = getline(&cmd, &len, stdin)) != -1) {
bh_assert(n > 0);
if (cmd[n - 1] == '\n') {
if (n == 1)
@ -204,8 +205,8 @@ int main(int argc, char *argv[])
if (argv[0][6] == '\0')
return print_help();
if (dir_list_size >= sizeof(dir_list) / sizeof(char*)) {
bh_printf("Only allow max dir number %d\n",
(int)(sizeof(dir_list) / sizeof(char*)));
printf("Only allow max dir number %d\n",
(int)(sizeof(dir_list) / sizeof(char*)));
return -1;
}
dir_list[dir_list_size++] = argv[0] + 6;
@ -216,16 +217,16 @@ int main(int argc, char *argv[])
if (argv[0][6] == '\0')
return print_help();
if (env_list_size >= sizeof(env_list) / sizeof(char*)) {
bh_printf("Only allow max env number %d\n",
(int)(sizeof(env_list) / sizeof(char*)));
printf("Only allow max env number %d\n",
(int)(sizeof(env_list) / sizeof(char*)));
return -1;
}
tmp_env = argv[0] + 6;
if (validate_env_str(tmp_env))
env_list[env_list_size++] = tmp_env;
else {
bh_printf("Wasm parse env string failed: expect \"key=value\", got \"%s\"\n",
tmp_env);
printf("Wasm parse env string failed: expect \"key=value\", got \"%s\"\n",
tmp_env);
return print_help();
}
}
@ -256,7 +257,7 @@ int main(int argc, char *argv[])
/* initialize runtime environment */
if (!wasm_runtime_full_init(&init_args)) {
bh_printf("Init runtime environment failed.\n");
printf("Init runtime environment failed.\n");
return -1;
}
@ -270,7 +271,7 @@ int main(int argc, char *argv[])
/* load WASM module */
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
error_buf, sizeof(error_buf)))) {
bh_printf("%s\n", error_buf);
printf("%s\n", error_buf);
goto fail2;
}
@ -288,7 +289,7 @@ int main(int argc, char *argv[])
heap_size,
error_buf,
sizeof(error_buf)))) {
bh_printf("%s\n", error_buf);
printf("%s\n", error_buf);
goto fail3;
}

View File

@ -48,7 +48,7 @@ app_instance_main(wasm_module_inst_t module_inst)
wasm_application_execute_main(module_inst, app_argc, app_argv);
if ((exception = wasm_runtime_get_exception(module_inst)))
bh_printf("%s\n", exception);
printf("%s\n", exception);
return NULL;
}
@ -80,7 +80,7 @@ void iwasm_main(void *arg1, void *arg2, void *arg3)
/* initialize runtime environment */
if (!wasm_runtime_full_init(&init_args)) {
bh_printf("Init runtime environment failed.\n");
printf("Init runtime environment failed.\n");
return;
}
@ -95,7 +95,7 @@ void iwasm_main(void *arg1, void *arg2, void *arg3)
/* load WASM module */
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
error_buf, sizeof(error_buf)))) {
bh_printf("%s\n", error_buf);
printf("%s\n", error_buf);
goto fail1;
}
@ -105,7 +105,7 @@ void iwasm_main(void *arg1, void *arg2, void *arg3)
CONFIG_APP_HEAP_SIZE,
error_buf,
sizeof(error_buf)))) {
bh_printf("%s\n", error_buf);
printf("%s\n", error_buf);
goto fail2;
}