|
|
1.1 ! root 1: /* $Header: /kernel/kersrc/coh.286/RCS/alloc.c,v 1.1 92/07/17 15:17:49 bin Exp Locker: bin $ */ ! 2: /* (lgl- ! 3: * The information contained herein is a trade secret of Mark Williams ! 4: * Company, and is confidential information. It is provided under a ! 5: * license agreement, and may be copied or disclosed only under the ! 6: * terms of that agreement. Any reproduction or disclosure of this ! 7: * material without the express written authorization of Mark Williams ! 8: * Company or persuant to the license agreement is unlawful. ! 9: * ! 10: * COHERENT Version 2.3.37 ! 11: * Copyright (c) 1982, 1983, 1984. ! 12: * An unpublished work by Mark Williams Company, Chicago. ! 13: * All rights reserved. ! 14: -lgl) */ ! 15: /* ! 16: * Coherent. ! 17: * Storage allocator. ! 18: * ! 19: * $Log: alloc.c,v $ ! 20: * Revision 1.1 92/07/17 15:17:49 bin ! 21: * Initial revision ! 22: * ! 23: * Revision 1.1 88/03/24 16:13:25 src ! 24: * Initial revision ! 25: * ! 26: */ ! 27: #include <sys/coherent.h> ! 28: #include <sys/alloc.h> ! 29: #include <errno.h> ! 30: #include <sys/proc.h> ! 31: ! 32: /* ! 33: * Create an arena. ! 34: */ ! 35: ALL * ! 36: setarena(cp, n) ! 37: register char *cp; ! 38: { ! 39: register ALL *ap1; ! 40: register ALL *ap2; ! 41: ! 42: if ((char *)(ap1=align(cp)) < (char *)cp) ! 43: ap1++; ! 44: if ((ap2=align(&cp[n])-1) < ap1) ! 45: panic("Arena %o too small", (int) cp); ! 46: ap1->a_link = (char *)ap2; ! 47: ap2->a_link = (char *)ap1; ! 48: setused(ap2); ! 49: return (ap1); ! 50: } ! 51: ! 52: /* ! 53: * Allocate `l' bytes of memory. ! 54: */ ! 55: char * ! 56: alloc(apq, l) ! 57: ALL *apq; ! 58: unsigned l; ! 59: { ! 60: register ALL *ap; ! 61: register ALL *ap1; ! 62: register ALL *ap2; ! 63: register unsigned i; ! 64: register unsigned n; ! 65: register unsigned s; ! 66: ! 67: n = 1 + (l + sizeof(ALL) - 1) / sizeof(ALL); ! 68: for (i=0; i<2; i++) { ! 69: for (ap1=apq; link(ap1)!=apq; ap1=link(ap1)) { ! 70: if (ap1 == NULL) ! 71: panic("Corrupt arena"); ! 72: if (tstfree(ap1)) { ! 73: for (ap2=link(ap1); tstfree(ap2); ap2=link(ap2)) ! 74: if (ap2 == apq) ! 75: break; ! 76: ap1->a_link = (char *)ap2; ! 77: if ((s=ap2-ap1) >= n) { ! 78: if (s > n) { ! 79: if (i == 0) ! 80: continue; ! 81: ap = &ap1[n]; ! 82: ap->a_link = (char *)ap2; ! 83: ap1->a_link = (char *)ap; ! 84: } ! 85: setused(ap1); ! 86: kclear((char *)ap1->a_data, l); ! 87: return (ap1->a_data); ! 88: } ! 89: } ! 90: } ! 91: } ! 92: u.u_error = EKSPACE; ! 93: return (NULL); ! 94: } ! 95: ! 96: /* ! 97: * Free memory. ! 98: */ ! 99: free(cp) ! 100: char *cp; ! 101: { ! 102: register ALL *ap; ! 103: extern char end; ! 104: ! 105: ap = ((ALL *)cp) - 1; ! 106: if (ap<(ALL *)&end || tstfree(ap)) ! 107: panic("Bad free %o\n", (unsigned)cp); ! 108: setfree(ap); ! 109: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.