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

@ -246,6 +246,7 @@ ifeq ($(CONFIG_INTERPRETERS_WAMR_LIBC_WASI),y)
CFLAGS += -DWASM_ENABLE_LIBC_WASI=1
CFLAGS += -I$(IWASM_ROOT)/libraries/libc-wasi/sandboxed-system-primitives/src
CFLAGS += -I$(IWASM_ROOT)/libraries/libc-wasi/sandboxed-system-primitives/include
CSRCS += blocking_op.c
CSRCS += posix_socket.c
CSRCS += libc_wasi_wrapper.c
VPATH += $(IWASM_ROOT)/libraries/libc-wasi
@ -309,6 +310,9 @@ CFLAGS += -DWASM_DISABLE_HW_BOUND_CHECK=0
CFLAGS += -DWASM_DISABLE_STACK_HW_BOUND_CHECK=0
endif
# REVISIT: is this worth to have a Kconfig?
CFLAGS += -DWASM_DISABLE_WAKEUP_BLOCKING_OP=0
ifeq ($(CONFIG_INTERPRETERS_WAMR_CUSTOM_NAME_SECTIONS),y)
CFLAGS += -DWASM_ENABLE_CUSTOM_NAME_SECTION=1
else
@ -354,8 +358,10 @@ CFLAGS += -I$(IWASM_ROOT)/interpreter
endif
CSRCS += nuttx_platform.c \
posix_blocking_op.c \
posix_thread.c \
posix_time.c \
posix_sleep.c \
mem_alloc.c \
ems_kfc.c \
ems_alloc.c \
@ -370,6 +376,7 @@ CSRCS += nuttx_platform.c \
bh_read_file.c \
runtime_timer.c \
wasm_application.c \
wasm_blocking_op.c \
wasm_runtime_common.c \
wasm_native.c \
wasm_exec_env.c \