Re-org memory allocation interfaces, add --stack-size and --heap-size option (#193)
This commit is contained in:
@ -5,6 +5,9 @@ NAME := iwasm
|
||||
IWASM_ROOT := wamr/core/iwasm
|
||||
SHARED_ROOT := wamr/core/shared
|
||||
|
||||
GLOBAL_DEFINES += BH_MALLOC=wasm_runtime_malloc
|
||||
GLOBAL_DEFINES += BH_FREE=wasm_runtime_free
|
||||
|
||||
# Change it to THUMBV7M if you want to build for developerkit
|
||||
WAMR_BUILD_TARGET := X86_32
|
||||
|
||||
@ -76,7 +79,6 @@ $(NAME)_SOURCES := ${SHARED_ROOT}/platform/alios/bh_assert.c \
|
||||
${SHARED_ROOT}/platform/alios/bh_platform_log.c \
|
||||
${SHARED_ROOT}/platform/alios/bh_thread.c \
|
||||
${SHARED_ROOT}/platform/alios/bh_time.c \
|
||||
${SHARED_ROOT}/mem-alloc/bh_memory.c \
|
||||
${SHARED_ROOT}/mem-alloc/mem_alloc.c \
|
||||
${SHARED_ROOT}/mem-alloc/ems/ems_kfc.c \
|
||||
${SHARED_ROOT}/mem-alloc/ems/ems_alloc.c \
|
||||
@ -91,6 +93,7 @@ $(NAME)_SOURCES := ${SHARED_ROOT}/platform/alios/bh_assert.c \
|
||||
${IWASM_ROOT}/common/wasm_runtime_common.c \
|
||||
${IWASM_ROOT}/common/wasm_native.c \
|
||||
${IWASM_ROOT}/common/wasm_exec_env.c \
|
||||
${IWASM_ROOT}/common/wasm_memory.c \
|
||||
${IWASM_ROOT}/common/arch/${INVOKE_NATIVE} \
|
||||
src/main.c
|
||||
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
#include "bh_log.h"
|
||||
#include "bh_platform_log.h"
|
||||
#include "wasm_export.h"
|
||||
#include "bh_memory.h"
|
||||
#include "test_wasm.h"
|
||||
|
||||
static int app_argc;
|
||||
@ -48,6 +47,7 @@ void iwasm_main(void *arg1)
|
||||
uint32 wasm_file_size;
|
||||
wasm_module_t wasm_module = NULL;
|
||||
wasm_module_inst_t wasm_module_inst = NULL;
|
||||
RuntimeInitArgs init_args;
|
||||
char error_buf[128];
|
||||
#if WASM_ENABLE_LOG != 0
|
||||
int log_verbose_level = 2;
|
||||
@ -55,15 +55,17 @@ void iwasm_main(void *arg1)
|
||||
|
||||
(void) arg1;
|
||||
|
||||
if (bh_memory_init_with_pool(global_heap_buf, sizeof(global_heap_buf))
|
||||
!= 0) {
|
||||
bh_printf("Init global heap failed.\n");
|
||||
return;
|
||||
}
|
||||
memset(&init_args, 0, sizeof(RuntimeInitArgs));
|
||||
|
||||
init_args.mem_alloc_type = Alloc_With_Pool;
|
||||
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
|
||||
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
|
||||
|
||||
/* initialize runtime environment */
|
||||
if (!wasm_runtime_init())
|
||||
goto fail1;
|
||||
if (!wasm_runtime_full_init(&init_args)) {
|
||||
bh_printf("Init runtime environment failed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_LOG != 0
|
||||
bh_log_set_verbose_level(log_verbose_level);
|
||||
@ -77,14 +79,17 @@ void iwasm_main(void *arg1)
|
||||
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
|
||||
error_buf, sizeof(error_buf)))) {
|
||||
bh_printf("%s\n", error_buf);
|
||||
goto fail2;
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
/* instantiate the module */
|
||||
if (!(wasm_module_inst = wasm_runtime_instantiate(wasm_module, 8 * 1024,
|
||||
8 * 1024, error_buf, sizeof(error_buf)))) {
|
||||
if (!(wasm_module_inst = wasm_runtime_instantiate(wasm_module,
|
||||
8 * 1024,
|
||||
8 * 1024,
|
||||
error_buf,
|
||||
sizeof(error_buf)))) {
|
||||
bh_printf("%s\n", error_buf);
|
||||
goto fail3;
|
||||
goto fail2;
|
||||
}
|
||||
|
||||
app_instance_main(wasm_module_inst);
|
||||
@ -92,15 +97,13 @@ void iwasm_main(void *arg1)
|
||||
/* destroy the module instance */
|
||||
wasm_runtime_deinstantiate(wasm_module_inst);
|
||||
|
||||
fail3:
|
||||
fail2:
|
||||
/* unload the module */
|
||||
wasm_runtime_unload(wasm_module);
|
||||
|
||||
fail2:
|
||||
fail1:
|
||||
/* destroy runtime environment */
|
||||
wasm_runtime_destroy();
|
||||
|
||||
fail1: bh_memory_destroy();
|
||||
}
|
||||
|
||||
#define DEFAULT_THREAD_STACKSIZE (6 * 1024)
|
||||
|
||||
Reference in New Issue
Block a user