malloc: Add a Kconfig option for heap protection

Add CONFIG_MCHECK_HEAP_PROTECTION option to enable mcheck heap
protection. Convert all uses of MCHECK_HEAP_PROTECTION to use the
CONFIG_ -prefixed version to work with Kconfig.

Disable this option when tracing is enabled, since the mcheck hooks (mcheck_pedantic_prehook(), etc.) interfere with function tracing.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
Simon Glass
2025-12-02 09:29:47 +00:00
parent d8b19014d7
commit 331063acd0
4 changed files with 17 additions and 7 deletions

10
Kconfig
View File

@@ -345,6 +345,16 @@ config MALLOC_DEBUG
enables additional assertions and the malloc_get_info() function
to retrieve memory-allocation statistics.
config MCHECK_HEAP_PROTECTION
bool "Enable mcheck heap protection"
depends on !TRACE
help
Enable heap protection using the mcheck library. This adds canary
values before and after each allocation to detect buffer overflows
and underflows, double-frees, and memory corruption. This
significantly increases memory overhead and should only be used for
debugging.
config SPL_SYS_MALLOC_F
bool "Enable malloc() pool in SPL"
depends on SPL_FRAMEWORK && SYS_MALLOC_F && SPL