libsrc/alloc.cxx File Reference

#include <unistd.h>
#include <sys/errno.h>
#include "udanax.h"

Include dependency graph for alloc.cxx:

Include dependency graph

Go to the source code of this file.

Functions

void lookatalloc ()
 ???

int statusofalloc (char *)
 ???

int validallocthinge (char *ptr)
 ???

int checkalloc (char *c)
 ???

HEADERweresurethatthisisourmorecore ()
 ???

int * falloc (unsigned nbytes)
 ???

void ffree (char *ap)
 ???


Variables

int ingrimreaper
int incrementalallocsize
int allocsize
HEADER base
HEADERallocp = NULL
HEADER baseallocated
int flag = 0
char * zzalloctop = 0 *zzallocbot = 0
int alloccount = 0


Function Documentation

int checkalloc char *  c  ) 
 

???

(to be defined)

Definition at line 186 of file alloc.cxx.

References assert, base, debug, flag, HEADER, L, header::s, statusofalloc(), validallocthinge(), and zzalloctop.

00188 {
00189     HEADER *r, *oldr;
00190     unsigned size;
00191 
00192     if (!flag)
00193         return /*BUG: original code returned nothing, I guess I'll return a zero*/ 0;
00194 
00195     if (debug && *c)
00196         L("%s", c);
00197 
00198     unsigned oldsize = 0;
00199     for (oldr = r = base.s.ptr; flag && (r != &base) && (r != (HEADER *) zzalloctop); r = r + r->s.size) {
00200         size = r->s.size;
00201         validallocthinge((char *) r);
00202         if (r->s.size == 0 && r != (HEADER *) zzalloctop) {
00203             L("checkalloc glorphed with ptr = %x bottom = %x top = %x\n", (int) r, (int) zzallocbot, (int) zzalloctop);
00204             statusofalloc("");
00205             assert(0); // found zero size in alloced stuff
00206             return 1;
00207         }
00208         oldr = r;
00209         oldsize = size;
00210     }
00211     return true;
00212 }

int* falloc unsigned  nbytes  ) 
 

???

(to be defined)

Definition at line 261 of file alloc.cxx.

References alloccount, allocp, assert, base, HEADER, ingrimreaper, L, NULL, header::s, and weresurethatthisisourmorecore().

Referenced by ealloc(), and initqueues().

00263 {
00264     register HEADER *p, *q;
00265     register unsigned nunits;
00266 
00267 /* if (errno) { if (errno != ENOTTY) perror ("xumain/backend/alloc"); errno = 0; } */
00268 
00269     if (ingrimreaper) {
00270         L("really error in falloc called from under grimreaper\n");
00271         assert(0); // falloc called from under grimreaper
00272     }
00273 
00274     assert(nbytes > 0); // falloc called with nbytes = 0
00275 
00276     //L("falloc called with %d\n",nbytes);
00277 
00278     alloccount++;
00279     nunits = 1 + (nbytes + sizeof(HEADER) - 1) / sizeof(HEADER);
00280     if ((q = allocp) == NULL) {
00281         base.s.ptr = allocp = q = &base;
00282         base.s.size = 0;
00283     } else {
00284 /* checkalloc(""); */
00285     }
00286     for (p = q->s.ptr;; q = p, p = p->s.ptr) {
00287         if (p->s.size >= nunits) {
00288             if (p->s.size == nunits)
00289                 q->s.ptr = p->s.ptr;
00290             else {
00291                 p->s.size -= nunits;
00292                 p += p->s.size;
00293                 p->s.size = nunits;
00294             }
00295             p->s.ptr = NULL;
00296             allocp = q;
00297             return (int *) (p + 1);
00298         }
00299         if (p == allocp)
00300             if ((p = weresurethatthisisourmorecore()) == NULL)
00301                 return NULL;
00302     }
00303 }

void ffree char *  ap  ) 
 

???

(to be defined)

Definition at line 313 of file alloc.cxx.

References allocp, assert, flag, HEADER, header::s, and validallocthinge().

Referenced by efree(), weresurethatthisisourmorecore(), and xgrabmorecore().

00315 {
00316     register HEADER *p, *q;
00317 
00318 /* if (errno) { if (errno != ENOTTY) perror ("xumain/backend/free"); errno = 0; } */
00319     p = (HEADER *) ap - 1;
00320     if (flag) {
00321 
00322         if (!validallocthinge((char *) p))
00323             assert(0); // wierd free in alloc
00324     }
00325 
00326     // memset(ap, 0, (p->s.size - 1) * sizeof(HEADER));
00327 
00328     for (q = allocp; !(p > q && p < q->s.ptr); q = q->s.ptr) {
00329         if (q >= q->s.ptr && (p > q || p < q->s.ptr)) {
00330             break;
00331         }
00332     }
00333 
00334     if (p + p->s.size == q->s.ptr) {
00335         p->s.size += q->s.ptr->s.size;
00336         p->s.ptr = q->s.ptr->s.ptr;
00337     } else {
00338         p->s.ptr = q->s.ptr;
00339     }
00340     if (q + q->s.size == p) {
00341         q->s.size += p->s.size;
00342         q->s.ptr = p->s.ptr;
00343     } else {
00344         q->s.ptr = p;
00345     }
00346     allocp = q;
00347 /* checkalloc(""); */
00348 }

void lookatalloc  ) 
 

???

(to be defined)

Definition at line 116 of file alloc.cxx.

References baseallocated, and lookatalloc2().

Referenced by playwithalloc().

00117 {
00118     lookatalloc2(&baseallocated);
00119 }

int statusofalloc char *   )  [static]
 

???

(to be defined)

Definition at line 129 of file alloc.cxx.

References base, flag, HEADER, L, and header::s.

Referenced by checkalloc().

00131 {
00132     unsigned number, maxsize, cumsize;
00133 
00134 /* checkalloc (c); */
00135     number = maxsize = cumsize = 0;
00136 
00137     HEADER *r;
00138     for (r = base.s.ptr; flag && (r != &base); r = r->s.ptr) {
00139         maxsize = (maxsize > r->s.size ? maxsize : r->s.size);
00140         cumsize += r->s.size;
00141         number++;
00142     }
00143     L("%d free hunks %d maxsize %d total free\n", number, maxsize, cumsize);
00144     return true;
00145 }

int validallocthinge char *  ptr  )  [static]
 

???

(to be defined)

Definition at line 155 of file alloc.cxx.

Referenced by checkalloc(), and ffree().

00157 {
00158     return 1;
00159 
00160 //    if (!flag)
00161 //        return true;
00162 //
00163 //    HEADER *p = (HEADER *) ptr;
00164 //    if (p->s.size == 0 && p != * (HEADER *)zzalloctop) {
00165 //        L("validallocthinge called with ptr = %x bottom = %x top = %x\n", ptr, zzallocbot, zzalloctop);
00166 //        statusofalloc("");
00167 //        assert(0); // attempt to free zero size thing
00168 //    }
00169 //
00170 //    if (flag && (unsigned) ptr > (unsigned) zzalloctop || (unsigned) ptr < (unsigned) zzallocbot) {
00171 //        L("validallocthinge called with ptr = %x bottom = %x top = %xn", ptr, zzallocbot, zzalloctop);
00172 //        assert(0); // bad validity check in alloc
00173 //        return 0;
00174 //    }
00175 //    return true;
00176 }

HEADER* weresurethatthisisourmorecore  )  [static]
 

???

(to be defined)

Definition at line 222 of file alloc.cxx.

References allocp, allocsize, assert, baseallocated, ffree(), flag, HEADER, NULL, header::s, and zzalloctop.

Referenced by falloc().

00223 {
00224     HEADER *up;
00225     int temp;
00226 
00227     if (flag)
00228         return NULL;
00229 
00230     char *cp   = (char *) sbrk(allocsize);
00231     zzalloctop = (char *)cp + allocsize;
00232     zzallocbot = (char *)cp;
00233 
00234     if ((int) cp == -1) {
00235         flag = 1;
00236         return NULL;
00237     }
00238 
00239     up   = (HEADER *) cp;
00240     temp = up->s.size = ((unsigned) allocsize) / sizeof(HEADER);
00241 
00242     if (temp == 0)
00243         assert(0); // this dumb fucker doesnt do arithmetic right
00244 
00245     baseallocated.s.ptr = (HEADER *) cp;
00246     baseallocated.s.size = temp;
00247     ffree((char *)(cp + sizeof(HEADER) /* up +1 */ ));
00248     flag = 1;
00249 
00250     return allocp;
00251 }


Variable Documentation

int alloccount = 0 [static]
 

Definition at line 106 of file alloc.cxx.

Referenced by falloc().

HEADER* allocp = NULL [static]
 

Definition at line 101 of file alloc.cxx.

Referenced by falloc(), ffree(), and weresurethatthisisourmorecore().

int allocsize
 

Definition at line 98 of file alloc.cxx.

HEADER base [static]
 

Definition at line 100 of file alloc.cxx.

Referenced by checkalloc(), falloc(), and statusofalloc().

HEADER baseallocated [static]
 

Definition at line 102 of file alloc.cxx.

Referenced by lookatalloc(), and weresurethatthisisourmorecore().

int flag = 0 [static]
 

Definition at line 104 of file alloc.cxx.

Referenced by checkalloc(), ffree(), statusofalloc(), and weresurethatthisisourmorecore().

int incrementalallocsize
 

Definition at line 97 of file alloc.cxx.

int ingrimreaper
 

Definition at line 95 of file alloc.cxx.

Referenced by falloc(), and grimlyreap().

char* zzalloctop = 0 *zzallocbot = 0 [static]
 

Definition at line 105 of file alloc.cxx.

Referenced by checkalloc(), and weresurethatthisisourmorecore().


Generated on Sun Aug 21 04:18:23 2005 for Udanax-Green by doxygen1.3.4