Normalize how the global heap pool is configured across iwasm apps (#1628)

Use the cmake variable `WAMR_BUILD_GLOBAL_HEAP_POOL` and
`WAMR_BUILD_GLOBAL_HEAP_SIZE` to enable/disable the global heap pool
and set its size. And set the default global heap size in core/config.h and
the cmake files.

As a result, the developers who build iwasm can easily enable/disable the
global heap pool and change its size regardless of the iwasm implementation,
without manually finding and patching the right location for that value.
This commit is contained in:
Jämes Ménétrey
2022-10-25 15:36:24 +02:00
committed by GitHub
parent b5eea934cf
commit 6adf9194d4
17 changed files with 137 additions and 54 deletions

View File

@ -31,7 +31,7 @@
#define CONFIG_APP_HEAP_SIZE 256
#else /* else of BUILD_TARGET_RISCV64_LP64 || BUILD_TARGET_RISCV32_ILP32 */
#define CONFIG_GLOBAL_HEAP_BUF_SIZE 131072
#define CONFIG_GLOBAL_HEAP_BUF_SIZE WASM_GLOBAL_HEAP_SIZE
#define CONFIG_APP_STACK_SIZE 8192
#define CONFIG_APP_HEAP_SIZE 8192
@ -103,7 +103,9 @@ app_instance_main(wasm_module_inst_t module_inst)
return NULL;
}
#if WASM_ENABLE_GLOBAL_HEAP_POOL != 0
static char global_heap_buf[CONFIG_GLOBAL_HEAP_BUF_SIZE] = { 0 };
#endif
#ifdef CONFIG_BOARD_ESP32
#include "mem_alloc.h"
@ -176,9 +178,13 @@ iwasm_main(void *arg1, void *arg2, void *arg3)
memset(&init_args, 0, sizeof(RuntimeInitArgs));
#if WASM_ENABLE_GLOBAL_HEAP_POOL != 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
#error Another memory allocation scheme than global heap pool is not implemented yet for Zephyr.
#endif
/* initialize runtime environment */
if (!wasm_runtime_full_init(&init_args)) {