sched/semaphore: check unmasked pending signals before blocking.#18672
Open
ankohuu wants to merge 1 commit intoapache:masterfrom
Open
sched/semaphore: check unmasked pending signals before blocking.#18672ankohuu wants to merge 1 commit intoapache:masterfrom
ankohuu wants to merge 1 commit intoapache:masterfrom
Conversation
A signal can arrive before sem_wait transitions the task to TSTATE_WAIT_SEM. In that window, the wait cannot yet be aborted by sem_wait_irq(). If sem_wait then blocks without re-checking unmasked pending signals, it can sleep indefinitely and miss the interrupt. Check for unmasked pending signals before touching the semaphore count and return -EINTR if one is already pending. Signed-off-by: Shunchao Hu <ankohuu@gmail.com>
3c04aaf to
8011e36
Compare
acassis
approved these changes
Apr 3, 2026
xiaoxiang781216
approved these changes
Apr 6, 2026
|
|
||
| /* Make sure we were supplied with a valid semaphore. */ | ||
|
|
||
| #ifdef CONFIG_ENABLE_ALL_SIGNALS |
Contributor
There was a problem hiding this comment.
Suggested change
| #ifdef CONFIG_ENABLE_ALL_SIGNALS | |
| #ifndef CONFIG_DISABLE_ALL_SIGNALS |
Contributor
Author
There was a problem hiding this comment.
Thanks Xiang, only change compilation macros may be not enough, right?
https://github.com/apache/nuttx/blob/master/sched/signal/Make.defs#L32-L36
The current implementation bases on your pending signals and aims to handle the case where a signal interrupts during syscall execution.
Contributor
Author
|
Personally, I think similar partial-signal cases should also be handled, but if we try to cover that case, I can’t find a clean way to do it.
I’m not familiar with NuttX. I originally only want to try #16808. Appreciate any guidance on how to approach it properly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A signal can arrive before
sem_waittransitions the task toTSTATE_WAIT_SEM. In that window, the wait cannot yet beaborted by
sem_wait_irq(). Ifsem_waitthen blocks withoutre-checking unmasked pending signals, it can sleep
indefinitely and miss the interrupt.
Check for unmasked pending signals in wait critical section
and return
-EINTRif one is already pending.Overall, the expected semantics are that
sem_wait()shouldnot block if there is already an unmasked pending signal that
should interrupt the wait. This patch enforces that behavior
by checking for unmasked pending signals before the
task can sleep.
Impact
May bugfix not behavior change
Testing
I confirm that the change was built and runtime-tested on a local setup.
Code
Logs before this change
Logs after this change