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
2 changes: 1 addition & 1 deletion core/iwasm/aot/aot_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ invoke_native_with_hw_bound_check(WASMExecEnv *exec_env, void *func_ptr,
uint16 param_count = func_type->param_count;
uint16 result_count = func_type->result_count;
const uint8 *types = func_type->types;
#if BH_PLATFORM_WINDOWS
#ifdef BH_PLATFORM_WINDOWS
const char *exce;
int result;
#endif
Expand Down
16 changes: 15 additions & 1 deletion core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,19 @@ wasm_runtime_destroy_exec_env(WASMExecEnv *exec_env)
bool
wasm_runtime_init_thread_env()
{
#ifdef BH_PLATFORM_WINDOWS
if (os_thread_env_init() != 0)
return false;
#endif

#if WASM_ENABLE_AOT != 0
#ifdef OS_ENABLE_HW_BOUND_CHECK
return aot_signal_init();
if (!aot_signal_init()) {
#ifdef BH_PLATFORM_WINDOWS
os_thread_env_destroy();
#endif
return false;
}
#endif
#endif
return true;
Expand All @@ -839,6 +849,10 @@ wasm_runtime_destroy_thread_env()
aot_signal_destroy();
#endif
#endif

#ifdef BH_PLATFORM_WINDOWS
os_thread_env_destroy();
#endif
}

#if (WASM_ENABLE_MEMORY_PROFILING != 0) || (WASM_ENABLE_MEMORY_TRACING != 0)
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/compilation/aot_compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ read_leb(const uint8 *buf, const uint8 *buf_end,
}
if (sign && (shift < maxbits) && (byte & 0x40)) {
/* Sign extend */
result |= (uint64)(- (((uint64)1) << shift));
result |= (~((uint64)0)) << shift;
}
*p_result = result;
return true;
Expand Down
18 changes: 9 additions & 9 deletions core/iwasm/interpreter/wasm_interp_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ rotl32(uint32 n, uint32 c)
const uint32 mask = (31);
c = c % 32;
c &= mask;
return (n<<c) | (n>>( (-c)&mask ));
return (n << c) | (n >> ((0 - c) & mask));
}

static inline uint32
Expand All @@ -59,7 +59,7 @@ rotr32(uint32 n, uint32 c)
const uint32 mask = (31);
c = c % 32;
c &= mask;
return (n>>c) | (n<<( (-c)&mask ));
return (n >> c) | (n << ((0 - c) & mask));
}

static inline uint64
Expand All @@ -68,7 +68,7 @@ rotl64(uint64 n, uint64 c)
const uint64 mask = (63);
c = c % 64;
c &= mask;
return (n<<c) | (n>>( (-c)&mask ));
return (n << c) | (n >> ((0 - c) & mask));
}

static inline uint64
Expand All @@ -77,7 +77,7 @@ rotr64(uint64 n, uint64 c)
const uint64 mask = (63);
c = c % 64;
c &= mask;
return (n>>c) | (n<<( (-c)&mask ));
return (n >> c) | (n << ((0 - c) & mask));
}

static inline double
Expand Down Expand Up @@ -2623,7 +2623,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
goto out_of_bounds;

bh_memcpy_s(maddr, linear_mem_size - addr,
data + offset, bytes);
data + offset, (uint32)bytes);
break;
}
case WASM_OP_DATA_DROP:
Expand Down Expand Up @@ -2717,9 +2717,9 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
bh_memcpy_s(
(uint8 *)(tbl_inst)
+ offsetof(WASMTableInstance, base_addr) + d * sizeof(uint32),
(tbl_inst->cur_size - d) * sizeof(uint32),
(uint32)((tbl_inst->cur_size - d) * sizeof(uint32)),
module->module->table_segments[elem_idx].func_indexes + s,
n * sizeof(uint32));
(uint32)(n * sizeof(uint32)));

break;
}
Expand Down Expand Up @@ -2764,10 +2764,10 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
bh_memmove_s(
(uint8 *)(dst_tbl_inst) + offsetof(WASMTableInstance, base_addr)
+ d * sizeof(uint32),
(dst_tbl_inst->cur_size - d) * sizeof(uint32),
(uint32)((dst_tbl_inst->cur_size - d) * sizeof(uint32)),
(uint8 *)(src_tbl_inst) + offsetof(WASMTableInstance, base_addr)
+ s * sizeof(uint32),
n * sizeof(uint32));
(uint32)(n * sizeof(uint32)));
break;
}
case WASM_OP_TABLE_GROW:
Expand Down
29 changes: 16 additions & 13 deletions core/iwasm/interpreter/wasm_interp_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ rotl32(uint32 n, uint32 c)
const uint32 mask = (31);
c = c % 32;
c &= mask;
return (n<<c) | (n>>( (-c)&mask ));
return (n << c) | (n >> ((0 - c) & mask));
}

static inline uint32
Expand All @@ -57,7 +57,7 @@ rotr32(uint32 n, uint32 c)
const uint32 mask = (31);
c = c % 32;
c &= mask;
return (n>>c) | (n<<( (-c)&mask ));
return (n >> c) | (n << ((0 - c) & mask));
}

static inline uint64
Expand All @@ -66,7 +66,7 @@ rotl64(uint64 n, uint64 c)
const uint64 mask = (63);
c = c % 64;
c &= mask;
return (n<<c) | (n>>( (-c)&mask ));
return (n << c) | (n >> ((0 - c) & mask));
}

static inline uint64
Expand All @@ -75,7 +75,7 @@ rotr64(uint64 n, uint64 c)
const uint64 mask = (63);
c = c % 64;
c &= mask;
return (n>>c) | (n<<( (-c)&mask ));
return (n >> c) | (n << ((0 - c) & mask));
}

static inline double
Expand Down Expand Up @@ -455,7 +455,8 @@ LOAD_PTR(void *addr)

#define DEF_OP_MATH(src_type, src_op_type, method) do { \
SET_OPERAND(src_op_type, 2, \
method(GET_OPERAND(src_type, src_op_type, 0))); \
(src_type)method(GET_OPERAND(src_type, \
src_op_type, 0))); \
frame_ip += 4; \
} while (0)

Expand Down Expand Up @@ -2229,7 +2230,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
else if (isnan(b))
*(float32*)(frame_lp + GET_OFFSET()) = b;
else
*(float32*)(frame_lp + GET_OFFSET()) = wa_fmin(a, b);
*(float32*)(frame_lp + GET_OFFSET()) = (float32)wa_fmin(a, b);
HANDLE_OP_END ();
}

Expand All @@ -2245,7 +2246,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
else if (isnan(b))
*(float32*)(frame_lp + GET_OFFSET()) = b;
else
*(float32*)(frame_lp + GET_OFFSET()) = wa_fmax(a, b);
*(float32*)(frame_lp + GET_OFFSET()) = (float32)wa_fmax(a, b);
HANDLE_OP_END ();
}

Expand All @@ -2255,7 +2256,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,

b = *(float32*)(frame_lp + GET_OFFSET());
a = *(float32*)(frame_lp + GET_OFFSET());
*(float32*)(frame_lp + GET_OFFSET()) = (signbit(b) ? -fabs(a) : fabs(a));
*(float32*)(frame_lp + GET_OFFSET()) =
(float32)(signbit(b) ? -fabs(a) : fabs(a));
HANDLE_OP_END ();
}

Expand Down Expand Up @@ -2606,7 +2608,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
if (offset + bytes > seg_len)
goto out_of_bounds;

bh_memcpy_s(maddr, linear_mem_size - addr, data + offset, bytes);
bh_memcpy_s(maddr, linear_mem_size - addr,
data + offset, (uint32)bytes);
break;
}
case WASM_OP_DATA_DROP:
Expand Down Expand Up @@ -2695,9 +2698,9 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
bh_memcpy_s(
(uint8 *)tbl_inst + offsetof(WASMTableInstance, base_addr)
+ d * sizeof(uint32),
(tbl_inst->cur_size - d) * sizeof(uint32),
(uint32)((tbl_inst->cur_size - d) * sizeof(uint32)),
module->module->table_segments[elem_idx].func_indexes + s,
n * sizeof(uint32));
(uint32)(n * sizeof(uint32)));
break;
}
case WASM_OP_ELEM_DROP:
Expand Down Expand Up @@ -2740,10 +2743,10 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
bh_memmove_s(
(uint8 *)dst_tbl_inst + offsetof(WASMTableInstance, base_addr)
+ d * sizeof(uint32),
(dst_tbl_inst->cur_size - d) * sizeof(uint32),
(uint32)((dst_tbl_inst->cur_size - d) * sizeof(uint32)),
(uint8 *)src_tbl_inst
+ offsetof(WASMTableInstance, base_addr) + s * sizeof(uint32),
n * sizeof(uint32));
(uint32)(n * sizeof(uint32)));
break;
}
case WASM_OP_TABLE_GROW:
Expand Down
4 changes: 2 additions & 2 deletions core/iwasm/interpreter/wasm_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2485,14 +2485,14 @@ wasm_interp_dump_call_stack(struct WASMExecEnv *exec_env)
/* place holder, will overwrite it in wasm_c_api */
frame.instance = module_inst;
frame.module_offset = 0;
frame.func_index = func_inst - module_inst->functions;
frame.func_index = (uint32)(func_inst - module_inst->functions);

func_code_base = wasm_get_func_code(func_inst);
if (!cur_frame->ip || !func_code_base) {
frame.func_offset = 0;
}
else {
frame.func_offset = cur_frame->ip - func_code_base;
frame.func_offset = (uint32)(cur_frame->ip - func_code_base);
}

/* look for the function name */
Expand Down
15 changes: 14 additions & 1 deletion core/shared/platform/include/platform_api_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,24 @@ int os_thread_detach(korp_tid);
*/
void os_thread_exit(void *retval);

/**
* Initialize current thread environment if current thread
* is created by developer but not runtime
*
* @return 0 if success, -1 otherwise
*/
int os_thread_env_init();

/**
* Destroy current thread environment
*/
void os_thread_env_destroy();

/**
* Suspend execution of the calling thread for (at least)
* usec microseconds
*
* @param return 0 if success, -1 otherwise
* @return 0 if success, -1 otherwise
*/
int os_usleep(uint32 usec);

Expand Down
56 changes: 56 additions & 0 deletions core/shared/platform/windows/win_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,62 @@ os_thread_exit(void *retval)
_endthreadex(0);
}

int
os_thread_env_init()
{
os_thread_data *thread_data = TlsGetValue(thread_data_key);

if (thread_data)
/* Already created */
return BHT_OK;

if (!(thread_data = BH_MALLOC(sizeof(os_thread_data))))
return BHT_ERROR;

memset(thread_data, 0, sizeof(os_thread_data));
thread_data->thread_id = GetCurrentThreadId();

if (os_sem_init(&thread_data->wait_node.sem) != BHT_OK)
goto fail1;

if (os_mutex_init(&thread_data->wait_lock) != BHT_OK)
goto fail2;

if (os_cond_init(&thread_data->wait_cond) != BHT_OK)
goto fail3;

if (!TlsSetValue(thread_data_key, thread_data))
goto fail4;

return BHT_OK;

fail4:
os_cond_destroy(&thread_data->wait_cond);
fail3:
os_mutex_destroy(&thread_data->wait_lock);
fail2:
os_sem_destroy(&thread_data->wait_node.sem);
fail1:
BH_FREE(thread_data);
return BHT_ERROR;
}

void
os_thread_env_destroy()
{
os_thread_data *thread_data = TlsGetValue(thread_data_key);

/* Note that supervisor_thread_data's resources will be destroyed
by os_thread_sys_destroy() */
if (thread_data && thread_data != &supervisor_thread_data) {
TlsSetValue(thread_data_key, NULL);
os_cond_destroy(&thread_data->wait_cond);
os_mutex_destroy(&thread_data->wait_lock);
os_sem_destroy(&thread_data->wait_node.sem);
BH_FREE(thread_data);
}
}

int
os_sem_init(korp_sem *sem)
{
Expand Down
1 change: 1 addition & 0 deletions product-mini/platforms/alios-things/aos.mk
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ $(NAME)_SOURCES := ${SHARED_ROOT}/platform/alios/alios_platform.c \
${IWASM_ROOT}/common/wasm_native.c \
${IWASM_ROOT}/common/wasm_exec_env.c \
${IWASM_ROOT}/common/wasm_memory.c \
${IWASM_ROOT}/common/wasm_c_api.c \
${IWASM_ROOT}/common/arch/${INVOKE_NATIVE} \
src/main.c

Expand Down