From 5b2033af516cc24b115e4353b09ded36d9d9fc70 Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Mon, 12 Oct 2026 18:33:06 +0200 Subject: [PATCH] libs/libc/stdlib: Raise SIGABRT in abort(). abort() called _exit() at once: a handler of SIGABRT never ran, and the comment above the function, which describes the POSIX behavior, was not true. With CONFIG_ENABLE_ALL_SIGNALS, unblock and raise SIGABRT. If a handler returns, or SIGABRT is ignored, restore the default action and raise it again. _exit() stays as the last step. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli --- libs/libc/stdlib/lib_abort.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/libs/libc/stdlib/lib_abort.c b/libs/libc/stdlib/lib_abort.c index 4f41a2ec8acc6..b74eae539fb17 100644 --- a/libs/libc/stdlib/lib_abort.c +++ b/libs/libc/stdlib/lib_abort.c @@ -26,8 +26,11 @@ #include +#include #include +#include #include +#include /**************************************************************************** * Public Functions @@ -60,12 +63,29 @@ void abort(void) { - /* NuttX does not support standard signal functionality (like the - * behavior of the SIGABRT signal). So no attempt is made to provide - * a conformant version of abort() at this time. This version does not - * signal the calling thread all. - * - * _exit() will close all open files and terminate the thread. +#ifdef CONFIG_ENABLE_ALL_SIGNALS + struct sigaction act; + sigset_t set; + + /* Unblock SIGABRT and raise it: a handler can catch it */ + + sigemptyset(&set); + sigaddset(&set, SIGABRT); + sigprocmask(SIG_UNBLOCK, &set, NULL); + raise(SIGABRT); + + /* The handler returned, or SIGABRT is ignored: restore the default + * action and raise SIGABRT again. + */ + + memset(&act, 0, sizeof(act)); + act.sa_handler = SIG_DFL; + sigaction(SIGABRT, &act, NULL); + raise(SIGABRT); +#endif + + /* SIGABRT has no default action, or signals are not enabled. _exit() + * closes all open files and terminates the process. */ _exit(EXIT_FAILURE);