home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
-
- #ifndef NOMALLOCCHECK
- #define MAXBLOCKS 10000
- typedef struct {
- unsigned int callerspc;
- unsigned int num;
- unsigned int mp;
- } block, *bp;
- extern block ht[MAXBLOCKS];
- #endif
- #define Hash(N) (((N) >> 3) % MAXBLOCKS)
-
- #define panicabort(S) { printf( "%s\n", S); abort(); }
- #define MAGIC 0x99773311
- #define MAGIC2 0x11773399
-
- extern unsigned int totalAllocated, totalFreed;
-
- malloc_stats()
- {
- printf( "total allocations %d\ntotal frees %d\n",
- totalAllocated, totalFreed);
- }
-
- /*ARGSUSED*/
- malloc_doall(f)
- int (*f)();
- {
- #ifndef NOMALLOCCHECK
- register bp p;
- for (p = ht; p < &ht[MAXBLOCKS]; p++)
- if (p->mp != 0) (*f)(p->callerspc, p->num, p->mp);
- #endif
- }
-
- checkitout(callerspc, num, p)
- int callerspc, num;
- register char *p;
- {
- if (*(int *)(p-4) != MAGIC || *(int *)(p+num) != MAGIC2) {
- printf( "corrupted block 0x%x allocated from 0x%x\n",
- p, callerspc);
- }
- }
-
- malloc_check()
- {
- malloc_doall(checkitout);
- }
-
- displayHunk(pc, num, mp)
- unsigned int pc, num, mp;
- {
- printf( "Allocated from 0x%x, size %d, addr 0x%x\n", pc, num, mp);
- }
-
- malloc_display()
- {
- malloc_doall(displayHunk);
- }
-