Add missing zstd.h to coregrind Makefile.am noinst_HEADERS
[valgrind.git] / memcheck / tests / solaris / brk.c
blob4ec6bf52ceca592594ec60dd1d6f88ff41ac8ad9
1 /* Test for the brk syscall wrapper. */
3 #include <assert.h>
4 #include <errno.h>
5 #include <stddef.h>
6 #include <sys/syscall.h>
8 /* Data segment end. */
9 extern int _end;
10 static char *begin = (char *)&_end;
12 __attribute__((noinline))
13 static int test_begin(void)
15 int res = 0;
16 int tmp;
18 /* Check that a value at the break is inaccessible. */
19 if (*begin)
20 res++;
22 /* Allocate one byte and check that the last byte is accessible and
23 initialized. */
24 tmp = syscall(SYS_brk, begin + 1);
25 assert(tmp != -1);
26 if (*begin)
27 res++;
29 /* Deallocate one byte and check that the last byte is now inaccessible. */
30 tmp = syscall(SYS_brk, begin);
31 assert(tmp != -1);
32 if (*begin)
33 res++;
35 return res;
38 __attribute__((noinline))
39 static void test_updown(void)
41 int tmp;
42 size_t i;
44 #define MAX_SIZE 8192
45 /* Run up phase. */
46 for (i = 0; i < MAX_SIZE; i++) {
47 tmp = syscall(SYS_brk, begin + i);
48 assert(tmp != -1);
51 /* Run down phase. */
52 for (i = 0; i < MAX_SIZE; i++) {
53 tmp = syscall(SYS_brk, begin + MAX_SIZE - 1 - i);
54 assert(tmp != -1);
56 #undef MAX_SIZE
59 __attribute__((noinline))
60 static void test_range(void)
62 int tmp;
64 tmp = syscall(SYS_brk, begin - 1);
65 assert(tmp == -1);
66 assert(errno == ENOMEM);
68 /* Unified limit for 64-bit and 32-bit version. */
69 unsigned long long impossible_limit = 0xffffff4fffffffULL;
70 tmp = syscall(SYS_brk, impossible_limit);
71 assert(tmp == -1);
72 assert(errno == ENOMEM);
75 int main(void)
77 int res;
78 res = test_begin();
79 test_updown();
80 test_range();
81 return res;