From 80116651c23c3d9776a59960c5e333f46a6562af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Fri, 12 Aug 2022 05:26:22 +0200 Subject: [PATCH] core: Treat stack overflows as an unrecoverable error Presently, RIOT just emits a warning when a stack overflow is encountered but still resumes execution. In my view, execution should be aborted as the detection of a stack overflows via the heuristic provided by the scheduler is an unrecoverable error. I ran into this while performing automated tests of a RIOT application where a stack overflow occurred but I only noticed this after inspecting the application output more closely. Similar to SSP failures, I added crash_code for stack overflows. --- core/lib/include/panic.h | 1 + core/sched.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/core/lib/include/panic.h b/core/lib/include/panic.h index e536dd5622..51854b5160 100644 --- a/core/lib/include/panic.h +++ b/core/lib/include/panic.h @@ -51,6 +51,7 @@ typedef enum { PANIC_DUMMY_HANDLER, /**< unhandled interrupt */ #endif PANIC_SSP, /**< stack smashing protector failure */ + PANIC_STACK_OVERFLOW, /**< stack overflow detected */ PANIC_UNDEFINED } core_panic_t; diff --git a/core/sched.c b/core/sched.c index e99272dc11..236c58e764 100644 --- a/core/sched.c +++ b/core/sched.c @@ -30,6 +30,7 @@ #include "log.h" #include "sched.h" #include "thread.h" +#include "panic.h" #ifdef MODULE_MPU_STACK_GUARD #include "mpu.h" @@ -130,9 +131,10 @@ static void _unschedule(thread_t *active_thread) */ if (*((uintptr_t *)(uintptr_t)active_thread->stack_start) != (uintptr_t)active_thread->stack_start) { - LOG_WARNING( + LOG_ERROR( "scheduler(): stack overflow detected, pid=%" PRIkernel_pid "\n", active_thread->pid); + core_panic(PANIC_STACK_OVERFLOW, "STACK OVERFLOW"); } #endif #ifdef MODULE_SCHED_CB