Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ iwasm VM core
- [Sign-extension operators](https://github.com/WebAssembly/sign-extension-ops)
- [Bulk memory operations](https://github.com/WebAssembly/bulk-memory-operations)
- [Shared memmory](https://github.com/WebAssembly/threads/blob/main/proposals/threads/Overview.md#shared-linear-memory)
- [Multi-value](https://github.com/WebAssembly/multi-value)

### Performance and memory usage
The WAMR performance, footprint and memory usage data are available at the [performance](../../wiki/Performance) wiki page.
Expand Down
8 changes: 6 additions & 2 deletions core/app-mgr/app-manager/module_wasm_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ wasm_app_module_init(void)
static bool
wasm_app_module_install(request_t * msg)
{
unsigned int m_data_size, heap_size;
unsigned int m_data_size, heap_size, stack_size;
unsigned int timeout, timers, err_size;
char *properties;
int properties_offset;
Expand Down Expand Up @@ -842,9 +842,13 @@ wasm_app_module_install(request_t * msg)
goto fail;
}

stack_size = APP_THREAD_STACK_SIZE_DEFAULT;
#ifdef OS_ENABLE_HW_BOUND_CHECK
stack_size += 4 * BH_KB;
#endif
/* Create WASM app thread. */
if (os_thread_create(&wasm_app_data->thread_id, wasm_app_routine,
(void*) m_data, APP_THREAD_STACK_SIZE_DEFAULT) != 0) {
(void*) m_data, stack_size) != 0) {
module_data_list_remove(m_data);
SEND_ERR_RESPONSE(msg->mid,
"Install WASM app failed: create app thread failed.");
Expand Down
25 changes: 23 additions & 2 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,21 +551,42 @@ load_func_types(const uint8 **p_buf, const uint8 *buf_end,
/* Create each function type */
for (i = 0; i < module->func_type_count; i++) {
uint32 param_count, result_count;
uint32 param_cell_num, ret_cell_num;
uint64 size1;

read_uint32(buf, buf_end, param_count);
read_uint32(buf, buf_end, result_count);

if (param_count > UINT16_MAX || result_count > UINT16_MAX) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"param count or result count too large");
return false;
}

size1 = (uint64)param_count + (uint64)result_count;
size = offsetof(AOTFuncType, types) + size1;
if (!(func_types[i] = loader_malloc
(size, error_buf, error_buf_size))) {
return false;
}

func_types[i]->param_count = param_count;
func_types[i]->result_count = result_count;
func_types[i]->param_count = (uint16)param_count;
func_types[i]->result_count = (uint16)result_count;
read_byte_array(buf, buf_end, func_types[i]->types, (uint32)size1);

param_cell_num = wasm_get_cell_num(func_types[i]->types, param_count);
ret_cell_num = wasm_get_cell_num(func_types[i]->types + param_count,
result_count);
if (param_cell_num > UINT16_MAX || ret_cell_num > UINT16_MAX) {
set_error_buf(error_buf, error_buf_size,
"AOT module load failed: "
"param count or result count too large");
return false;
}

func_types[i]->param_cell_num = (uint16)param_cell_num;
func_types[i]->ret_cell_num = (uint16)ret_cell_num;
}

*p_buf = buf;
Expand Down
150 changes: 144 additions & 6 deletions core/iwasm/aot/aot_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,77 @@ aot_call_function(WASMExecEnv *exec_env,
{
AOTModuleInstance *module_inst = (AOTModuleInstance*)exec_env->module_inst;
AOTFuncType *func_type = function->func_type;
bool ret = invoke_native_internal(exec_env, function->func_ptr,
func_type, NULL, NULL, argv, argc, argv);
return ret && !aot_get_exception(module_inst) ? true : false;
uint32 result_count = func_type->result_count;
uint32 ext_ret_count = result_count > 1 ? result_count - 1 : 0;
bool ret;

if (ext_ret_count > 0) {
uint32 cell_num = 0, i;
uint8 *ext_ret_types = func_type->types + func_type->param_count + 1;
uint32 argv1_buf[32], *argv1 = argv1_buf, *ext_rets = NULL;
uint32 *argv_ret = argv;
uint32 ext_ret_cell = wasm_get_cell_num(ext_ret_types, ext_ret_count);
uint64 size;

/* Allocate memory all arguments */
size = sizeof(uint32) * (uint64)argc /* original arguments */
+ sizeof(void*) * (uint64)ext_ret_count /* extra result values' addr */
+ sizeof(uint32) * (uint64)ext_ret_cell; /* extra result values */
if (size > sizeof(argv1_buf)
&& !(argv1 = runtime_malloc(size, module_inst->cur_exception,
sizeof(module_inst->cur_exception)))) {
aot_set_exception_with_id(module_inst, EXCE_OUT_OF_MEMORY);
return false;
}

/* Copy original arguments */
bh_memcpy_s(argv1, (uint32)size, argv, sizeof(uint32) * argc);

/* Get the extra result value's address */
ext_rets = argv1 + argc + sizeof(void*)/sizeof(uint32) * ext_ret_count;

/* Append each extra result value's address to original arguments */
for (i = 0; i < ext_ret_count; i++) {
*(uintptr_t*)(argv1 + argc + sizeof(void*) / sizeof(uint32) * i) =
(uintptr_t)(ext_rets + cell_num);
cell_num += wasm_value_type_cell_num(ext_ret_types[i]);
}

ret = invoke_native_internal(exec_env, function->func_ptr,
func_type, NULL, NULL, argv1, argc, argv);
if (!ret || aot_get_exception(module_inst)) {
if (argv1 != argv1_buf)
wasm_runtime_free(argv1);
return false;
}

/* Get extra result values */
switch (func_type->types[func_type->param_count]) {
case VALUE_TYPE_I32:
case VALUE_TYPE_F32:
argv_ret++;
break;
case VALUE_TYPE_I64:
case VALUE_TYPE_F64:
argv_ret += 2;
break;
default:
bh_assert(0);
break;
}
ext_rets = argv1 + argc + sizeof(void*)/sizeof(uint32) * ext_ret_count;
bh_memcpy_s(argv_ret, sizeof(uint32) * cell_num,
ext_rets, sizeof(uint32) * cell_num);
if (argv1 != argv1_buf)
wasm_runtime_free(argv1);

return true;
}
else {
ret = invoke_native_internal(exec_env, function->func_ptr,
func_type, NULL, NULL, argv, argc, argv);
return ret && !aot_get_exception(module_inst) ? true : false;
}
}

bool
Expand Down Expand Up @@ -1183,10 +1251,12 @@ aot_call_indirect(WASMExecEnv *exec_env,
void **func_ptrs = (void**)module_inst->func_ptrs.ptr, *func_ptr;
uint32 table_size = module_inst->table_size;
uint32 func_idx, func_type_idx1;
uint32 ext_ret_count;
AOTImportFunc *import_func;
const char *signature = NULL;
void *attachment = NULL;
char buf[128];
bool ret;

/* this function is called from native code, so exec_env->handle and
exec_env->native_stack_boundary must have been set, we don't set
Expand Down Expand Up @@ -1241,9 +1311,77 @@ aot_call_indirect(WASMExecEnv *exec_env,
}
}

return invoke_native_internal(exec_env, func_ptr,
func_type, signature, attachment,
argv, argc, argv);
ext_ret_count = func_type->result_count > 1
? func_type->result_count - 1 : 0;
if (ext_ret_count > 0) {
uint32 argv1_buf[32], *argv1 = argv1_buf;
uint32 *ext_rets = NULL, *argv_ret = argv;
uint32 cell_num = 0, i;
uint8 *ext_ret_types = func_type->types + func_type->param_count + 1;
uint32 ext_ret_cell = wasm_get_cell_num(ext_ret_types, ext_ret_count);
uint64 size;

/* Allocate memory all arguments */
size = sizeof(uint32) * (uint64)argc /* original arguments */
+ sizeof(void*) * (uint64)ext_ret_count /* extra result values' addr */
+ sizeof(uint32) * (uint64)ext_ret_cell; /* extra result values */
if (size > sizeof(argv1_buf)
&& !(argv1 = runtime_malloc(size, module_inst->cur_exception,
sizeof(module_inst->cur_exception)))) {
aot_set_exception_with_id(module_inst, EXCE_OUT_OF_MEMORY);
return false;
}

/* Copy original arguments */
bh_memcpy_s(argv1, (uint32)size, argv, sizeof(uint32) * argc);

/* Get the extra result value's address */
ext_rets = argv1 + argc + sizeof(void*)/sizeof(uint32) * ext_ret_count;

/* Append each extra result value's address to original arguments */
for (i = 0; i < ext_ret_count; i++) {
*(uintptr_t*)(argv1 + argc + sizeof(void*) / sizeof(uint32) * i) =
(uintptr_t)(ext_rets + cell_num);
cell_num += wasm_value_type_cell_num(ext_ret_types[i]);
}

ret = invoke_native_internal(exec_env, func_ptr,
func_type, signature, attachment,
argv1, argc, argv);
if (!ret || aot_get_exception(module_inst)) {
if (argv1 != argv1_buf)
wasm_runtime_free(argv1);
return false;
}

/* Get extra result values */
switch (func_type->types[func_type->param_count]) {
case VALUE_TYPE_I32:
case VALUE_TYPE_F32:
argv_ret++;
break;
case VALUE_TYPE_I64:
case VALUE_TYPE_F64:
argv_ret += 2;
break;
default:
bh_assert(0);
break;
}
ext_rets = argv1 + argc + sizeof(void*)/sizeof(uint32) * ext_ret_count;
bh_memcpy_s(argv_ret, sizeof(uint32) * cell_num,
ext_rets, sizeof(uint32) * cell_num);

if (argv1 != argv1_buf)
wasm_runtime_free(argv1);

return true;
}
else {
return invoke_native_internal(exec_env, func_ptr,
func_type, signature, attachment,
argv, argc, argv);
}
}

#if WASM_ENABLE_BULK_MEMORY != 0
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/common/arch/invokeNative_aarch64.s
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ invokeNative:
cmp x21, #0
beq call_func

/* Fill all stack args: reserve stack space and fill ony by one */
/* Fill all stack args: reserve stack space and fill one by one */
mov x23, sp
bic sp, x23, #15 /* Ensure stack is 16 bytes aligned */
lsl x23, x21, #3 /* x23 = nstacks * 8 */
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/common/arch/invokeNative_arm_vfp.s
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ invokeNative:
beq call_func


/* Fill all stack args: reserve stack space and fill ony by one */
/* Fill all stack args: reserve stack space and fill one by one */
add r4, r4, #64 /* r4 points to stack args */
bic sp, sp, #7 /* Ensure stack is 8 byte aligned */
mov r7, r5, lsl#2 /* r7 = nstacks * 4 */
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/common/wasm_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ check_symbol_signature(const WASMType *type, const char *signature)
if (*p++ != '(')
return false;

if ((uint32)(p_end - p) < type->param_count + 1)
if ((uint32)(p_end - p) < (uint32)(type->param_count + 1))
/* signatures of parameters, and ')' */
return false;

Expand Down
Loading