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
8 changes: 4 additions & 4 deletions core/iwasm/aot/aot_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1454,14 +1454,14 @@ load_text_section(const uint8 *buf, const uint8 *buf_end, AOTModule *module,
/* Now code points to an ELF object, we pull it down to .text section */
uint64 offset;
uint64 size;
char *buf = module->code;
module->elf_hdr = buf;
if (!get_text_section(buf, &offset, &size)) {
char *code_buf = module->code;
module->elf_hdr = code_buf;
if (!get_text_section(code_buf, &offset, &size)) {
set_error_buf(error_buf, error_buf_size,
"get text section of ELF failed");
return false;
}
module->code = buf + offset;
module->code = code_buf + offset;
module->code_size -= (uint32)offset;
}
#endif
Expand Down
12 changes: 10 additions & 2 deletions core/iwasm/aot/aot_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ table_instantiate(AOTModuleInstance *module_inst, AOTModule *module,

/* fill table with element segment content */
for (i = 0; i < module->table_init_data_count; i++) {
AOTTableInstance *tbl_inst;

table_seg = module->table_init_data_list[i];

#if WASM_ENABLE_REF_TYPES != 0
Expand Down Expand Up @@ -1404,6 +1402,16 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
uint32 ext_ret_count = result_count > 1 ? result_count - 1 : 0;
bool ret;

if (argc < func_type->param_cell_num) {
char buf[128];
snprintf(buf, sizeof(buf),
"invalid argument count %u, must be no smaller than %u", argc,
func_type->param_cell_num);
aot_set_exception(module_inst, buf);
return false;
}
argc = func_type->param_cell_num;

/* set thread handle and stack boundary */
wasm_exec_env_set_thread_info(exec_env);

Expand Down
4 changes: 2 additions & 2 deletions core/iwasm/common/wasm_shared_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ destroy_wait_info(void *wait_info)
}

static void
release_wait_info(HashMap *wait_map, AtomicWaitInfo *wait_info, void *address)
release_wait_info(HashMap *wait_map_, AtomicWaitInfo *wait_info, void *address)
{
if (wait_info->wait_list->len == 0) {
bh_hash_map_remove(wait_map, address, NULL, NULL);
bh_hash_map_remove(wait_map_, address, NULL, NULL);
destroy_wait_info(wait_info);
}
}
Expand Down
14 changes: 7 additions & 7 deletions core/iwasm/compilation/aot_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,35 +311,35 @@ check_type_compatible(uint8 src_type, uint8 dst_type)
if (!(func_type = \
LLVMFunctionType(ret_type, param_types, argc, false))) { \
aot_set_last_error("llvm add function type failed."); \
return false; \
goto fail; \
} \
if (comp_ctx->is_jit_mode) { \
/* JIT mode, call the function directly */ \
if (!(func_ptr_type = LLVMPointerType(func_type, 0))) { \
aot_set_last_error("llvm add pointer type failed."); \
return false; \
goto fail; \
} \
if (!(value = I64_CONST((uint64)(uintptr_t)name)) \
|| !(func = LLVMConstIntToPtr(value, func_ptr_type))) { \
aot_set_last_error("create LLVM value failed."); \
return false; \
goto fail; \
} \
} \
else if (comp_ctx->is_indirect_mode) { \
int32 func_index; \
if (!(func_ptr_type = LLVMPointerType(func_type, 0))) { \
aot_set_last_error("create LLVM function type failed."); \
return false; \
goto fail; \
} \
\
func_index = aot_get_native_symbol_index(comp_ctx, #name); \
if (func_index < 0) { \
return false; \
goto fail; \
} \
if (!(func = aot_get_func_from_table( \
comp_ctx, func_ctx->native_symbol, func_ptr_type, \
func_index))) { \
return false; \
goto fail; \
} \
} \
else { \
Expand All @@ -349,7 +349,7 @@ check_type_compatible(uint8 src_type, uint8 dst_type)
&& !(func = LLVMAddFunction(comp_ctx->module, func_name, \
func_type))) { \
aot_set_last_error("llvm add function failed."); \
return false; \
goto fail; \
} \
} \
} while (0)
Expand Down
2 changes: 2 additions & 0 deletions core/iwasm/compilation/aot_emit_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ call_aot_free_frame_func(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx)
}

return true;
fail:
return false;
}
#endif /* end of (WASM_ENABLE_DUMP_CALL_STACK != 0) \
|| (WASM_ENABLE_PERF_PROFILING != 0) */
Expand Down
5 changes: 4 additions & 1 deletion core/iwasm/include/wasm_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,10 @@ wasm_runtime_get_module_inst(wasm_exec_env_t exec_env);
* @param exec_env the execution environment to call the function,
* which must be created from wasm_create_exec_env()
* @param function the function to call
* @param argc the number of arguments
* @param argc total cell number that the function parameters occupy,
* a cell is a slot of the uint32 array argv[], e.g. i32/f32 argument
* occupies one cell, i64/f64 argument occupies two cells, note that
* it might be different from the parameter number of the function
* @param argv the arguments. If the function has return value,
* the first (or first two in case 64-bit return value) element of
* argv stores the return value of the called WASM function after this
Expand Down
22 changes: 3 additions & 19 deletions core/iwasm/interpreter/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ wasm_value_type_size(uint8 value_type)
case VALUE_TYPE_V128:
return sizeof(int64) * 2;
#endif
case VALUE_TYPE_VOID:
return 0;
default:
bh_assert(0);
}
Expand All @@ -529,25 +531,7 @@ wasm_value_type_size(uint8 value_type)
inline static uint16
wasm_value_type_cell_num(uint8 value_type)
{
if (value_type == VALUE_TYPE_VOID)
return 0;
else if (value_type == VALUE_TYPE_I32 || value_type == VALUE_TYPE_F32
#if WASM_ENABLE_REF_TYPES != 0
|| value_type == VALUE_TYPE_FUNCREF
|| value_type == VALUE_TYPE_EXTERNREF
#endif
)
return 1;
else if (value_type == VALUE_TYPE_I64 || value_type == VALUE_TYPE_F64)
return 2;
#if WASM_ENABLE_SIMD != 0
else if (value_type == VALUE_TYPE_V128)
return 4;
#endif
else {
bh_assert(0);
}
return 0;
return wasm_value_type_size(value_type) / 4;
}

inline static uint32
Expand Down
82 changes: 43 additions & 39 deletions core/iwasm/interpreter/wasm_interp_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,18 +256,19 @@ read_leb(const uint8 *buf, uint32 *p_offset, uint32 maxbits, bool sign)
--frame_csp; \
} while (0)

#define POP_CSP_N(n) \
do { \
uint32 *frame_sp_old = frame_sp; \
uint32 cell_num = 0; \
POP_CSP_CHECK_OVERFLOW(n + 1); \
frame_csp -= n; \
frame_ip = (frame_csp - 1)->target_addr; \
/* copy arity values of block */ \
frame_sp = (frame_csp - 1)->frame_sp; \
cell_num = (frame_csp - 1)->cell_num; \
word_copy(frame_sp, frame_sp_old - cell_num, cell_num); \
frame_sp += cell_num; \
#define POP_CSP_N(n) \
do { \
uint32 *frame_sp_old = frame_sp; \
uint32 cell_num_to_copy; \
POP_CSP_CHECK_OVERFLOW(n + 1); \
frame_csp -= n; \
frame_ip = (frame_csp - 1)->target_addr; \
/* copy arity values of block */ \
frame_sp = (frame_csp - 1)->frame_sp; \
cell_num_to_copy = (frame_csp - 1)->cell_num; \
word_copy(frame_sp, frame_sp_old - cell_num_to_copy, \
cell_num_to_copy); \
frame_sp += cell_num_to_copy; \
} while (0)

/* Pop the given number of elements from the given frame's stack. */
Expand Down Expand Up @@ -367,11 +368,11 @@ read_leb(const uint8 *buf, uint32 *p_offset, uint32 maxbits, bool sign)
PUSH_##src_op_type(cval); \
} while (0)

#define DEF_OP_EQZ(src_op_type) \
do { \
int32 val; \
val = POP_##src_op_type() == 0; \
PUSH_I32(val); \
#define DEF_OP_EQZ(src_op_type) \
do { \
int32 pop_val; \
pop_val = POP_##src_op_type() == 0; \
PUSH_I32(pop_val); \
} while (0)

#define DEF_OP_CMP(src_type, src_op_type, cond) \
Expand Down Expand Up @@ -434,9 +435,9 @@ read_leb(const uint8 *buf, uint32 *p_offset, uint32 maxbits, bool sign)

#define DEF_OP_MATH(src_type, src_op_type, method) \
do { \
src_type val; \
val = POP_##src_op_type(); \
PUSH_##src_op_type(method(val)); \
src_type src_val; \
src_val = POP_##src_op_type(); \
PUSH_##src_op_type(method(src_val)); \
} while (0)

#define TRUNC_FUNCTION(func_name, src_type, dst_type, signed_type) \
Expand Down Expand Up @@ -1384,22 +1385,22 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,

HANDLE_OP(WASM_OP_TABLE_SET)
{
uint32 tbl_idx, elem_idx, val;
uint32 tbl_idx, elem_idx, elem_val;
WASMTableInstance *tbl_inst;

read_leb_uint32(frame_ip, frame_ip_end, tbl_idx);
bh_assert(tbl_idx < module->table_count);

tbl_inst = wasm_get_table_inst(module, tbl_idx);

val = POP_I32();
elem_val = POP_I32();
elem_idx = POP_I32();
if (elem_idx >= tbl_inst->cur_size) {
wasm_set_exception(module, "out of bounds table access");
goto got_exception;
}

((uint32 *)(tbl_inst->base_addr))[elem_idx] = val;
((uint32 *)(tbl_inst->base_addr))[elem_idx] = elem_val;
HANDLE_OP_END();
}

Expand All @@ -1414,9 +1415,9 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,

HANDLE_OP(WASM_OP_REF_IS_NULL)
{
uint32 val;
val = POP_I32();
PUSH_I32(val == NULL_REF ? 1 : 0);
uint32 ref_val;
ref_val = POP_I32();
PUSH_I32(ref_val == NULL_REF ? 1 : 0);
HANDLE_OP_END();
}

Expand Down Expand Up @@ -2955,16 +2956,16 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
case WASM_OP_MEMORY_FILL:
{
uint32 dst, len;
uint8 val, *mdst;
uint8 fill_val, *mdst;
frame_ip++;

len = POP_I32();
val = POP_I32();
fill_val = POP_I32();
dst = POP_I32();

CHECK_BULK_MEMORY_OVERFLOW(dst, len, mdst);

memset(mdst, val, len);
memset(mdst, fill_val, len);

break;
}
Expand Down Expand Up @@ -3119,7 +3120,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
}
case WASM_OP_TABLE_FILL:
{
uint32 tbl_idx, n, val, i;
uint32 tbl_idx, n, fill_val;
WASMTableInstance *tbl_inst;

read_leb_uint32(frame_ip, frame_ip_end, tbl_idx);
Expand All @@ -3128,7 +3129,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
tbl_inst = wasm_get_table_inst(module, tbl_idx);

n = POP_I32();
val = POP_I32();
fill_val = POP_I32();
i = POP_I32();

/* TODO: what if the element is not passive? */
Expand All @@ -3142,7 +3143,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
}

for (; n != 0; i++, n--) {
((uint32 *)(tbl_inst->base_addr))[i] = val;
((uint32 *)(tbl_inst->base_addr))[i] = fill_val;
}

break;
Expand All @@ -3167,15 +3168,16 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
switch (opcode) {
case WASM_OP_ATOMIC_NOTIFY:
{
uint32 count, ret;
uint32 notify_count, ret;

count = POP_I32();
notify_count = POP_I32();
addr = POP_I32();
CHECK_BULK_MEMORY_OVERFLOW(addr + offset, 4, maddr);
CHECK_ATOMIC_MEMORY_ACCESS();

ret = wasm_runtime_atomic_notify(
(WASMModuleInstanceCommon *)module, maddr, count);
(WASMModuleInstanceCommon *)module, maddr,
notify_count);
bh_assert((int32)ret >= 0);

PUSH_I32(ret);
Expand All @@ -3184,7 +3186,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
case WASM_OP_ATOMIC_WAIT32:
{
uint64 timeout;
uint32 expect, addr, ret;
uint32 expect, ret;

timeout = POP_I64();
expect = POP_I32();
Expand Down Expand Up @@ -3708,13 +3710,15 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst, WASMExecEnv *exec_env,
frame here. */
unsigned frame_size = wasm_interp_interp_frame_size(all_cell_num);

if (argc != function->param_cell_num) {
if (argc < function->param_cell_num) {
char buf[128];
snprintf(buf, sizeof(buf), "invalid argument count %d, expected %d",
argc, function->param_cell_num);
snprintf(buf, sizeof(buf),
"invalid argument count %u, must be no smaller than %u", argc,
function->param_cell_num);
wasm_set_exception(module_inst, buf);
return;
}
argc = function->param_cell_num;

if ((uint8 *)&prev_frame < exec_env->native_stack_boundary) {
wasm_set_exception((WASMModuleInstance *)exec_env->module_inst,
Expand Down
Loading