Re-org memory allocation interfaces, add --stack-size and --heap-size option (#193)
This commit is contained in:
@ -84,9 +84,9 @@ typedef int16_t lv_coord_t;
|
||||
/* Automatically defrag. on free. Defrag. means joining the adjacent free cells. */
|
||||
# define LV_MEM_AUTO_DEFRAG 1
|
||||
#else /*LV_MEM_CUSTOM*/
|
||||
# define LV_MEM_CUSTOM_INCLUDE "bh_memory.h" /*Header for the dynamic memory function*/
|
||||
# define LV_MEM_CUSTOM_ALLOC bh_malloc /*Wrapper to malloc*/
|
||||
# define LV_MEM_CUSTOM_FREE bh_free /*Wrapper to free*/
|
||||
# define LV_MEM_CUSTOM_INCLUDE "bh_config.h" /*Header for the dynamic memory function*/
|
||||
# define LV_MEM_CUSTOM_ALLOC BH_MALLOC /*Wrapper to malloc*/
|
||||
# define LV_MEM_CUSTOM_FREE BH_FREE /*Wrapper to free*/
|
||||
#endif /*LV_MEM_CUSTOM*/
|
||||
|
||||
/* Garbage Collector settings
|
||||
|
||||
@ -27,7 +27,6 @@
|
||||
#include "bh_common.h"
|
||||
#include "bh_queue.h"
|
||||
#include "bh_thread.h"
|
||||
#include "bh_memory.h"
|
||||
#include "runtime_sensor.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
#include "module_wasm_app.h"
|
||||
@ -466,19 +465,22 @@ static void hal_init(void)
|
||||
// Driver function
|
||||
int iwasm_main(int argc, char *argv[])
|
||||
{
|
||||
RuntimeInitArgs init_args;
|
||||
korp_thread tid;
|
||||
|
||||
if (!parse_args(argc, argv))
|
||||
return -1;
|
||||
|
||||
if (bh_memory_init_with_pool(global_heap_buf, sizeof(global_heap_buf))
|
||||
!= 0) {
|
||||
printf("Init global heap failed.\n");
|
||||
return -1;
|
||||
}
|
||||
memset(&init_args, 0, sizeof(RuntimeInitArgs));
|
||||
|
||||
if (vm_thread_sys_init() != 0) {
|
||||
goto fail1;
|
||||
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_full_init(&init_args)) {
|
||||
bh_printf("Init runtime environment failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!init_connection_framework()) {
|
||||
@ -513,7 +515,6 @@ int iwasm_main(int argc, char *argv[])
|
||||
exit_connection_framework();
|
||||
|
||||
fail1:
|
||||
bh_memory_destroy();
|
||||
|
||||
wasm_runtime_destroy();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
#include "bh_common.h"
|
||||
#include "bh_queue.h"
|
||||
#include "bh_thread.h"
|
||||
#include "bh_memory.h"
|
||||
#include "runtime_sensor.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
#include "module_wasm_app.h"
|
||||
@ -146,16 +145,19 @@ static void hal_init(void)
|
||||
|
||||
int iwasm_main()
|
||||
{
|
||||
RuntimeInitArgs init_args;
|
||||
host_init();
|
||||
|
||||
if (bh_memory_init_with_pool(global_heap_buf, sizeof(global_heap_buf))
|
||||
!= 0) {
|
||||
printf("Init global heap failed.\n");
|
||||
return -1;
|
||||
}
|
||||
memset(&init_args, 0, sizeof(RuntimeInitArgs));
|
||||
|
||||
if (vm_thread_sys_init() != 0) {
|
||||
goto fail1;
|
||||
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_full_init(&init_args)) {
|
||||
bh_printf("Init runtime environment failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
wgl_init();
|
||||
@ -167,7 +169,6 @@ int iwasm_main()
|
||||
// TODO:
|
||||
app_manager_startup(&interface);
|
||||
|
||||
fail1:
|
||||
bh_memory_destroy();
|
||||
wasm_runtime_destroy();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
#include "bh_log.h"
|
||||
#include "bh_platform_log.h"
|
||||
#include "wasm_export.h"
|
||||
#include "bh_memory.h"
|
||||
|
||||
extern int iwasm_main();
|
||||
|
||||
|
||||
@ -10,6 +10,9 @@ set (WAMR_BUILD_PLATFORM "zephyr")
|
||||
|
||||
enable_language (ASM)
|
||||
|
||||
add_definitions(-DWA_MALLOC=wasm_runtime_malloc)
|
||||
add_definitions(-DWA_FREE=wasm_runtime_free)
|
||||
|
||||
# Build as THUMB by default
|
||||
# change to "ARM[sub]", "THUMB[sub]", "X86_32", "MIPS" or "XTENSA"
|
||||
# if we want to support arm_32, x86, mips or xtensa
|
||||
@ -17,7 +20,6 @@ if (NOT DEFINED WAMR_BUILD_TARGET)
|
||||
set (WAMR_BUILD_TARGET "THUMBV7")
|
||||
endif ()
|
||||
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_INTERP)
|
||||
# Enable Interpreter by default
|
||||
set (WAMR_BUILD_INTERP 1)
|
||||
|
||||
@ -27,7 +27,6 @@
|
||||
#include "bh_common.h"
|
||||
#include "bh_queue.h"
|
||||
#include "bh_thread.h"
|
||||
#include "bh_memory.h"
|
||||
#include "runtime_sensor.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
#include "module_wasm_app.h"
|
||||
@ -448,8 +447,6 @@ static bool parse_args(int argc, char *argv[])
|
||||
}
|
||||
|
||||
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*)"),
|
||||
@ -461,29 +458,29 @@ static NativeSymbol native_symbols[] = {
|
||||
// Driver function
|
||||
int iwasm_main(int argc, char *argv[])
|
||||
{
|
||||
RuntimeInitArgs init_args;
|
||||
korp_thread tid;
|
||||
uint32 n_native_symbols;
|
||||
|
||||
if (!parse_args(argc, argv))
|
||||
return -1;
|
||||
|
||||
if (bh_memory_init_with_pool(global_heap_buf, sizeof(global_heap_buf))
|
||||
!= 0) {
|
||||
printf("Init global heap failed.\n");
|
||||
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);
|
||||
|
||||
init_args.native_module_name = "env";
|
||||
init_args.n_native_symbols = sizeof(native_symbols) / sizeof(NativeSymbol);
|
||||
init_args.native_symbols = native_symbols;
|
||||
|
||||
/* initialize runtime environment */
|
||||
if (!wasm_runtime_full_init(&init_args)) {
|
||||
bh_printf("Init runtime environment failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vm_thread_sys_init() != 0) {
|
||||
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;
|
||||
@ -514,7 +511,7 @@ int iwasm_main(int argc, char *argv[])
|
||||
exit_connection_framework();
|
||||
|
||||
fail1:
|
||||
bh_memory_destroy();
|
||||
wasm_runtime_destroy();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
#include "bh_common.h"
|
||||
#include "bh_queue.h"
|
||||
#include "bh_thread.h"
|
||||
#include "bh_memory.h"
|
||||
#include "runtime_sensor.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
#include "module_wasm_app.h"
|
||||
@ -80,8 +79,6 @@ timer_ctx_t timer_ctx;
|
||||
static char global_heap_buf[370 * 1024] = { 0 };
|
||||
|
||||
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*)"),
|
||||
@ -92,28 +89,28 @@ static NativeSymbol native_symbols[] = {
|
||||
|
||||
int iwasm_main()
|
||||
{
|
||||
RuntimeInitArgs init_args;
|
||||
korp_thread tid, tm_tid;
|
||||
uint32 n_native_symbols;
|
||||
|
||||
host_init();
|
||||
|
||||
if (bh_memory_init_with_pool(global_heap_buf, sizeof(global_heap_buf))
|
||||
!= 0) {
|
||||
printf("Init global heap failed.\n");
|
||||
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);
|
||||
|
||||
init_args.native_module_name = "env";
|
||||
init_args.n_native_symbols = sizeof(native_symbols) / sizeof(NativeSymbol);
|
||||
init_args.native_symbols = native_symbols;
|
||||
|
||||
/* initialize runtime environment */
|
||||
if (!wasm_runtime_full_init(&init_args)) {
|
||||
bh_printf("Init runtime environment failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vm_thread_sys_init() != 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
display_init();
|
||||
|
||||
// timer manager
|
||||
@ -122,7 +119,6 @@ int iwasm_main()
|
||||
// TODO:
|
||||
app_manager_startup(&interface);
|
||||
|
||||
fail1:
|
||||
bh_memory_destroy();
|
||||
wasm_runtime_destroy();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -10,9 +10,10 @@
|
||||
#include "bh_log.h"
|
||||
#include "bh_platform_log.h"
|
||||
#include "wasm_export.h"
|
||||
#include "bh_memory.h"
|
||||
|
||||
extern void display_init(void);
|
||||
extern int iwasm_main();
|
||||
|
||||
void main(void)
|
||||
{
|
||||
display_init();
|
||||
|
||||
@ -10,6 +10,9 @@ set (WAMR_BUILD_PLATFORM "zephyr")
|
||||
|
||||
enable_language (ASM)
|
||||
|
||||
add_definitions(-DWA_MALLOC=wasm_runtime_malloc)
|
||||
add_definitions(-DWA_FREE=wasm_runtime_free)
|
||||
|
||||
# Build as THUMB by default
|
||||
# change to "ARM[sub]", "THUMB[sub]", "X86_32", "MIPS_32" or "XTENSA_32"
|
||||
# if we want to support arm_32, x86, mips or xtensa
|
||||
|
||||
@ -27,7 +27,6 @@
|
||||
#include "bh_common.h"
|
||||
#include "bh_queue.h"
|
||||
#include "bh_thread.h"
|
||||
#include "bh_memory.h"
|
||||
#include "runtime_sensor.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
#include "module_wasm_app.h"
|
||||
@ -462,54 +461,50 @@ static bool parse_args(int argc, char *argv[])
|
||||
// Driver function
|
||||
int iwasm_main(int argc, char *argv[])
|
||||
{
|
||||
RuntimeInitArgs init_args;
|
||||
korp_thread tid;
|
||||
|
||||
if (!parse_args(argc, argv))
|
||||
return -1;
|
||||
|
||||
#if 1
|
||||
if (bh_memory_init_with_pool(global_heap_buf, sizeof(global_heap_buf))
|
||||
memset(&init_args, 0, sizeof(RuntimeInitArgs));
|
||||
|
||||
#if USE_GLOBAL_HEAP_BUF != 0
|
||||
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);
|
||||
#else
|
||||
if (bh_memory_init_with_allocator(malloc, free)
|
||||
init_args.mem_alloc_type = Alloc_With_Allocator;
|
||||
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;
|
||||
#endif
|
||||
!= 0) {
|
||||
printf("Init global heap failed.\n");
|
||||
|
||||
/* initialize runtime environment */
|
||||
if (!wasm_runtime_full_init(&init_args)) {
|
||||
bh_printf("Init runtime environment failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vm_thread_sys_init() != 0) {
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
//
|
||||
// timer manager
|
||||
//
|
||||
/* timer manager */
|
||||
init_wasm_timer();
|
||||
|
||||
|
||||
//
|
||||
// connection framework
|
||||
//
|
||||
/* connection framework */
|
||||
if (!init_connection_framework()) {
|
||||
vm_thread_sys_destroy();
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
//
|
||||
// sensor framework
|
||||
//
|
||||
/* sensor framework */
|
||||
init_sensor_framework();
|
||||
// add the sys sensor objects
|
||||
add_sys_sensor("sensor_test",
|
||||
"This is a sensor for test",
|
||||
0,
|
||||
1000,
|
||||
read_test_sensor,
|
||||
"This is a sensor for test",
|
||||
0,
|
||||
1000,
|
||||
read_test_sensor,
|
||||
config_test_sensor);
|
||||
start_sensor_framework();
|
||||
|
||||
|
||||
|
||||
#ifndef CONNECTION_UART
|
||||
if (server_mode)
|
||||
vm_thread_create(&tid, func_server_mode, NULL,
|
||||
@ -527,7 +522,7 @@ int iwasm_main(int argc, char *argv[])
|
||||
exit_connection_framework();
|
||||
|
||||
fail1:
|
||||
bh_memory_destroy();
|
||||
wasm_runtime_destroy();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user