solaris: aligned allocation issues

Solaris 11.3 doesn't have aligned_alloc - add a configure time test
memalign does not accept either a size or an alignment of zero
This commit is contained in:
Paul Floyd 2023-04-23 13:51:37 +02:00
parent 8360205968
commit a821780d8c
7 changed files with 52 additions and 4 deletions

View File

@ -4803,6 +4803,7 @@ AC_CHECK_LIB([pthread], [pthread_create])
AC_CHECK_LIB([rt], [clock_gettime])
AC_CHECK_FUNCS([ \
aligned_alloc \
clock_gettime\
copy_file_range \
epoll_create \

View File

@ -1742,8 +1742,10 @@ extern int * __error(void) __attribute__((weak));
#if defined(VGO_solaris)
#define VG_MEMALIGN_ALIGN_POWER_TWO 0
#define VG_MEMALIGN_NO_ALIGN_ZERO 1
#else
#define VG_MEMALIGN_ALIGN_POWER_TWO 1
#define VG_MEMALIGN_NO_ALIGN_ZERO 0
#endif
#if defined(VGO_solaris)
@ -1802,7 +1804,8 @@ extern int * __error(void) __attribute__((weak));
DO_INIT; \
MALLOC_TRACE("memalign(alignment %llu, size %llu)", \
(ULong)alignment, (ULong)size ); \
if ((VG_MEMALIGN_NO_SIZE_ZERO && (alignment == 0)) \
if ((VG_MEMALIGN_NO_SIZE_ZERO && (size == 0)) \
|| (VG_MEMALIGN_NO_ALIGN_ZERO && (alignment == 0)) \
|| (VG_MEMALIGN_ALIGN_POWER_TWO && (alignment & (alignment - 1)) != 0) \
|| (VG_MEMALIGN_ALIGN_FACTOR_FOUR && (alignment % 4 != 0))) { \
SET_ERRNO_EINVAL; \

View File

@ -141,6 +141,7 @@ EXTRA_DIST = \
custom-overlap.stderr.exp custom-overlap.vgtest \
cxx17_aligned_new.stderr.exp cxx17_aligned_new.vgtest \
cxx17_aligned_new.stderr.exp_32 \
cxx17_aligned_new.stderr.exp-solaris \
cxx17_aligned_new.stdout.exp \
sized_aligned_new_delete_args.stderr.exp \
sized_aligned_new_delete_args.vgtest \
@ -226,6 +227,7 @@ EXTRA_DIST = \
memalign_test.stderr.exp-freebsd-clang \
memalign_args.vgtest memalign_args.stderr.exp \
memalign_args.stderr.exp-glibc \
memalign_args.stderr.exp-darwin \
memcmptest.stderr.exp memcmptest.stderr.exp2 \
memcmptest.stdout.exp memcmptest.vgtest \
memmem.stderr.exp memmem.vgtest \

View File

@ -0,0 +1,30 @@
_ZnwmSt11align_val_t(size 64, al 64) = 0x........
_ZdlPvSt11align_val_t(0x........)
_ZnamSt11align_val_t(size 320, al 64) = 0x........
_ZdaPvSt11align_val_t(0x........)
_ZnwmSt11align_val_t(size 64, al 64) = 0x........
_ZdlPvmSt11align_val_t(0x........)
_ZnamSt11align_val_t(size 320, al 64) = 0x........
_ZdaPvmSt11align_val_t(0x........)
_ZnwmSt11align_val_tRKSt9nothrow_t(size 64, al 64) = 0x........
_ZdlPvSt11align_val_tRKSt9nothrow_t(0x........)
_ZnamSt11align_val_tRKSt9nothrow_t(size 320, al 64) = 0x........
_ZdaPvSt11align_val_tRKSt9nothrow_t(0x........)
_Znwm(4) = 0x........
_ZdlPvSt11align_val_t(0x........)
_ZnwmRKSt9nothrow_t(4) = 0x........
_ZdlPvm(0x........)
_Znam(20) = 0x........
_ZdaPv(0x........)
_ZnamRKSt9nothrow_t(20) = 0x........
_ZdaPv(0x........)
HEAP SUMMARY:
in use at exit: ... bytes in ... blocks
total heap usage: ... allocs, ... frees, ... bytes allocated
For a detailed leak analysis, rerun with: --leak-check=full
For lists of detected and suppressed errors, rerun with: -s
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

View File

@ -23,7 +23,7 @@ int main(void)
(void)posix_memalign((void **)&mem,align,size);
free(mem);
#if !defined(VGO_darwin)
#if defined(HAVE_ALIGNED_ALLOC)
p = aligned_alloc(align, size);
free(p);
#endif

View File

@ -0,0 +1,11 @@
Conditional jump or move depends on uninitialised value(s)
at 0x........: memalign (vg_replace_malloc.c:...)
by 0x........: main (memalign_args.c:19)
Conditional jump or move depends on uninitialised value(s)
at 0x........: posix_memalign (vg_replace_malloc.c:...)
by 0x........: main (memalign_args.c:23)
Conditional jump or move depends on uninitialised value(s)
at 0x........: valloc (vg_replace_malloc.c:...)
by 0x........: main (memalign_args.c:31)

View File

@ -1,12 +1,13 @@
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include "../../config.h"
int main(void)
{
#if defined(HAVE_ALIGNED_ALLOC)
char* p = NULL;
// zero size
p = aligned_alloc(0, 8);
assert(p == NULL && errno == EINVAL);
@ -33,6 +34,6 @@ int main(void)
}
assert(p == NULL && errno == ENOMEM);
#endif
}