BSD 4 release
[unix-history] / usr / src / cmd / px / malloc.c
index e8603a2..acc9607 100644 (file)
@@ -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
 #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 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)
 char   *sbrk();
 
 char *
 malloc(nbytes)
-unsigned nbytes;
+
+       unsigned nbytes;
 {
        register union store *p, *q;
        register nw;
 {
        register union store *p, *q;
        register nw;
@@ -108,17 +117,19 @@ found:
        allocp = p + nw;
        ASSERT(allocp<=alloct,(char *));
        if(q>allocp) {
        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));
 }
 
                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)
 free(ap)
-register char *ap;
+
+       register char *ap;
 {
        register union store *p = (union store *)ap;
 
 {
        register union store *p = (union store *)ap;
 
@@ -132,40 +143,6 @@ register char *ap;
        return(NULL);
 }
 
        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()
 {
 #ifdef debug
 allock()
 {
@@ -184,4 +161,3 @@ allock()
 #endif
 }
 #endif
 #endif
 }
 #endif
-