From: Paul Floyd Date: Sat, 1 Apr 2023 20:28:36 +0000 (+0200) Subject: Darwin: try to improve posix_memalign / zone_memalign wrapper X-Git-Tag: VALGRIND_3_21_0~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f4052623c6246ee0d59db00d607ec858cefa849;p=thirdparty%2Fvalgrind.git Darwin: try to improve posix_memalign / zone_memalign wrapper It still doesn't set errno though. --- 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; \