diff --git a/scripts/fuzz.sh b/scripts/fuzz.sh index 18bcbbe6a01f..0ca35a77b806 100755 --- a/scripts/fuzz.sh +++ b/scripts/fuzz.sh @@ -97,6 +97,8 @@ main() local fuzz_configs=( -DCONFIG_ZEPHYR_POSIX=y -DCONFIG_ASSERT=y + -DCONFIG_EXCEPTION_DEBUG=y + -DCONFIG_ARCH_POSIX_TRAP_ON_FATAL=y -DCONFIG_SYS_HEAP_BIG_ONLY=y -DCONFIG_ZEPHYR_NATIVE_DRIVERS=y -DCONFIG_ARCH_POSIX_LIBFUZZER=y diff --git a/zephyr/wrapper.c b/zephyr/wrapper.c index e2fed0558a43..27e9a16c5b73 100644 --- a/zephyr/wrapper.c +++ b/zephyr/wrapper.c @@ -326,14 +326,32 @@ int poll_for_register_delay(uint32_t reg, uint32_t mask, return 0; } +/* Mutable, volatile and not static to escape optimizers and static + * analyzers. + */ +volatile int *_sof_fatal_null = NULL; + void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *esf) { ARG_UNUSED(esf); + + /* flush and switch to immediate mode */ LOG_PANIC(); ipc_send_panic_notification(); +#if defined(CONFIG_ARCH_POSIX) || defined(CONFIG_ZEPHYR_POSIX) + LOG_ERR("Halting emulation"); + + /* In emulation we want to stop _immediately_ and print a useful stack + * trace; not a useless pointer to some signal handler or Zephyr + * cleanup routine. See Zephyr POSIX limitations discussed in: + * https://github.com/zephyrproject-rtos/zephyr/pull/68494 + */ + *_sof_fatal_null = 42; +#else LOG_ERR("Halting system"); +#endif k_fatal_halt(reason); }