Not yet working stack checking (symbol STACKCHECK)
[gnokii.git] / gnokii / cleanup.c
1 #ifdef GNOKII_MAIN
2 #include "config.h"
3 #endif
4
5 #include <stdio.h>
6
7 void _cleanup(void)
8 {
9         /* hack for pic32 gcc */
10 }
11
12 #ifdef STACKCHECK
13
14 static volatile int live_check_disable=0;
15
16 void live_check(const char *file,int line)
17 {
18 static volatile char *top=NULL,*top_printed=NULL;
19 static volatile size_t largest=0,largest_printed=0;
20 volatile char mark;
21
22         if (&mark > top) 
23                 top=&mark;
24         if (live_check_disable<=0 && top!=top_printed) {
25                 printf("live_check [%s:%d]: new top=0x%08lX\n",file,line,(long)top);
26                 fflush(stdout);
27                 top_printed=top;
28                 }
29         if (largest < top-&mark)
30                 largest = top-&mark;
31         if (live_check_disable<=0 && largest!=largest_printed) {
32                 printf("live_check [%s:%d]: largest=%ld\n",file,line,(long)largest);
33                 fflush(stdout);
34                 largest_printed=largest;
35                 }
36         if (largest >= 12000) {
37                 if (live_check_disable<=0)
38                         puts("live_check - aborting!");
39                 _exit(99);
40                 }
41 }
42
43 void live_disable(int how)
44 {
45         live_check_disable+=how;
46 }
47
48 #endif /* STACKCHECK */