From f2dee1433c21ffa3ded4521d28b3418e28560085 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 11 Mar 2026 11:21:05 -1000 Subject: [PATCH] Place backtrace_count before array for forward compatibility Moving backtrace_count before the variable-length backtrace array ensures magic, pc, and count are at fixed offsets regardless of MAX_BACKTRACE value. This makes the .noinit data readable across firmware versions that may change the max backtrace depth. Co-Authored-By: J. Nick Koston --- esphome/components/esp32/crash_handler.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/esphome/components/esp32/crash_handler.cpp b/esphome/components/esp32/crash_handler.cpp index efedb42889f..53ce16e11c9 100644 --- a/esphome/components/esp32/crash_handler.cpp +++ b/esphome/components/esp32/crash_handler.cpp @@ -28,11 +28,13 @@ static inline bool IRAM_ATTR is_code_addr(uint32_t addr) { // Raw crash data written by the panic handler wrapper. // Lives in .noinit so it survives software reset but contains garbage after power cycle. // Validated by magic marker. Static linkage since it's only used within this file. +// Field order matters: magic, pc, and backtrace_count are at fixed offsets +// so the struct remains readable even if MAX_BACKTRACE changes between versions. struct RawCrashData { uint32_t magic; uint32_t pc; - uint32_t backtrace[MAX_BACKTRACE]; uint8_t backtrace_count; + uint32_t backtrace[MAX_BACKTRACE]; }; static RawCrashData __attribute__((section(".noinit"))) s_raw_crash_data;