]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Change behaviour of posix_memalign for Solaris
authorPaul Floyd <pjfloyd@wanadoo.fr>
Tue, 28 Feb 2023 20:21:05 +0000 (21:21 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Tue, 28 Feb 2023 20:21:05 +0000 (21:21 +0100)
It returns NULL and 0 status whilst most other platforms
allocatae some undefined amount of memory (which is allowed
by posix).

Update the posix_memalign test as well.

Finally remove some clang warnings about alignment.

coregrind/m_replacemalloc/vg_replace_malloc.c
memcheck/tests/freebsd/Makefile.am
memcheck/tests/posix_memalign.c

index 5ded69e969e6e35a25fa360a9fee2fdf070218f7..cc38d665bfe5bc74eccbd08ee425836175c3a3d9 100644 (file)
@@ -1817,6 +1817,12 @@ extern int *___errno (void) __attribute__((weak));
 
 /*---------------------- posix_memalign ----------------------*/
 
+#if defined(VGO_solaris)
+#define VG_POSIX_MEMALIGN_SIZE_0_RETURN_NULL 1
+#else
+#define VG_POSIX_MEMALIGN_SIZE_0_RETURN_NULL 0
+#endif
+
 #define POSIX_MEMALIGN(soname, fnname) \
    \
    int VG_REPLACE_FUNCTION_EZU(10160,soname,fnname) \
@@ -1837,6 +1843,12 @@ extern int *___errno (void) __attribute__((weak));
           || (alignment & (alignment - 1)) != 0) { \
          return VKI_EINVAL; \
       } \
+      if (VG_POSIX_MEMALIGN_SIZE_0_RETURN_NULL && \
+          size == 0U) { \
+         /* no allocation for zro size on Solaris/Illumos */ \
+         *memptr = NULL; \
+         return 0; \
+      } \
       /* Round up to minimum alignment if necessary. */ \
       if (alignment < VG_MIN_MALLOC_SZB) \
           alignment = VG_MIN_MALLOC_SZB; \
@@ -1861,7 +1873,9 @@ extern int *___errno (void) __attribute__((weak));
  POSIX_MEMALIGN(SO_SYN_MALLOC,    posix_memalign);
 
 #elif defined(VGO_darwin)
- //POSIX_MEMALIGN(VG_Z_LIBC_SONAME, posix_memalign);
+#if (DARWIN_VERSIO >= DARWIN_10_6)
+ POSIX_MEMALIGN(VG_Z_LIBC_SONAME, posix_memalign);
+#endif
 
 #elif defined(VGO_solaris)
  POSIX_MEMALIGN(VG_Z_LIBC_SONAME, posix_memalign);
index 631d0efe9e6a9d3a04c03ac23d2a2f1a17cc91ac..2259e1efb8cf98fce59089183e7c252a17c90740 100644 (file)
@@ -134,3 +134,5 @@ scalar_CFLAGS = ${AM_CFLAGS} -g
 errno_aligned_allocs_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_NON_POWER_OF_TWO_ALIGNMENT@
 
 extattr_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_UNUSED_BUT_SET_VARIABLE@
+
+memalign_CFLAGS = ${AM_CFLAGS} @FLAG_W_NO_NON_POWER_OF_TWO_ALIGNMENT@
index 415c6c025b0d9b9834a797a1bc154ce9b429b1bb..219df2ffd844d22f77d64c267c3f97d880db21cc 100644 (file)
@@ -28,25 +28,33 @@ int main ( void )
 
 #  define PM(a,b,c) posix_memalign((void**)a, b, c)
 
+   // test for size 0
+   res = PM(&p, 64, 0);
+#if defined(VGO_solaris)
+   assert(NULL == p);
+#else
+   assert(0 == res && p && 0 == (long)p % 64);
+#endif
+
    res = PM(&p, -1,100);      assert(EINVAL == res);
    res = PM(&p, 0, 100);      assert(EINVAL == res);
    res = PM(&p, 1, 100);      assert(EINVAL == res);
    res = PM(&p, 2, 100);      assert(EINVAL == res);
    res = PM(&p, 3, 100);      assert(EINVAL == res);
    res = PM(&p, sizeof(void*), 100);
-                              assert(0 == res && 0 == (long)p % sizeof(void*));
+                              assert(0 == res && p && 0 == (long)p % sizeof(void*));
 
    res = PM(&p, 31, 100);     assert(EINVAL == res);
-   res = PM(&p, 32, 100);     assert(0 == res && 0 == (long)p % 32);
+   res = PM(&p, 32, 100);     assert(0 == res && p && 0 == (long)p % 32);
    res = PM(&p, 33, 100);     assert(EINVAL == res);
 
    res = PM(&p, 4095, 100);   assert(EINVAL == res);
-   res = PM(&p, 4096, 100);   assert(0 == res && 0 == (long)p % 4096); 
+   res = PM(&p, 4096, 100);   assert(0 == res && p && 0 == (long)p % 4096);
    res = PM(&p, 4097, 100);   assert(EINVAL == res);
 
-   res = PM(&p, 4 * 1024 * 1024, 100);   assert(0 == res 
+   res = PM(&p, 4 * 1024 * 1024, 100);   assert(0 == res && p
                                                 && 0 == (long)p % (4 * 1024 * 1024));
-   res = PM(&p, 16 * 1024 * 1024, 100);   assert(0 == res 
+   res = PM(&p, 16 * 1024 * 1024, 100);   assert(0 == res &&p
                                                 && 0 == (long)p % (16 * 1024 * 1024));
 #endif
 }