1 | #include <stdio.h> |
---|---|
2 | #include <stdlib.h> |
3 | #include <tst-stack-align.h> |
4 | |
5 | struct big { char c[4 * 1024]; }; |
6 | |
7 | struct big *array; |
8 | struct big *array_end; |
9 | |
10 | static int align_check; |
11 | |
12 | int |
13 | compare (void const *a1, void const *b1) |
14 | { |
15 | struct big const *a = a1; |
16 | struct big const *b = b1; |
17 | |
18 | if (!align_check) |
19 | align_check = TEST_STACK_ALIGN () ? -1 : 1; |
20 | |
21 | if (! (array <= a && a < array_end |
22 | && array <= b && b < array_end)) |
23 | { |
24 | exit (EXIT_FAILURE); |
25 | } |
26 | return b->c[0] - a->c[0]; |
27 | } |
28 | |
29 | int |
30 | main (int argc, char **argv) |
31 | { |
32 | size_t i; |
33 | size_t array_members = argv[1] ? atoi (argv[1]) : 50; |
34 | array = (struct big *) malloc (size: array_members * sizeof *array); |
35 | if (array == NULL) |
36 | { |
37 | puts (s: "no memory"); |
38 | exit (EXIT_FAILURE); |
39 | } |
40 | |
41 | array_end = array + array_members; |
42 | for (i = 0; i < array_members; i++) |
43 | array[i].c[0] = i % 128; |
44 | |
45 | qsort (array, array_members, sizeof *array, compare); |
46 | |
47 | if (align_check == -1) |
48 | { |
49 | puts (s: "stack not sufficiently aligned"); |
50 | exit (EXIT_FAILURE); |
51 | } |
52 | |
53 | return 0; |
54 | } |
55 |