diff --git a/libraries/AP_InternalError/AP_InternalError.cpp b/libraries/AP_InternalError/AP_InternalError.cpp index d881f16de9..30544296fb 100644 --- a/libraries/AP_InternalError/AP_InternalError.cpp +++ b/libraries/AP_InternalError/AP_InternalError.cpp @@ -1,6 +1,7 @@ #include "AP_InternalError.h" #include +#include extern const AP_HAL::HAL &hal; @@ -56,6 +57,7 @@ void AP_InternalError::errors_as_string(uint8_t *buffer, const uint16_t len) con "stack_ovrflw", // stack_overflow "imu_reset", // imu_reset "gpio_isr", + "mem_guard", }; static_assert((1U<<(ARRAY_SIZE(error_bit_descriptions))) == uint32_t(AP_InternalError::error_t::__LAST__), "too few descriptions for bits"); @@ -110,3 +112,13 @@ void AP_stack_overflow(const char *thread_name) AP_HAL::panic("stack overflow %s\n", thread_name); } } + +// hook for memory guard errors with --enable-memory-guard +void AP_memory_guard_error(uint32_t size) +{ + INTERNAL_ERROR(AP_InternalError::error_t::mem_guard); + if (!hal.util->get_soft_armed()) { + ::printf("memory guard error size=%u\n", unsigned(size)); + AP_HAL::panic("memory guard size=%u\n", unsigned(size)); + } +} diff --git a/libraries/AP_InternalError/AP_InternalError.h b/libraries/AP_InternalError/AP_InternalError.h index 9435039b67..8a810f2a0a 100644 --- a/libraries/AP_InternalError/AP_InternalError.h +++ b/libraries/AP_InternalError/AP_InternalError.h @@ -63,7 +63,8 @@ public: stack_overflow = (1U << 23), //0x800000 8388608 imu_reset = (1U << 24), //0x1000000 16777216 gpio_isr = (1U << 25), //0x2000000 33554432 - __LAST__ = (1U << 26), // used only for sanity check + mem_guard = (1U << 26), //0x4000000 67108864 + __LAST__ = (1U << 27), // used only for sanity check }; // if you've changed __LAST__ to be 32, then you will want to @@ -101,6 +102,7 @@ namespace AP { extern "C" { void AP_stack_overflow(const char *thread_name); + void AP_memory_guard_error(uint32_t size); } #define INTERNAL_ERROR(error_number) \