X-Git-Url: https://git.jankratochvil.net/?p=gnokii.git;a=blobdiff_plain;f=gnokii%2Fcleanup.c;h=2a0b51e5fb33f1f1c44ce553ad5581af0057a890;hp=1900733023a4300af80e8495e9685932e33e6bcc;hb=945be3cc1ae0f7739a3d28722d07f7d17b2690bf;hpb=81b1712d54efa46b3148a5beb42d32d7632ef30c diff --git a/gnokii/cleanup.c b/gnokii/cleanup.c index 1900733..2a0b51e 100644 --- a/gnokii/cleanup.c +++ b/gnokii/cleanup.c @@ -7,35 +7,40 @@ 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) +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 (&mark > top) - top=&mark; + 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-&mark) - largest = top-&mark; + 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 >= 12000) { + if (largest >= STACKCHECK) { if (live_check_disable<=0) - puts("live_check - aborting!"); + printf("live_check - aborting: limit=%d < largest=%ld!\n",STACKCHECK,(long)largest); _exit(99); } } @@ -45,4 +50,21 @@ 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 */