Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signal handler is called within "kernel" #10326

Open
yamt opened this issue Aug 21, 2023 · 0 comments
Open

signal handler is called within "kernel" #10326

yamt opened this issue Aug 21, 2023 · 0 comments

Comments

@yamt
Copy link
Contributor

yamt commented Aug 21, 2023

nuttx, at least w/o CONFIG_LIB_SYSCALL, calls user-specified signal hander within the "kernel" part of the code directly.
it isn't safe because user handler can call system calls.

in the extreme case, the user handler escapes with a longjmp. it likely crashes the kernel later.
unfortunately it's somehow common for apps for posix environment to use longjmp within a signal handler.

while CONFIG_LIB_SYSCALL seems to defer signal delivery as expected (i haven't tested this. just glancing the code)
it isn't always desirable because:

  • it has considerable overhead like linking otherwise unused system calls
  • you need to write arch-dependent code (eg. sim doesn't have an implementation right now)

i guess a lighter-weight fix is nicer to have. eg. making every syscall-type functions call, say,enter_kernel/leave_kernel.

wenyongh pushed a commit to bytecodealliance/wasm-micro-runtime that referenced this issue Sep 20, 2023
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 apache/nuttx#10326
* the singal+longjmp approach may be too difficult for average programmers
  who might implement host functions to deal with

See also #1910
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this issue May 27, 2024
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 apache/nuttx#10326
* the singal+longjmp approach may be too difficult for average programmers
  who might implement host functions to deal with

See also bytecodealliance#1910
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant