+/* Copyright (c) 1979 Regents of the University of California */
+
+static char sccsid[] = "@(#)malloc.c 4.1 10/10/80";
+
+/*
+ * Patched up version of malloc to do an integrity check
+ * on each allocation or free.
+ */
+
#ifdef debug
#define ASSERT(p,t) if(!(p))return(t(TRASHED));else
#else
static union store allocs[2]; /*initial arena*/
static union store *allocp; /*search ptr*/
static union store *alloct; /*arena top*/
-static union store *allocx; /*for benefit of realloc*/
char *sbrk();
char *
malloc(nbytes)
-unsigned nbytes;
+
+ unsigned nbytes;
{
register union store *p, *q;
register nw;
allocp = p + nw;
ASSERT(allocp<=alloct,(char *));
if(q>allocp) {
- allocx = allocp->ptr;
allocp->ptr = p->ptr;
}
p->ptr = setbusy(allocp);
return((char *)(p+1));
}
-/* freeing strategy tuned for LIFO allocation
-*/
+/*
+ * freeing strategy tuned for LIFO allocation
+ */
+
free(ap)
-register char *ap;
+
+ register char *ap;
{
register union store *p = (union store *)ap;
return(NULL);
}
-/* realloc(p, nbytes) reallocates a block obtained from malloc()
- * and freed since last call of malloc()
- * to have new size nbytes, and old content
- * returns new location, or 0 on failure
-*/
-
-char *
-realloc(p, nbytes)
-register union store *p;
-unsigned nbytes;
-{
- register union store *q;
- union store *s, *t;
- register unsigned nw;
- unsigned onw;
-
- if(testbusy(p[-1].ptr))
- free((char *)p);
- onw = p[-1].ptr - p;
- q = (union store *)malloc(nbytes);
- if(q==NULL || q==p)
- return((char *)q);
- s = p;
- t = q;
- nw = (nbytes+WORD-1)/WORD;
- if(nw<onw)
- onw = nw;
- while(onw--!=0)
- *t++ = *s++;
- if(q<p && q+nw>=p)
- (q+(q+nw-p))->ptr = allocx;
- return((char *)q);
-}
-
#ifdef debug
allock()
{
#endif
}
#endif
-