[Concept,25/37] mcheck: support memalign

Message ID 20251201170529.3237986-26-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>

Implement the dlmemalign wrapper function for mcheck heap protection.
Uses mcheck_memalign_prehook() and mcheck_memalign_posthook() to
properly handle aligned allocations.

Changes from original commit:
- Uses dlmemalign/dlmemalign_impl instead of mEMALIGn/mEMALIGn_impl

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 ae838768d79cbb834c4a8a5f4810df373e58b622)
---

 common/dlmalloc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
  

Patch

diff --git a/common/dlmalloc.c b/common/dlmalloc.c
index 102b6c2bf8d..c9eb18787e8 100644
--- a/common/dlmalloc.c
+++ b/common/dlmalloc.c
@@ -5628,7 +5628,12 @@  void *dlrealloc(void *oldmem, size_t bytes)
 
 void *dlmemalign(size_t alignment, size_t bytes)
 {
-	return NULL;
+	size_t fullsz = mcheck_memalign_prehook(alignment, bytes);
+	void *p = dlmemalign_impl(alignment, fullsz);
+
+	if (!p)
+		return p;
+	return mcheck_memalign_posthook(alignment, p, bytes);
 }
 
 /* dlpvalloc, dlvalloc redirect to dlmemalign, so they need no wrapping */