X-Git-Url: https://git.jankratochvil.net/?p=gnokii.git;a=blobdiff_plain;f=gnokii%2Fcleanup.c;h=2a0b51e5fb33f1f1c44ce553ad5581af0057a890;hp=e11b7c2327fdbda40d1a95b81f5c93e118d4d237;hb=945be3cc1ae0f7739a3d28722d07f7d17b2690bf;hpb=f2cfd49e920cfff5a15ea44fc82d002306d07cb1 diff --git a/gnokii/cleanup.c b/gnokii/cleanup.c index e11b7c2..2a0b51e 100644 --- a/gnokii/cleanup.c +++ b/gnokii/cleanup.c @@ -1,4 +1,70 @@ +#ifdef GNOKII_MAIN +#include "config.h" +#endif + +#include + void _cleanup(void) { /* hack for pic32 gcc */ + +#ifdef LIVE + LIVE; +#endif /* LIVE */ } + +#ifdef STACKCHECK + +static volatile int live_check_disable=0; + +void live_check(const char *file,int line,int alloc) +{ +static volatile char *top=NULL,*top_printed=NULL; +static volatile size_t largest=0,largest_printed=0; +volatile char mark; +volatile char *will=&mark-(alloc==-1 ? 0 : alloc); + + if (will > top) + top=will; + if (live_check_disable<=0 && top!=top_printed) { + printf("live_check [%s:%d]: new top=0x%08lX\n",file,line,(long)top); + fflush(stdout); + top_printed=top; + } + if (largest < top-will) + largest = top-will; + if (live_check_disable<=0 && largest!=largest_printed) { + printf("live_check [%s:%d]: largest=%ld\n",file,line,(long)largest); + fflush(stdout); + largest_printed=largest; + } + if (largest >= STACKCHECK) { + if (live_check_disable<=0) + printf("live_check - aborting: limit=%d < largest=%ld!\n",STACKCHECK,(long)largest); + _exit(99); + } +} + +void live_disable(int how) +{ + live_check_disable+=how; +} + +#define STACKCHECK_HEADER_PC_OFFSET 16 + +void stackcheck(void) +{ +volatile void *func; +volatile int fp_alloc; + + asm("movel %%d0,%0" : "=r" (fp_alloc) : /* input */ : "d0"); + asm("movel %%sp@,%0" : "=r" (func) : /* input */); + + if (live_check_disable<=0) + printf("mcount(func=0x%08lX,fp_alloc=%d)\n",((long)func)-STACKCHECK_HEADER_PC_OFFSET,-fp_alloc); +#ifdef LIVE_ALLOC + LIVE_ALLOC((-fp_alloc)+4); +#endif /* LIVE_ALLOC */ +} + +#endif /* STACKCHECK */