mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-03 01:51:29 +00:00
Change behaviour of posix_memalign for Solaris
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.
This commit is contained in:
parent
19dc72931b
commit
33ce1bf1cb
@ -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);
|
||||
|
||||
@ -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@
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user