include/errno.h: skip set_errno in interrupt context#18839
Merged
Conversation
Contributor
|
Do we need to add an ASSERT and fix already? |
set_errno() should not modify the interrupted task's errno. Add a check using up_interrupt_context() and skip the assignment when called from an interrupt handler. Signed-off-by: Jerry Ma <shichunma@bestechnic.com>
masc2008
commented
May 3, 2026
Contributor
Author
masc2008
left a comment
There was a problem hiding this comment.
fixed compile error.
Contributor
Author
some person may have already called some libc function like in interrupt context, it's not a good practice. But I don't think it's good to do such break change. let's start from a small step. |
acassis
approved these changes
May 3, 2026
Contributor
|
Just an FYI, since we are moving to 13.0.0 next, this would be a good time for the breaking change of adding an assertion. |
xiaoxiang781216
approved these changes
May 3, 2026
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
errnois defined as a per-thread value. Whenset_errno()is called from an interrupt handler, it currently modifies the interrupted task'serrno, which violates POSIX semantics because the interrupted task did not request the failing operation.up_interrupt_context()guard inside theset_errno()macro so that the assignment is skipped when running in an interrupt handler.<nuttx/irq.h>and wrap theerrno = (int)(e)assignment withif (!up_interrupt_context()).Impact
Testing
I confirm that changes are verified on local setup and works as intended:
Testing logs after change:
there is no log when do it, I tested this under qemu-armv7a and BES chip.