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(-) 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 */ -- 2.43.0