From 571ab51aa5fe6b3b8e394a79109a8f9d8967230c Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Thu, 29 Aug 2024 15:32:37 +0800 Subject: [PATCH] fix(system): fixed potential double exception when booting on xtensa Due to old windows from the startup flow being present after switching to running freertos tasks windowoverflow exceptions could potentially try to save windows to the startup stack. During this overflow they also values previously saved on the startup stack to find earlier frames' stacks. Since the start up stack was already recycled these values were invalid and would cause a crash. Closes https://github.com/espressif/esp-idf/issues/14406Y --- .../freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c | 5 +++++ components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c b/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c index b8eefa5f08..2ed1e3f139 100644 --- a/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c +++ b/components/freertos/FreeRTOS-Kernel-SMP/portable/xtensa/port.c @@ -344,6 +344,11 @@ BaseType_t xPortStartScheduler( void ) } #endif // configNUM_CORES > 1 + // Windows contain references to the startup stack which will be reclaimed by the main task + // Spill the windows to create a clean environment to ensure we do not carry over any such references + // to invalid SPs which will cause problems if main_task does a windowoverflow to them + xthal_window_spill(); + // Cannot be directly called from C; never returns __asm__ volatile ("call0 _frxt_dispatch\n"); diff --git a/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c b/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c index b35b71ac12..2b5f5aadb0 100644 --- a/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c +++ b/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c @@ -108,6 +108,11 @@ BaseType_t xPortStartScheduler( void ) port_xSchedulerRunning[xPortGetCoreID()] = 1; + // Windows contain references to the startup stack which will be reclaimed by the main task + // Spill the windows to create a clean environment to ensure we do not carry over any such references + // to invalid SPs which will cause problems if main_task does a windowoverflow to them + xthal_window_spill(); + // Cannot be directly called from C; never returns __asm__ volatile ("call0 _frxt_dispatch\n");