|
|
1.1 ! root 1: /* getstk.c - getstk */ ! 2: ! 3: #include <conf.h> ! 4: #include <kernel.h> ! 5: #include <mem.h> ! 6: ! 7: /*------------------------------------------------------------------------ ! 8: * getstk -- allocate stack memory, returning address of topmost int ! 9: *------------------------------------------------------------------------ ! 10: */ ! 11: SYSCALL *getstk(nbytes) ! 12: unsigned int nbytes; ! 13: { ! 14: PStype ps; ! 15: struct mblock *p, *q; /* q follows p along memlist */ ! 16: struct mblock *fits, *fitsq; ! 17: unsigned len; ! 18: ! 19: disable(ps); ! 20: if (nbytes == 0) { ! 21: restore(ps); ! 22: return( (int *)SYSERR ); ! 23: } ! 24: nbytes = (unsigned)roundew(nbytes); ! 25: fits = (struct mblock *)NULL; ! 26: q = &memlist; ! 27: for (p = q->mnext ; (char *)p != NULL ; q = p,p = p->mnext) ! 28: if ( p->mlen >= nbytes) { ! 29: fitsq = q; ! 30: fits = p; ! 31: } ! 32: if ((char *)fits == NULL) { ! 33: restore(ps); ! 34: return( (int *)SYSERR ); ! 35: } ! 36: if (nbytes == (len = fits->mlen) ) { ! 37: fitsq->mnext = fits->mnext; ! 38: } else { ! 39: fits->mlen -= nbytes; ! 40: } ! 41: fits = (struct mblock *)((unsigned)fits + len - sizeof(int)); ! 42: restore(ps); ! 43: return( (int *)fits ); ! 44: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.