[Concept,23/37] mcheck: Use memset/memcpy instead of MALLOC_ZERO/MALLOC_COPY for mcheck.

Message ID 20251201170529.3237986-24-sjg@u-boot.org
State New
Headers
Series malloc: Import dlmalloc 2.8.6 |

Commit Message

Simon Glass Dec. 1, 2025, 5:05 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

These fast helpers sometimes breach mem-chunk boundaries.
Thus they trigger mcheck alarm. Standard ones are accurate though.

When MCHECK_HEAP_PROTECTION is enabled, redefine MALLOC_ZERO and
MALLOC_COPY to use standard memset/memcpy instead of the optimized
versions that may access memory outside allocated chunks.

Signed-off-by: Eugene Uriev <eugeneuriev@gmail.com>
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
(cherry picked from commit dfba071ddc3e609e61770b34ab0115fbce05edb2)
---

 common/dlmalloc.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Patch

diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index 972cadd2e2f..4f88e48f4b0 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -559,6 +559,10 @@  MAX_RELEASE_CHECK_RATE   default: 4095 unless not HAVE_MMAP
 
 #ifdef MCHECK_HEAP_PROTECTION
 #define STATIC_IF_MCHECK static
+#undef MALLOC_COPY
+#undef MALLOC_ZERO
+static inline void MALLOC_ZERO(void *p, size_t sz) { memset(p, 0, sz); }
+static inline void MALLOC_COPY(void *dest, const void *src, size_t sz) { memcpy(dest, src, sz); }
 #else
 #define STATIC_IF_MCHECK
 #define dlmalloc_impl dlmalloc