void _cleanup(void)
{
/* hack for pic32 gcc */
+
+#if 0
+#ifdef LIVE
+ LIVE;
+#endif /* LIVE */
+#endif
}
#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);
}
}
live_check_disable+=how;
}
+#define STACKCHECK_HEADER_PC_OFFSET 16
+
+void stackcheck(void)
+{
+volatile static inside=0;
+volatile void *func;
+volatile int fp_alloc;
+
+ asm("movel %%d0,%0" : "=r" (fp_alloc) : /* input */ : "d0");
+ asm("movel %%fp@(4),%0" : "=r" (func) : /* input */);
+
+ if (inside)
+ return;
+ inside++;
+
+ 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 */
+
+ inside--;
+}
+
#endif /* STACKCHECK */