* [PATCH] common: panic: add new CONFIG_PANIC_TRAP option
@ 2025-08-21 21:00 Ahmad Fatoum
0 siblings, 0 replies; only message in thread
From: Ahmad Fatoum @ 2025-08-21 21:00 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-08-22 2:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-21 21:00 [PATCH] common: panic: add new CONFIG_PANIC_TRAP option Ahmad Fatoum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox