home *** CD-ROM | disk | FTP | other *** search
- /*
- * What we want to do is keep track of who calls calloc, malloc, and free,
- * and what size blocks they request.
- * Turn off all this expensive checking by defining NOMALLOCCHECK.
- */
-
- #include <stdio.h>
-
- char *__malloc();
-
- #define MAGIC 0x99773311
- #define MAGIC2 0x11773399
- /* define MINALLOC 0 */ /* MINALLOC is the minimum number of bytes
- that may be allocated.
- Some dumb Yellow Page routine on june.cs.washington.edu
- allocates 0 bytes for some unknown reason
- so I had to disable MINALLOC. Eric Jul, Nov. 1987 */
-
- int vMallocLimit = 2000000;
-
- /*VARARGS*/
- char *malloc(num)
- int num;
- {
- register char *callerspc; /* r11 on vax, a5 on sun */
- register char *mp;
-
- #ifdef NOMALLOCCHECK
- return(__malloc(num));
- #else NOMALLOCCHECK
-
- #ifdef vax
- asm(" movl 16(fp), r11");
- #endif
- #ifdef sun
- asm(" movl a6@(4), a5");
- #endif
-
- #ifdef MINALLOC
- if (num > vMallocLimit || num < MINALLOC) {
- printf( "malloc(%d) arg too small or above limit of %d\n",
- num, vMallocLimit);
- printf( "(vMallocLimit is tunable.)\n");
- abort();
- }
- #else MINALLOC
- if (num > vMallocLimit) {
- printf( "malloc request %d bytes, limit is %d bytes\n",
- num, vMallocLimit);
- printf( "(vMallocLimit is tunable.)\n");
- abort();
- }
- #endif MINALLOC
- mp = __malloc (num + 2*sizeof(int));
- #ifdef lint
- callerspc = mp;
- #endif
- install_alloc(callerspc, num, mp+sizeof(int));
- *(int *)mp = MAGIC;
- *(int *)(mp+num+sizeof(int)) = MAGIC2;
- return(mp+sizeof(int));
- #endif NOMALLOCCHECK
-
- }
-
- #define CHARPERINT (sizeof(int)/sizeof(char))
- #define NULL 0
-
- char *calloc(num, size)
- unsigned int num, size;
- {
- register char *callerspc; /* r11 on vax, a5 on sun */
- register char *mp; /* r10 */
- register int length; /* r 9 */
- register char *fp; /* r 8 */
-
- #ifdef NOMALLOCCHECK
- fp = __malloc(length);
- #ifdef vax
- while (length > 32768) {
- asm(" movc5 $0, (r0), $0, $32768, (r8)");
- length -= 32768;
- fp += 32768;
- }
- asm(" movc5 $0, (r0), $0, r9, (r8)");
- #endif
- #ifdef sun
- bzero(fp, length);
- #endif
- return (fp);
- #else NOMALLOCCHECK
-
- #ifdef vax
- asm(" movl 16(fp), r11");
- #endif
- #ifdef sun
- asm(" movl a6@(4), a5");
- #endif
- length = num;
- length *= size;
- mp = __malloc(length+8);
- #ifdef lint
- callerspc = mp;
- #endif lint
- install_alloc(callerspc, length, mp+4);
- if (mp == NULL) return(NULL);
- fp = mp + sizeof(int);
- #ifdef lint
- fp = fp;
- #endif
- #ifdef vax
- while (length > 32768) {
- asm(" movc5 $0, (r0), $0, $32768, (r8)");
- length -= 32768;
- fp += 32768;
- }
- asm(" movc5 $0, (r0), $0, r9, (r8)");
- #endif
- #ifdef sun
- bzero(fp, length);
- #endif
- *(int *)mp = MAGIC;
- *(int *)(mp+length+4) = MAGIC2;
- return(mp+4);
- #endif NOMALLOCCHECK
- }
-
- void free(mp)
- char *mp;
- {
- register char *callerspc; /* r11 on vax, a5 on sun */
- #ifdef NOMALLOCCHECK
- __free(mp);
- return;
- #else NOMALLOCCHECK
-
- #ifdef vax
- asm(" movl 16(fp), r11");
- #endif
- #ifdef sun
- asm(" movl a6@(4), a5");
- #endif
- #ifdef lint
- callerspc = mp;
- #endif lint
- install_free(callerspc, (unsigned int) mp);
- __free(mp - 4);
- #endif NOMALLOCCHECK
- }
-
- char *cfree()
- {
- abort();
- }
-
- char *realloc()
- {
- abort();
- }
-