From: Paul Floyd Date: Tue, 28 Feb 2023 18:56:52 +0000 (+0100) Subject: Put back Darwin zone memalign X-Git-Tag: VALGRIND_3_21_0~159 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19dc72931b2168c70239c5922fb2bf2fca90e4bf;p=thirdparty%2Fvalgrind.git Put back Darwin zone memalign I had another look at the XNU source and this does seem to exist. The manpage says that it is the zone version of posix_memalign, though that's probably more because Darwin has no memalign. --- diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index 0b591a7c83..5ded69e969 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -1506,6 +1506,34 @@ extern int *___errno (void) __attribute__((weak)); * */ +#define ZONEMEMALIGN(soname, fnname) \ + \ + void* VG_REPLACE_FUNCTION_EZU(10100,soname,fnname) \ + ( void *zone, SizeT alignment, SizeT n ); \ + void* VG_REPLACE_FUNCTION_EZU(10100,soname,fnname) \ + ( void *zone, SizeT alignment, SizeT n ) \ + { \ + void* v; \ + \ + DO_INIT; \ + TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord) zone); \ + TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED(n); \ + MALLOC_TRACE("zone_memalign(%p, al %llu, size %llu)", \ + zone, (ULong)alignment, (ULong)n ); \ + \ + /* Round up to minimum alignment if necessary. */ \ + if (alignment < VG_MIN_MALLOC_SZB) \ + alignment = VG_MIN_MALLOC_SZB; \ + \ + /* Round up to nearest power-of-two if necessary (like glibc). */ \ + while (0 != (alignment & (alignment - 1))) alignment++; \ + \ + v = (void*)VALGRIND_NON_SIMD_CALL2( info.tl_memalign, alignment, n ); \ + MALLOC_TRACE(" = %p\n", v ); \ + if (!v) SET_ERRNO_ENOMEM; \ + return v; \ + } + #if defined(VGO_linux) #if !defined(MUSL_LIBC) #define MEMALIGN(soname, fnname) \ @@ -1647,6 +1675,10 @@ extern int *___errno (void) __attribute__((weak)); MEMALIGN(VG_Z_LIBC_SONAME, memalign); MEMALIGN(SO_SYN_MALLOC, memalign); +#elif defined(VGO_darwin) + ZONEMEMALIGN(VG_Z_LIBC_SONAME, malloc_zone_memalign); + ZONEMEMALIGN(SO_SYN_MALLOC, malloc_zone_memalign); + #elif defined(VGO_solaris) MEMALIGN(VG_Z_LIBC_SONAME, memalign); MEMALIGN(VG_Z_LIBUMEM_SO_1, memalign);