From 203e964b2c592c5f5b09916503da29f860e32193 Mon Sep 17 00:00:00 2001 From: shichunma Date: Sun, 3 May 2026 08:51:59 +0800 Subject: [PATCH] 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 --- include/errno.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/errno.h b/include/errno.h index 615ebc818a0a2..1be449988313d 100644 --- a/include/errno.h +++ b/include/errno.h @@ -29,6 +29,10 @@ #include +#if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) +# include +#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