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:
@ -111,6 +111,19 @@ add_custom_command (
|
||||
|
||||
add_custom_target (vmlib_untrusted ALL DEPENDS libvmlib_untrusted.a)
|
||||
|
||||
if (DEFINED WAMR_BUILD_GLOBAL_HEAP_POOL)
|
||||
execute_process(
|
||||
COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_GLOBAL_HEAP_POOL = .*/WAMR_BUILD_GLOBAL_HEAP_POOL = ${WAMR_BUILD_GLOBAL_HEAP_POOL}/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile"
|
||||
OUTPUT_VARIABLE cmdOutput
|
||||
)
|
||||
if (DEFINED WAMR_BUILD_GLOBAL_HEAP_SIZE)
|
||||
execute_process(
|
||||
COMMAND bash -c "sed -i -E 's/^WAMR_BUILD_GLOBAL_HEAP_SIZE = .*/WAMR_BUILD_GLOBAL_HEAP_SIZE = ${WAMR_BUILD_GLOBAL_HEAP_SIZE}/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Makefile"
|
||||
OUTPUT_VARIABLE cmdOutput
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (WAMR_BUILD_LIB_RATS EQUAL 1)
|
||||
execute_process(
|
||||
COMMAND bash -c "sed -i -E 's/^#define LIB_RATS 0 /#define LIB_RATS 1/g' ${CMAKE_CURRENT_SOURCE_DIR}/enclave-sample/Enclave/Enclave.edl"
|
||||
|
||||
@ -370,15 +370,14 @@ set_log_verbose_level(int log_verbose_level)
|
||||
}
|
||||
|
||||
static bool
|
||||
init_runtime(bool alloc_with_pool, uint32_t max_thread_num)
|
||||
init_runtime(uint32_t max_thread_num)
|
||||
{
|
||||
uint64_t ecall_args[2];
|
||||
uint64_t ecall_args[1];
|
||||
|
||||
ecall_args[0] = alloc_with_pool;
|
||||
ecall_args[1] = max_thread_num;
|
||||
ecall_args[0] = max_thread_num;
|
||||
if (SGX_SUCCESS
|
||||
!= ecall_handle_command(g_eid, CMD_INIT_RUNTIME, (uint8_t *)ecall_args,
|
||||
sizeof(uint64_t) * 2)) {
|
||||
sizeof(ecall_args))) {
|
||||
printf("Call ecall_handle_command() failed.\n");
|
||||
return false;
|
||||
}
|
||||
@ -612,7 +611,7 @@ main(int argc, char *argv[])
|
||||
void *wasm_module_inst = NULL;
|
||||
char error_buf[128] = { 0 };
|
||||
int log_verbose_level = 2;
|
||||
bool is_repl_mode = false, alloc_with_pool = false;
|
||||
bool is_repl_mode = false;
|
||||
const char *dir_list[8] = { NULL };
|
||||
uint32_t dir_list_size = 0;
|
||||
const char *env_list[8] = { NULL };
|
||||
@ -628,7 +627,7 @@ main(int argc, char *argv[])
|
||||
|
||||
#if TEST_OCALL_API != 0
|
||||
{
|
||||
if (!init_runtime(alloc_with_pool, max_thread_num)) {
|
||||
if (!init_runtime(max_thread_num)) {
|
||||
return -1;
|
||||
}
|
||||
ecall_iwasm_test(g_eid);
|
||||
@ -735,7 +734,7 @@ main(int argc, char *argv[])
|
||||
wasm_file = argv[0];
|
||||
|
||||
/* Init runtime */
|
||||
if (!init_runtime(alloc_with_pool, max_thread_num)) {
|
||||
if (!init_runtime(max_thread_num)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -828,7 +827,7 @@ wamr_pal_create_process(struct wamr_pal_create_process_args *args)
|
||||
{
|
||||
uint32_t stack_size = 16 * 1024, heap_size = 16 * 1024;
|
||||
int log_verbose_level = 2;
|
||||
bool is_repl_mode = false, alloc_with_pool = false;
|
||||
bool is_repl_mode = false;
|
||||
const char *dir_list[8] = { NULL };
|
||||
uint32_t dir_list_size = 0;
|
||||
const char *env_list[8] = { NULL };
|
||||
@ -871,7 +870,7 @@ wamr_pal_create_process(struct wamr_pal_create_process_args *args)
|
||||
}
|
||||
|
||||
/* Init runtime */
|
||||
if (!init_runtime(alloc_with_pool, max_thread_num)) {
|
||||
if (!init_runtime(max_thread_num)) {
|
||||
printf("Failed to init runtime\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
<ProdID>0</ProdID>
|
||||
<ISVSVN>0</ISVSVN>
|
||||
<StackMaxSize>0x100000</StackMaxSize>
|
||||
<HeapMaxSize>0x2000000</HeapMaxSize>
|
||||
<HeapMaxSize>0x8000000</HeapMaxSize>
|
||||
<ReservedMemMaxSize>0x1000000</ReservedMemMaxSize>
|
||||
<ReservedMemExecutable>1</ReservedMemExecutable>
|
||||
<TCSNum>10</TCSNum>
|
||||
|
||||
@ -64,10 +64,8 @@ typedef struct EnclaveModule {
|
||||
uint32 total_size_mapped;
|
||||
} EnclaveModule;
|
||||
|
||||
#if WASM_ENABLE_SPEC_TEST == 0
|
||||
static char global_heap_buf[10 * 1024 * 1024] = { 0 };
|
||||
#else
|
||||
static char global_heap_buf[100 * 1024 * 1024] = { 0 };
|
||||
#if WASM_ENABLE_GLOBAL_HEAP_POOL != 0
|
||||
static char global_heap_buf[WASM_GLOBAL_HEAP_SIZE] = { 0 };
|
||||
#endif
|
||||
|
||||
static void
|
||||
@ -80,32 +78,25 @@ set_error_buf(char *error_buf, uint32 error_buf_size, const char *string)
|
||||
static void
|
||||
handle_cmd_init_runtime(uint64 *args, uint32 argc)
|
||||
{
|
||||
bool alloc_with_pool;
|
||||
uint32 max_thread_num;
|
||||
RuntimeInitArgs init_args;
|
||||
|
||||
bh_assert(argc == 2);
|
||||
bh_assert(argc == 1);
|
||||
|
||||
os_set_print_function(enclave_print);
|
||||
|
||||
#if WASM_ENABLE_SPEC_TEST == 0
|
||||
alloc_with_pool = (bool)args[0];
|
||||
#else
|
||||
alloc_with_pool = true;
|
||||
#endif
|
||||
max_thread_num = (uint32)args[1];
|
||||
max_thread_num = (uint32)args[0];
|
||||
|
||||
memset(&init_args, 0, sizeof(RuntimeInitArgs));
|
||||
init_args.max_thread_num = max_thread_num;
|
||||
|
||||
if (alloc_with_pool) {
|
||||
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 {
|
||||
init_args.mem_alloc_type = Alloc_With_System_Allocator;
|
||||
}
|
||||
#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
|
||||
init_args.mem_alloc_type = Alloc_With_System_Allocator;
|
||||
#endif
|
||||
|
||||
/* initialize runtime environment */
|
||||
if (!wasm_runtime_full_init(&init_args)) {
|
||||
@ -604,9 +595,13 @@ ecall_iwasm_main(uint8_t *wasm_file_buf, uint32_t wasm_file_size)
|
||||
|
||||
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
|
||||
init_args.mem_alloc_type = Alloc_With_System_Allocator;
|
||||
#endif
|
||||
|
||||
/* initialize runtime environment */
|
||||
if (!wasm_runtime_full_init(&init_args)) {
|
||||
|
||||
@ -9,8 +9,10 @@ SGX_ARCH ?= x64
|
||||
SGX_DEBUG ?= 0
|
||||
SPEC_TEST ?= 0
|
||||
|
||||
# This variable is automatically set by CMakeLists.txt
|
||||
# These variables are automatically set by CMakeLists.txt
|
||||
SGX_IPFS = 0
|
||||
WAMR_BUILD_GLOBAL_HEAP_POOL = 0
|
||||
WAMR_BUILD_GLOBAL_HEAP_SIZE = 10485760
|
||||
|
||||
VMLIB_BUILD_DIR ?= $(CURDIR)/../build
|
||||
LIB_RATS_SRC ?= $(VMLIB_BUILD_DIR)/_deps/librats-build
|
||||
@ -132,7 +134,7 @@ ifeq ($(LIB_RATS), 1)
|
||||
Enclave_Include_Paths += -I$(LIB_RATS_INCLUDE_DIR)
|
||||
endif
|
||||
|
||||
Enclave_C_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $(Enclave_Include_Paths)
|
||||
Enclave_C_Flags := $(SGX_COMMON_CFLAGS) -nostdinc -fvisibility=hidden -fpie -fstack-protector $(Enclave_Include_Paths) -DWASM_GLOBAL_HEAP_SIZE=$(WAMR_BUILD_GLOBAL_HEAP_SIZE) -DWASM_ENABLE_GLOBAL_HEAP_POOL=$(WAMR_BUILD_GLOBAL_HEAP_POOL)
|
||||
ifeq ($(SPEC_TEST), 1)
|
||||
Enclave_C_Flags += -DWASM_ENABLE_SPEC_TEST=1
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user