Re-org memory allocation interfaces, add --stack-size and --heap-size option (#193)

This commit is contained in:
wenyongh
2020-03-10 19:54:44 +08:00
committed by GitHub
parent 381859d530
commit 0fdd49ea31
110 changed files with 1264 additions and 2125 deletions

View File

@ -51,10 +51,10 @@ memories_deinstantiate(WASMMemoryInstance **memories, uint32 count)
if (memories[i]) {
if (memories[i]->heap_handle)
mem_allocator_destroy(memories[i]->heap_handle);
wasm_free(memories[i]->heap_data);
wasm_free(memories[i]);
wasm_runtime_free(memories[i]->heap_data);
wasm_runtime_free(memories[i]);
}
wasm_free(memories);
wasm_runtime_free(memories);
}
}
@ -72,7 +72,7 @@ memory_instantiate(uint32 num_bytes_per_page,
/* Allocate memory space, addr data and global data */
if (total_size >= UINT32_MAX
|| !(memory = wasm_malloc((uint32)total_size))) {
|| !(memory = wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate memory failed: allocate memory failed.");
return NULL;
@ -92,7 +92,7 @@ memory_instantiate(uint32 num_bytes_per_page,
memory->end_addr = memory->global_data + global_data_size;
/* Allocate heap space */
if (!(memory->heap_data = wasm_malloc(heap_size))) {
if (!(memory->heap_data = wasm_runtime_malloc(heap_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate memory failed: allocate memory failed.");
goto fail1;
@ -114,10 +114,10 @@ memory_instantiate(uint32 num_bytes_per_page,
return memory;
fail2:
wasm_free(memory->heap_data);
wasm_runtime_free(memory->heap_data);
fail1:
wasm_free(memory);
wasm_runtime_free(memory);
return NULL;
}
@ -141,7 +141,7 @@ memories_instantiate(const WASMModule *module,
total_size = sizeof(WASMMemoryInstance*) * (uint64)memory_count;
if (total_size >= UINT32_MAX
|| !(memories = wasm_malloc((uint32)total_size))) {
|| !(memories = wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate memory failed: "
"allocate memory failed.");
@ -210,8 +210,8 @@ tables_deinstantiate(WASMTableInstance **tables, uint32 count)
if (tables) {
for (i = 0; i < count; i++)
if (tables[i])
wasm_free(tables[i]);
wasm_free(tables);
wasm_runtime_free(tables[i]);
wasm_runtime_free(tables);
}
}
@ -229,7 +229,7 @@ tables_instantiate(const WASMModule *module,
WASMTableInstance **tables, *table;
if (total_size >= UINT32_MAX
|| !(tables = wasm_malloc((uint32)total_size))) {
|| !(tables = wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate table failed: "
"allocate memory failed.");
@ -244,7 +244,8 @@ tables_instantiate(const WASMModule *module,
total_size = offsetof(WASMTableInstance, base_addr) +
sizeof(uint32) * (uint64)import->u.table.init_size;
if (total_size >= UINT32_MAX
|| !(table = tables[table_index++] = wasm_malloc((uint32)total_size))) {
|| !(table = tables[table_index++] =
wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate table failed: "
"allocate memory failed.");
@ -264,7 +265,8 @@ tables_instantiate(const WASMModule *module,
total_size = offsetof(WASMTableInstance, base_addr) +
sizeof(uint32) * (uint64)module->tables[i].init_size;
if (total_size >= UINT32_MAX
|| !(table = tables[table_index++] = wasm_malloc((uint32)total_size))) {
|| !(table = tables[table_index++] =
wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate table failed: "
"allocate memory failed.");
@ -290,7 +292,7 @@ static void
functions_deinstantiate(WASMFunctionInstance *functions, uint32 count)
{
if (functions) {
wasm_free(functions);
wasm_runtime_free(functions);
}
}
@ -308,7 +310,7 @@ functions_instantiate(const WASMModule *module,
WASMFunctionInstance *functions, *function;
if (total_size >= UINT32_MAX
|| !(functions = wasm_malloc((uint32)total_size))) {
|| !(functions = wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate function failed: "
"allocate memory failed.");
@ -373,7 +375,7 @@ static void
globals_deinstantiate(WASMGlobalInstance *globals)
{
if (globals)
wasm_free(globals);
wasm_runtime_free(globals);
}
/**
@ -392,7 +394,7 @@ globals_instantiate(const WASMModule *module,
WASMGlobalInstance *globals, *global;
if (total_size >= UINT32_MAX
|| !(globals = wasm_malloc((uint32)total_size))) {
|| !(globals = wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate global failed: "
"allocate memory failed.");
@ -505,7 +507,7 @@ static void
export_functions_deinstantiate(WASMExportFuncInstance *functions)
{
if (functions)
wasm_free(functions);
wasm_runtime_free(functions);
}
/**
@ -523,7 +525,7 @@ export_functions_instantiate(const WASMModule *module,
uint64 total_size = sizeof(WASMExportFuncInstance) * (uint64)export_func_count;
if (total_size >= UINT32_MAX
|| !(export_func = export_funcs = wasm_malloc((uint32)total_size))) {
|| !(export_func = export_funcs = wasm_runtime_malloc((uint32)total_size))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate export function failed: "
"allocate memory failed.");
@ -623,7 +625,7 @@ wasm_instantiate(WASMModule *module,
return NULL;
/* Allocate the memory */
if (!(module_inst = wasm_malloc((uint32)sizeof(WASMModuleInstance)))) {
if (!(module_inst = wasm_runtime_malloc((uint32)sizeof(WASMModuleInstance)))) {
set_error_buf(error_buf, error_buf_size,
"Instantiate module failed: allocate memory failed.");
globals_deinstantiate(globals);
@ -850,7 +852,7 @@ wasm_deinstantiate(WASMModuleInstance *module_inst)
globals_deinstantiate(module_inst->globals);
export_functions_deinstantiate(module_inst->export_functions);
wasm_free(module_inst);
wasm_runtime_free(module_inst);
}
WASMFunctionInstance*
@ -1128,8 +1130,8 @@ wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count)
return false;
}
if (!(new_memory = wasm_realloc(memory, (uint32)total_size))) {
if (!(new_memory = wasm_malloc((uint32)total_size))) {
if (!(new_memory = wasm_runtime_realloc(memory, (uint32)total_size))) {
if (!(new_memory = wasm_runtime_malloc((uint32)total_size))) {
wasm_set_exception(module, "fail to enlarge memory.");
return false;
}
@ -1138,7 +1140,7 @@ wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count)
(uint8*)memory, total_size_old);
memset((uint8*)new_memory + total_size_old,
0, (uint32)total_size - total_size_old);
wasm_free(memory);
wasm_runtime_free(memory);
}
new_memory->cur_page_count = total_page_count;