From 3f4052623c6246ee0d59db00d607ec858cefa849 Mon Sep 17 00:00:00 2001 From: Paul Floyd Date: Sat, 1 Apr 2023 22:28:36 +0200 Subject: [PATCH] Darwin: try to improve posix_memalign / zone_memalign wrapper It still doesn't set errno though. --- coregrind/m_replacemalloc/vg_replace_malloc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index db2fc5f309..5977fa317b 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -1575,7 +1575,8 @@ extern int *___errno (void) __attribute__((weak)); * */ - /* @todo PJF exactly what is the behaviour if this? */ + /* Probably in the wrong place, this is the function + called by posix_memalign, at least on macOS 10.13 */ #define ZONEMEMALIGN(soname, fnname) \ \ void* VG_REPLACE_FUNCTION_EZU(10100,soname,fnname) \ @@ -1591,6 +1592,12 @@ extern int *___errno (void) __attribute__((weak)); MALLOC_TRACE("zone_memalign(%p, al %llu, size %llu)", \ zone, (ULong)alignment, (ULong)n ); \ \ + if (alignment == 0 \ + || alignment % sizeof (void *) != 0 \ + || (alignment & (alignment - 1)) != 0) { \ + SET_ERRNO_EINVAL; \ + return NULL; \ + } \ /* Round up to minimum alignment if necessary. */ \ if (alignment < VG_MIN_MALLOC_SZB) \ alignment = VG_MIN_MALLOC_SZB; \ -- 2.47.2