Skip to content

Commit

Permalink
core: Treat stack overflows as an unrecoverable error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nmeum committed Aug 12, 2022
1 parent 4ab7ba6 commit 0dade34
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/lib/include/panic.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef enum {
PANIC_DUMMY_HANDLER, /**< unhandled interrupt */
#endif
PANIC_SSP, /**< stack smashing protector failure */
PANIC_STACK_OVERFLOW, /**< stack overflow detect */
PANIC_UNDEFINED
} core_panic_t;

Expand Down
4 changes: 3 additions & 1 deletion core/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "irq.h"
#include "thread.h"
#include "log.h"
#include "panic.h"

#ifdef MODULE_MPU_STACK_GUARD
#include "mpu.h"
Expand Down Expand Up @@ -127,9 +128,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
Expand Down

0 comments on commit 0dade34

Please sign in to comment.