From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] common: panic: add new CONFIG_PANIC_TRAP option
Date: Thu, 21 Aug 2025 23:00:10 +0200 [thread overview]
Message-ID: <20250821210010.1435851-1-a.fatoum@pengutronix.de> (raw)
When running under libfuzzer for example, it's better to trap, so
libfuzzer generates a crash input file than to just print an error
message and exit gracefully.
The same can apply when running under a hardware debugger, so make
this option available generally.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/Kconfig | 9 +++++++++
common/misc.c | 2 ++
2 files changed, 11 insertions(+)
diff --git a/common/Kconfig b/common/Kconfig
index ad211d1fa519..0664ffcb43a5 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -376,6 +376,7 @@ config RELOCATABLE
choice
prompt "Configure action on fatal error"
+ default PANIC_TRAP if SANDBOX
default PANIC_RESET
config PANIC_POWEROFF
@@ -407,6 +408,14 @@ choice
fatal error, so you don't have to reset it manually.
This is the recommended configuration in production.
+ config PANIC_TRAP
+ bool "invoke a trap instruction"
+ help
+ This option triggers the trap instruction emitted by
+ __builtin_trap() on fatal errors.
+ This is mainly useful when running under a debugger
+ or debugging instrumentation.
+
endchoice
config PROMPT
diff --git a/common/misc.c b/common/misc.c
index f2c084a0df4b..67f88af1a3df 100644
--- a/common/misc.c
+++ b/common/misc.c
@@ -305,6 +305,8 @@ static void __noreturn do_panic(bool stacktrace, const char *fmt, va_list ap)
if (IS_ENABLED(CONFIG_PANIC_POWEROFF))
poweroff_machine(0);
+ else if (IS_ENABLED(CONFIG_PANIC_TRAP))
+ __builtin_trap();
else
restart_machine(0);
}
--
2.39.5
reply other threads:[~2025-08-22 2:25 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250821210010.1435851-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox