FreeBSD regtest: remove test for version 13+ syscalls
[valgrind.git] / memcheck / tests / freebsd / errno_aligned_allocs.c
blob26979f465598c15a51300575f36cf8d82c441cc7
1 #include <stdlib.h>
2 #if defined(__FreeBSD__)
3 #include <malloc_np.h>
4 #endif
5 #include <assert.h>
6 #include <errno.h>
8 int main(void)
10 char* p = NULL;
11 int res;
13 // zero alignment
14 res = posix_memalign((void**)&p, 0, 8);
15 assert(p == NULL && res == EINVAL);
16 // align not multiple of sizeof(void*)
17 res = posix_memalign((void**)&p, 2, 32);
18 assert(p == NULL && res == EINVAL);
19 // align not power of two
20 res = posix_memalign((void**)&p, 40, 160);
21 assert(p == NULL && res == EINVAL);
23 // digging through the jemalloc code
24 // the max alignment allowed is
25 // 0x70000000 for i386 and
26 // 0x7000000000000000 for amd64
27 // but valgrind has a limit of only 16M
28 // 0x10000000
29 // on both platforms
30 // the 64bit limit is around 1e18 bytes
31 // a million terabytes
33 // Valgrind handles that badly. it throws a core_panic :-(
35 //res = posix_memalign((void**)&p, (1UL<<63), 4096);
36 //assert(p == NULL && res == ENOMEM);
38 // too big
39 if (sizeof(size_t) == 8)
41 res = posix_memalign((void**)&p, 16, 1UL<<48);
43 else
45 // on x86 it's hard to actually get ENOMEM
46 // if we ask for more than 2Gbytes the fishy
47 // detector will kick in and not try to allocate
48 // less than 2Gbytes and it's likely to succeed
49 // (at least on a machine just running VG regtests)
50 // so fake it
51 p = NULL;
52 res = ENOMEM;
54 assert(p == NULL && res == ENOMEM);
55 errno = 0;
58 // if ever we make this multi-platform, Solaris doesn't support this
59 // zero size
60 p = aligned_alloc(32, 0);
61 assert(p && ((size_t)p % 32U == 0U));
62 free(p);
63 // zero alignment
64 p = aligned_alloc(0, 8);
65 assert(p == NULL && errno == EINVAL);
66 errno = 0;
67 // non multiple of alignment passes on FreeBSD
68 p = aligned_alloc(8, 25);
69 assert(p && ((size_t)p % 8U == 0U));
70 free(p);
71 //errno = 0;
72 // align not power of 2
73 p = aligned_alloc(40, 160);
74 assert(p == NULL && errno == EINVAL);
75 errno = 0;
76 // too big
77 if (sizeof(size_t) == 8)
79 p = aligned_alloc(16, 1UL<<48);
81 else
83 p = NULL;
84 errno = ENOMEM;
86 assert(p == NULL && errno == ENOMEM);