Skip to content

Commit f6ef4e7

Browse files
committed
fix(wasi-threads): fix platform includes
1 parent 3c2f060 commit f6ef4e7

File tree

11 files changed

+77
-39
lines changed

11 files changed

+77
-39
lines changed

core/iwasm/aot/aot_runtime.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,15 +1391,22 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
13911391
#ifdef OS_ENABLE_BLOCK_INSN_INTERRUPT
13921392
wasm_exec_env_push_jmpbuf(exec_env, &jmpbuf_node);
13931393
wasm_runtime_set_exec_env_tls(exec_env);
1394-
if (os_setjmp(jmpbuf_node.jmpbuf) == 0)
1394+
if (os_setjmp(jmpbuf_node.jmpbuf) == 0) {
13951395
#endif
13961396
ret = invoke_native_internal(exec_env, function->u.func.func_ptr,
13971397
func_type, NULL, NULL, argv1, argc,
13981398
argv);
13991399
#ifdef OS_ENABLE_BLOCK_INSN_INTERRUPT
1400+
}
1401+
else {
1402+
ret = false;
1403+
}
14001404

14011405
jmpbuf_node_pop = wasm_exec_env_pop_jmpbuf(exec_env);
14021406
bh_assert(&jmpbuf_node == jmpbuf_node_pop);
1407+
if (!exec_env->jmpbuf_stack_top) {
1408+
wasm_runtime_set_exec_env_tls(NULL);
1409+
}
14031410
#endif
14041411

14051412
#if WASM_ENABLE_DUMP_CALL_STACK != 0
@@ -1461,15 +1468,22 @@ aot_call_function(WASMExecEnv *exec_env, AOTFunctionInstance *function,
14611468
#ifdef OS_ENABLE_BLOCK_INSN_INTERRUPT
14621469
wasm_exec_env_push_jmpbuf(exec_env, &jmpbuf_node);
14631470
wasm_runtime_set_exec_env_tls(exec_env);
1464-
if (os_setjmp(jmpbuf_node.jmpbuf) == 0)
1471+
if (os_setjmp(jmpbuf_node.jmpbuf) == 0) {
14651472
#endif
14661473
ret =
14671474
invoke_native_internal(exec_env, function->u.func.func_ptr,
14681475
func_type, NULL, NULL, argv, argc, argv);
14691476
#ifdef OS_ENABLE_BLOCK_INSN_INTERRUPT
1477+
}
1478+
else {
1479+
ret = false;
1480+
}
14701481

14711482
jmpbuf_node_pop = wasm_exec_env_pop_jmpbuf(exec_env);
14721483
bh_assert(&jmpbuf_node == jmpbuf_node_pop);
1484+
if (!exec_env->jmpbuf_stack_top) {
1485+
wasm_runtime_set_exec_env_tls(NULL);
1486+
}
14731487
#endif
14741488

14751489
#if WASM_ENABLE_DUMP_CALL_STACK != 0

core/iwasm/common/wasm_runtime_common.c

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ wasm_runtime_get_exec_env_tls()
323323

324324
#ifdef OS_ENABLE_BLOCK_INSN_INTERRUPT
325325
static void
326-
os_interrupt_block_insn_sig_handler(int sig)
326+
interrupt_block_insn_sig_handler(int sig)
327327
{
328328
bh_assert(sig == SIGUSR1);
329329

@@ -332,22 +332,7 @@ os_interrupt_block_insn_sig_handler(int sig)
332332

333333
os_longjmp(jmpbuf_node->jmpbuf, 1);
334334
}
335-
336-
bool
337-
os_interrupt_block_insn_init()
338-
{
339-
struct sigaction act;
340-
memset(&act, 0, sizeof(act));
341-
act.sa_handler = os_interrupt_block_insn_sig_handler;
342-
sigfillset(&act.sa_mask);
343-
if (sigaction(SIGUSR1, &act, NULL) < 0) {
344-
LOG_ERROR("failed to set signal handler");
345-
return false;
346-
}
347-
348-
return true;
349-
}
350-
#endif
335+
#endif /* OS_ENABLE_BLOCK_INSN_INTERRUPT */
351336

352337
static bool
353338
wasm_runtime_env_init()
@@ -381,8 +366,8 @@ wasm_runtime_env_init()
381366
}
382367
#endif
383368
#ifdef OS_ENABLE_BLOCK_INSN_INTERRUPT
384-
if (!os_interrupt_block_insn_init()) {
385-
goto fail5;
369+
if (!os_interrupt_block_insn_init(interrupt_block_insn_sig_handler)) {
370+
goto fail6;
386371
}
387372
#endif
388373
#ifdef OS_ENABLE_HW_BOUND_CHECK
@@ -440,7 +425,7 @@ wasm_runtime_env_init()
440425
fail7:
441426
#endif
442427
#endif
443-
#ifdef OS_ENABLE_HW_BOUND_CHECK
428+
#if defined(OS_ENABLE_HW_BOUND_CHECK) || defined(OS_ENABLE_BLOCK_INSN_INTERRUPT)
444429
runtime_signal_destroy();
445430
fail6:
446431
#endif

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2147,13 +2147,17 @@ wasm_call_function(WASMExecEnv *exec_env, WASMFunctionInstance *function,
21472147
#ifdef OS_ENABLE_BLOCK_INSN_INTERRUPT
21482148
wasm_exec_env_push_jmpbuf(exec_env, &jmpbuf_node);
21492149
wasm_runtime_set_exec_env_tls(exec_env);
2150-
if (os_setjmp(jmpbuf_node.jmpbuf) == 0)
2150+
if (os_setjmp(jmpbuf_node.jmpbuf) == 0) {
21512151
#endif
21522152
interp_call_wasm(module_inst, exec_env, function, argc, argv);
21532153
#ifdef OS_ENABLE_BLOCK_INSN_INTERRUPT
2154+
}
21542155

21552156
jmpbuf_node_pop = wasm_exec_env_pop_jmpbuf(exec_env);
21562157
bh_assert(&jmpbuf_node == jmpbuf_node_pop);
2158+
if (!exec_env->jmpbuf_stack_top) {
2159+
wasm_runtime_set_exec_env_tls(NULL);
2160+
}
21572161
#endif
21582162

21592163
return !wasm_get_exception(module_inst) ? true : false;

core/iwasm/libraries/thread-mgr/thread_manager.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,8 +1065,10 @@ set_exception_visitor(void *node, void *user_data)
10651065
sizeof(curr_wasm_inst->cur_exception),
10661066
wasm_inst->cur_exception, sizeof(wasm_inst->cur_exception));
10671067

1068+
#ifdef OS_ENABLE_BLOCK_INSN_INTERRUPT
10681069
bh_assert(curr_exec_env->handle);
10691070
os_thread_signal(curr_exec_env->handle, SIGUSR1);
1071+
#endif
10701072

10711073
/* Terminate the thread so it can exit from dead loops */
10721074
set_thread_cancel_flags(curr_exec_env);

core/shared/platform/android/platform_internal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ typedef sem_t korp_sem;
6363

6464
#define bh_socket_t int
6565

66-
#if WASM_DISABLE_BLOCK_INSN_INTERRUPT == 0
66+
#if WASM_DISABLE_BLOCK_INSN_INTERRUPT == 0 && WASM_ENABLE_THREAD_MGR != 0
6767
#define OS_ENABLE_BLOCK_INSN_INTERRUPT
68+
69+
typedef void (*os_block_insn_sig_handler)(int sig);
70+
bool
71+
os_interrupt_block_insn_init(os_block_insn_sig_handler handler);
6872
#endif
6973

7074
#if WASM_DISABLE_HW_BOUND_CHECK == 0

core/shared/platform/common/posix/posix_thread.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,23 @@ os_thread_get_stack_boundary()
420420
return addr;
421421
}
422422

423+
#ifdef OS_ENABLE_BLOCK_INSN_INTERRUPT
424+
bool
425+
os_interrupt_block_insn_init(os_block_insn_sig_handler handler)
426+
{
427+
struct sigaction act;
428+
memset(&act, 0, sizeof(act));
429+
act.sa_handler = handler;
430+
sigfillset(&act.sa_mask);
431+
if (sigaction(SIGUSR1, &act, NULL) < 0) {
432+
os_printf("failed to set signal handler\n");
433+
return false;
434+
}
435+
436+
return true;
437+
}
438+
#endif /* OS_ENABLE_BLOCK_INSN_INTERRUPT */
439+
423440
#ifdef OS_ENABLE_HW_BOUND_CHECK
424441

425442
#define SIG_ALT_STACK_SIZE (32 * 1024)

core/shared/platform/darwin/platform_internal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ typedef sem_t korp_sem;
6868

6969
#if WASM_DISABLE_BLOCK_INSN_INTERRUPT == 0
7070
#define OS_ENABLE_BLOCK_INSN_INTERRUPT
71-
#endif
71+
72+
typedef void (*os_block_insn_sig_handler)(int sig);
73+
bool
74+
os_interrupt_block_insn_init(os_block_insn_sig_handler handler);
75+
#endif /* WASM_DISABLE_BLOCK_INSN_INTERRUPT */
7276

7377
#if WASM_DISABLE_HW_BOUND_CHECK == 0
7478
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \

core/shared/platform/freebsd/platform_internal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ typedef sem_t korp_sem;
6767

6868
#if WASM_DISABLE_BLOCK_INSN_INTERRUPT == 0
6969
#define OS_ENABLE_BLOCK_INSN_INTERRUPT
70-
#endif
70+
71+
typedef void (*os_block_insn_sig_handler)(int sig);
72+
bool
73+
os_interrupt_block_insn_init(os_block_insn_sig_handler handler);
74+
#endif /* WASM_DISABLE_BLOCK_INSN_INTERRUPT */
7175

7276
#if WASM_DISABLE_HW_BOUND_CHECK == 0
7377
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \

core/shared/platform/linux/platform_internal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ typedef sem_t korp_sem;
6565

6666
#if WASM_DISABLE_BLOCK_INSN_INTERRUPT == 0
6767
#define OS_ENABLE_BLOCK_INSN_INTERRUPT
68-
#endif
68+
69+
typedef void (*os_block_insn_sig_handler)(int sig);
70+
bool
71+
os_interrupt_block_insn_init(os_block_insn_sig_handler handler);
72+
#endif /* WASM_DISABLE_BLOCK_INSN_INTERRUPT */
6973

7074
#if WASM_DISABLE_HW_BOUND_CHECK == 0
7175
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \

core/shared/platform/vxworks/platform_internal.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ typedef sem_t korp_sem;
6262

6363
#if WASM_DISABLE_BLOCK_INSN_INTERRUPT == 0
6464
#define OS_ENABLE_BLOCK_INSN_INTERRUPT
65-
#endif
65+
66+
typedef void (*os_block_insn_sig_handler)(int sig);
67+
bool
68+
os_interrupt_block_insn_init(os_block_insn_sig_handler handler);
69+
#endif /* WASM_DISABLE_BLOCK_INSN_INTERRUPT */
6670

6771
#if WASM_DISABLE_HW_BOUND_CHECK == 0
6872
#if defined(BUILD_TARGET_X86_64) || defined(BUILD_TARGET_AMD_64) \

0 commit comments

Comments
 (0)