|
|
1.1 root 1: /* $Header: /newbits/286_KERNEL/USRSRC/coh/RCS/alloc.c,v 1.1 92/01/09 13:25:51 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/01/09 13:25:51 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: #include <sys/uproc.h>
32:
33: /*
34: * Create an arena.
35: */
36: ALL *
37: setarena(cp, n)
38: register char *cp;
39: {
40: register ALL *ap1;
41: register ALL *ap2;
42:
43: if ((char *)(ap1=align(cp)) < (char *)cp)
44: ap1++;
45: if ((ap2=align(&cp[n])-1) < ap1)
46: panic("Arena %o too small", (int) cp);
47: ap1->a_link = (char *)ap2;
48: ap2->a_link = (char *)ap1;
49: setused(ap2);
50: return (ap1);
51: }
52:
53: /*
54: * Allocate `l' bytes of memory.
55: */
56: char *
57: alloc(apq, l)
58: ALL *apq;
59: unsigned l;
60: {
61: register ALL *ap;
62: register ALL *ap1;
63: register ALL *ap2;
64: register unsigned i;
65: register unsigned n;
66: register unsigned s;
67:
68: n = 1 + (l + sizeof(ALL) - 1) / sizeof(ALL);
69: for (i=0; i<2; i++) {
70: for (ap1=apq; link(ap1)!=apq; ap1=link(ap1)) {
71: if (ap1 == NULL)
72: panic("Corrupt arena");
73: if (tstfree(ap1)) {
74: for (ap2=link(ap1); tstfree(ap2); ap2=link(ap2))
75: if (ap2 == apq)
76: break;
77: ap1->a_link = (char *)ap2;
78: if ((s=ap2-ap1) >= n) {
79: if (s > n) {
80: if (i == 0)
81: continue;
82: ap = &ap1[n];
83: ap->a_link = (char *)ap2;
84: ap1->a_link = (char *)ap;
85: }
86: setused(ap1);
87: kclear((char *)ap1->a_data, l);
88: return (ap1->a_data);
89: }
90: }
91: }
92: }
93: u.u_error = EKSPACE;
94: return (NULL);
95: }
96:
97: /*
98: * Free memory.
99: */
100: free(cp)
101: char *cp;
102: {
103: register ALL *ap;
104: extern char end;
105:
106: ap = ((ALL *)cp) - 1;
107: if (ap<(ALL *)&end || tstfree(ap))
108: panic("Bad free %o\n", (unsigned)cp);
109: setfree(ap);
110: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.