This source file includes following definitions.
- prepare_alternate_stack
- check_alternate_stack_no_overflow
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <stdint.h>
20 #include <string.h>
21
22 #define MYSTACK_SIZE (1 << 24)
23
24
25
26
27
28
29
30 #define MYSTACK_CRUMPLE_ZONE 8192
31 static char mystack_storage[MYSTACK_SIZE + 2 * MYSTACK_CRUMPLE_ZONE + 31];
32 static char *mystack;
33
34 static void
35 prepare_alternate_stack (void)
36 {
37 #ifdef SIGSTKSZ
38 if (MYSTACK_SIZE < SIGSTKSZ)
39 {
40 size_t size = SIGSTKSZ;
41 printf ("SIGSTKSZ=%zu exceeds MYSTACK_SIZE=%d\n", size, MYSTACK_SIZE);
42 exit (1);
43 }
44 #endif
45 memset (mystack_storage, 's', sizeof mystack_storage);
46 mystack = (char *) ((uintptr_t) (mystack_storage + MYSTACK_CRUMPLE_ZONE) | 31);
47 }
48
49 static void
50 check_alternate_stack_no_overflow (void)
51 {
52 unsigned int i;
53
54 for (i = MYSTACK_CRUMPLE_ZONE; i > 0; i--)
55 if (*(mystack - i) != 's')
56 {
57 printf ("Alternate stack was exceeded by %u bytes!!\n", i);
58 exit (1);
59 }
60 for (i = MYSTACK_CRUMPLE_ZONE; i > 0; i--)
61 if (*(mystack + MYSTACK_SIZE - 1 + i) != 's')
62 {
63 printf ("Alternate stack was exceeded by %u bytes!!\n", i);
64 exit (1);
65 }
66 }