Implement async termination of blocking thread (#2516)

Send a signal whose handler is no-op to a blocking thread to wake up
the blocking syscall with either EINTR equivalent or partial success.

Unlike the approach taken in the `dev/interrupt_block_insn` branch (that is,
signal + longjmp similarly to `OS_ENABLE_HW_BOUND_CHECK`), this PR
does not use longjmp because:
* longjmp from signal handler doesn't work on nuttx
  refer to https://github.com/apache/nuttx/issues/10326
* the singal+longjmp approach may be too difficult for average programmers
  who might implement host functions to deal with

See also https://github.com/bytecodealliance/wasm-micro-runtime/issues/1910
This commit is contained in:
YAMAMOTO Takashi
2023-09-20 19:11:52 +09:00
committed by GitHub
parent d436e846ab
commit 444b159963
21 changed files with 1029 additions and 302 deletions

View File

@ -323,6 +323,34 @@ os_sem_getvalue(korp_sem *sem, int *sval);
int
os_sem_unlink(const char *name);
/**
* Initialize process-global state for os_wakeup_blocking_op.
*/
int
os_blocking_op_init();
/**
* Start accepting os_wakeup_blocking_op requests for the calling thread.
*/
void
os_begin_blocking_op();
/**
* Stop accepting os_wakeup_blocking_op requests for the calling thread.
*/
void
os_end_blocking_op();
/**
* Wake up the specified thread.
*
* For example, on posix-like platforms, this can be implemented by
* sending a signal (w/o SA_RESTART) which interrupts a blocking
* system call.
*/
int
os_wakeup_blocking_op(korp_tid tid);
/****************************************************
* Section 2 *
* Socket support *