diff options
Diffstat (limited to 'gnu/usr.bin/ld/rtld/malloc.c')
-rw-r--r-- | gnu/usr.bin/ld/rtld/malloc.c | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/gnu/usr.bin/ld/rtld/malloc.c b/gnu/usr.bin/ld/rtld/malloc.c index 4e09f9cb48e..e611c370cc6 100644 --- a/gnu/usr.bin/ld/rtld/malloc.c +++ b/gnu/usr.bin/ld/rtld/malloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: malloc.c,v 1.3 2002/07/10 17:28:16 marc Exp $ */ +/* $OpenBSD: malloc.c,v 1.4 2002/07/15 21:05:57 marc Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -35,7 +35,7 @@ #if defined(LIBC_SCCS) && !defined(lint) /*static char *sccsid = "from: @(#)malloc.c 5.11 (Berkeley) 2/23/91";*/ -static char *rcsid = "$OpenBSD: malloc.c,v 1.3 2002/07/10 17:28:16 marc Exp $"; +static char *rcsid = "$OpenBSD: malloc.c,v 1.4 2002/07/15 21:05:57 marc Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -153,8 +153,8 @@ void * malloc(nbytes) size_t nbytes; { - union overhead *op; - int bucket, n; + union overhead *op; + int bucket, n; unsigned amt; /* @@ -166,10 +166,10 @@ malloc(nbytes) if (morepages(NPOOLPAGES) == 0) return NULL; op = (union overhead *)(pagepool_start); - n = n - sizeof (*op) - ((int)op & (n - 1)); + n = n - sizeof (*op) - ((int)op & (n - 1)); if (n < 0) n += pagesz; - if (n) { + if (n) { pagepool_start += n; } bucket = 0; @@ -208,17 +208,17 @@ malloc(nbytes) * If nothing in hash bucket right now, * request more memory from the system. */ - if ((op = nextf[bucket]) == NULL) { - morecore(bucket); - if ((op = nextf[bucket]) == NULL) - return (NULL); + if ((op = nextf[bucket]) == NULL) { + morecore(bucket); + if ((op = nextf[bucket]) == NULL) + return (NULL); } /* remove from linked list */ - nextf[bucket] = op->ov_next; + nextf[bucket] = op->ov_next; op->ov_magic = MAGIC; op->ov_index = bucket; #ifdef MSTATS - nmalloc[bucket]++; + nmalloc[bucket]++; #endif #ifdef RCHECK /* @@ -227,9 +227,9 @@ malloc(nbytes) */ op->ov_size = (nbytes + RSLOP - 1) & ~(RSLOP - 1); op->ov_rmagic = RMAGIC; - *(u_short *)((caddr_t)(op + 1) + op->ov_size) = RMAGIC; + *(u_short *)((caddr_t)(op + 1) + op->ov_size) = RMAGIC; #endif - return ((char *)(op + 1)); + return ((char *)(op + 1)); } /* @@ -239,10 +239,10 @@ static void morecore(bucket) int bucket; { - union overhead *op; + union overhead *op; int sz; /* size of desired block */ - int amt; /* amount to allocate */ - int nblks; /* how many blocks we get */ + int amt; /* amount to allocate */ + int nblks; /* how many blocks we get */ /* * sbrk_size <= 0 only for big, FLUFFY, requests (about @@ -257,7 +257,7 @@ morecore(bucket) #endif if (sz < pagesz) { amt = pagesz; - nblks = amt / sz; + nblks = amt / sz; } else { amt = sz + pagesz; nblks = 1; @@ -272,39 +272,39 @@ morecore(bucket) * Add new memory allocated to that on * free list for this hash bucket. */ - nextf[bucket] = op; - while (--nblks > 0) { + nextf[bucket] = op; + while (--nblks > 0) { op->ov_next = (union overhead *)((caddr_t)op + sz); op = (union overhead *)((caddr_t)op + sz); - } + } } void free(cp) void *cp; { - int size; + int size; union overhead *op; - if (cp == NULL) - return; + if (cp == NULL) + return; op = (union overhead *)((caddr_t)cp - sizeof (union overhead)); #ifdef DEBUG - ASSERT(op->ov_magic == MAGIC); /* make sure it was in use */ + ASSERT(op->ov_magic == MAGIC); /* make sure it was in use */ #else if (op->ov_magic != MAGIC) return; /* sanity */ #endif #ifdef RCHECK - ASSERT(op->ov_rmagic == RMAGIC); + ASSERT(op->ov_rmagic == RMAGIC); ASSERT(*(u_short *)((caddr_t)(op + 1) + op->ov_size) == RMAGIC); #endif - size = op->ov_index; - ASSERT(size < NBUCKETS); + size = op->ov_index; + ASSERT(size < NBUCKETS); op->ov_next = nextf[size]; /* also clobbers ov_magic */ - nextf[size] = op; + nextf[size] = op; #ifdef MSTATS - nmalloc[size]--; + nmalloc[size]--; #endif } @@ -326,14 +326,14 @@ realloc(cp, nbytes) void *cp; size_t nbytes; { - u_int onb; + u_int onb; int i; union overhead *op; - char *res; + char *res; int was_alloced = 0; - if (cp == NULL) - return (malloc(nbytes)); + if (cp == NULL) + return (malloc(nbytes)); op = (union overhead *)((caddr_t)cp - sizeof (union overhead)); if (op->ov_magic == MAGIC) { was_alloced++; @@ -380,11 +380,11 @@ realloc(cp, nbytes) } else free(cp); } - if ((res = malloc(nbytes)) == NULL) - return (NULL); - if (cp != res) /* common optimization if "compacting" */ + if ((res = malloc(nbytes)) == NULL) + return (NULL); + if (cp != res) /* common optimization if "compacting" */ bcopy(cp, res, (nbytes < onb) ? nbytes : onb); - return (res); + return (res); } /* @@ -422,24 +422,24 @@ findbucket(freep, srchlen) mstats(s) char *s; { - int i, j; - union overhead *p; - int totfree = 0, - totused = 0; - - fprintf(stderr, "Memory allocation statistics %s\nfree:\t", s); - for (i = 0; i < NBUCKETS; i++) { - for (j = 0, p = nextf[i]; p; p = p->ov_next, j++) - ; - fprintf(stderr, " %d", j); - totfree += j * (1 << (i + 3)); - } - fprintf(stderr, "\nused:\t"); - for (i = 0; i < NBUCKETS; i++) { - fprintf(stderr, " %d", nmalloc[i]); - totused += nmalloc[i] * (1 << (i + 3)); - } - fprintf(stderr, "\n\tTotal in use: %d, total free: %d\n", + int i, j; + union overhead *p; + int totfree = 0, + totused = 0; + + fprintf(stderr, "Memory allocation statistics %s\nfree:\t", s); + for (i = 0; i < NBUCKETS; i++) { + for (j = 0, p = nextf[i]; p; p = p->ov_next, j++) + ; + fprintf(stderr, " %d", j); + totfree += j * (1 << (i + 3)); + } + fprintf(stderr, "\nused:\t"); + for (i = 0; i < NBUCKETS; i++) { + fprintf(stderr, " %d", nmalloc[i]); + totused += nmalloc[i] * (1 << (i + 3)); + } + fprintf(stderr, "\n\tTotal in use: %d, total free: %d\n", totused, totfree); } #endif |