This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 3c9a9d683f2 include/errno.h: skip set_errno in interrupt context
3c9a9d683f2 is described below
commit 3c9a9d683f2291ce88af2fa04382fe15a8b37932
Author: shichunma <[email protected]>
AuthorDate: Sun May 3 08:51:59 2026 +0800
include/errno.h: skip set_errno in interrupt context
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 <[email protected]>
---
include/errno.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/include/errno.h b/include/errno.h
index 615ebc818a0..1be44998831 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -29,6 +29,10 @@
#include <nuttx/compiler.h>
+#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
+# include <nuttx/irq.h>
+#endif
+
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -41,12 +45,24 @@
*/
#define errno *__errno()
+#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__)
+#define set_errno(e) \
+ do \
+ { \
+ if (!up_interrupt_context()) \
+ { \
+ errno = (int)(e); \
+ } \
+ } \
+ while (0)
+#else
#define set_errno(e) \
do \
{ \
errno = (int)(e); \
} \
while (0)
+#endif
#define get_errno() errno
/* Definitions of error numbers and the string that would be