X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/b202b2da3819475912294fd6740ab4adbffbf038..31cef89cb428866f787983e68246030321893df4:/usr/src/cmd/px/malloc.c diff --git a/usr/src/cmd/px/malloc.c b/usr/src/cmd/px/malloc.c index e8603a2550..acc96074d5 100644 --- a/usr/src/cmd/px/malloc.c +++ b/usr/src/cmd/px/malloc.c @@ -1,3 +1,12 @@ +/* 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 @@ -48,12 +57,12 @@ union store { union store *ptr; 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; @@ -108,17 +117,19 @@ found: 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; @@ -132,40 +143,6 @@ register char *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=p) - (q+(q+nw-p))->ptr = allocx; - return((char *)q); -} - #ifdef debug allock() { @@ -184,4 +161,3 @@ allock() #endif } #endif -