annotate src/ralloc.c @ 293:7e7575d7b6d0

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Thu, 20 Jun 1991 10:29:36 +0000
parents 49342840ba00
children 8c615e453683
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Block-relocating memory allocator.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2 Copyright (C) 1990 Free Software Foundation, Inc.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 the Free Software Foundation; either version 1, or (at your option)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 any later version.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 GNU General Public License for more details.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 /* NOTES:
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 Only relocate the blocs neccessary for SIZE in r_alloc_sbrk,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 rather than all of them. This means allowing for a possible
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 hole between the first bloc and the end of malloc storage. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 #include "config.h"
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27 #include "lisp.h" /* Needed for xterm.h */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 #undef NULL
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 #include "mem_limits.h"
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 #include "xterm.h" /* Needed for BLOCK_INPUT */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 #define NIL ((POINTER) 0)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 /* System call to set the break value. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 extern POINTER sbrk ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 /* The break value, as seen by malloc (). */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 static POINTER virtual_break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 /* The break value, viewed by the relocatable blocs. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 static POINTER break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 /* The REAL (i.e., page aligned) break value of the process. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 static POINTER page_break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 /* Macros for rounding. Note that rounding to any value is possible
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 by changing the definition of PAGE. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 #define PAGE (getpagesize ())
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 #define ALIGNED(addr) (((unsigned int) (addr) & (PAGE - 1)) == 0)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 #define ROUNDUP(size) (((unsigned int) (size) + PAGE) & ~(PAGE - 1))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 #define ROUND_TO_PAGE(addr) (addr & (~(PAGE - 1)))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 #define EXCEEDS_ELISP_PTR(ptr) ((unsigned int) (ptr) >> VALBITS)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 /* Level of warnings issued. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 static int warnlevel;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 /* Function to call to issue a warning;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 0 means don't issue them. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 static void (*warnfunction) ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 static void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 check_memory_limits (address)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 POINTER address;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 SIZE data_size = address - data_space_start;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 switch (warnlevel)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 case 0:
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 if (data_size > (lim_data / 4) * 3)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 warnlevel++;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 (*warnfunction) ("Warning: past 75% of memory limit");
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 break;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 case 1:
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 if (data_size > (lim_data / 20) * 17)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 warnlevel++;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 (*warnfunction) ("Warning: past 85% of memory limit");
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 break;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 case 2:
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 if (data_size > (lim_data / 20) * 19)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 warnlevel++;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 (*warnfunction) ("Warning: past 95% of memory limit");
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 break;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 default:
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 (*warnfunction) ("Warning: past acceptable memory limits");
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 break;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 if (EXCEEDS_ELISP_PTR (address))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 (*warnfunction) ("Warning: memory in use exceeds lisp pointer size");
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 /* Obtain SIZE bytes of space. If enough space is not presently available
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 in our process reserve, (i.e., (page_break_value - break_value)),
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 this means getting more page-aligned space from the system. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 static void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 obtain (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 SIZE already_available = page_break_value - break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 if (already_available < size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 SIZE get = ROUNDUP (size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 if (warnfunction)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 check_memory_limits (page_break_value);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 if (((int) sbrk (get)) < 0)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 page_break_value += get;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 break_value += size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 /* Obtain SIZE bytes of space and return a pointer to the new area. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 static POINTER
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 get_more_space (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 POINTER ptr = break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 obtain (size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 return ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 /* Note that SIZE bytes of space have been relinquished by the process.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 If SIZE is more than a page, return the space the system. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 static void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 relinquish (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 SIZE page_part = ROUND_TO_PAGE (size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 if (page_part)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 if (((int) (sbrk (- page_part))) < 0)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 page_break_value -= page_part;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 break_value -= size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 bzero (break_value, (size - page_part));
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 typedef struct bp
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 struct bp *next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 struct bp *prev;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 POINTER *variable;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 POINTER data;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 } *bloc_ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 #define NIL_BLOC ((bloc_ptr) 0)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 #define BLOC_PTR_SIZE (sizeof (struct bp))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 /* Head and tail of the list of relocatable blocs. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 static bloc_ptr first_bloc, last_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 /* Declared in dispnew.c, this version dosen't fuck up if regions overlap. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 extern void safe_bcopy ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 /* Find the bloc reference by the address in PTR. Returns a pointer
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 to that block. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 static bloc_ptr
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 find_bloc (ptr)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 POINTER *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 register bloc_ptr p = first_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 while (p != NIL_BLOC)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 if (p->variable == ptr && p->data == *ptr)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 return p;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 p = p->next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 return p;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 /* Allocate a bloc of SIZE bytes and append it to the chain of blocs.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 Returns a pointer to the new bloc. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 static bloc_ptr
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 get_bloc (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 register bloc_ptr new_bloc = (bloc_ptr) malloc (BLOC_PTR_SIZE);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 new_bloc->data = get_more_space (size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 new_bloc->size = size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 new_bloc->next = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 new_bloc->variable = NIL;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 if (first_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 new_bloc->prev = last_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 last_bloc->next = new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 last_bloc = new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 else
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 first_bloc = last_bloc = new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 new_bloc->prev = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 return new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 /* Relocate all blocs from BLOC on upward in the list to the zone
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 indicated by ADDRESS. Direction of relocation is determined by
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 the position of ADDRESS relative to BLOC->data.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 Note that ordering of blocs is not affected by this function. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 static void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 relocate_some_blocs (bloc, address)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 bloc_ptr bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 POINTER address;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 register bloc_ptr b;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 POINTER data_zone = bloc->data;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 register SIZE data_zone_size = 0;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 register SIZE offset = bloc->data - address;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 POINTER new_data_zone = data_zone - offset;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 for (b = bloc; b != NIL_BLOC; b = b->next)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 data_zone_size += b->size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 b->data -= offset;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 *b->variable = b->data;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 safe_bcopy (data_zone, new_data_zone, data_zone_size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 /* Free BLOC from the chain of blocs, relocating any blocs above it
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 and returning BLOC->size bytes to the free area. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 static void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 free_bloc (bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 bloc_ptr bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 if (bloc == first_bloc && bloc == last_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 first_bloc = last_bloc = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 else if (bloc == last_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 last_bloc = bloc->prev;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 last_bloc->next = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 else if (bloc == first_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 first_bloc = bloc->next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 first_bloc->prev = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 relocate_some_blocs (bloc->next, bloc->data);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 else
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 bloc->next->prev = bloc->prev;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 bloc->prev->next = bloc->next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 relocate_some_blocs (bloc->next, bloc->data);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 relinquish (bloc->size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 free (bloc);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 static int use_relocatable_buffers;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 /* Obtain SIZE bytes of storage from the free pool, or the system,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 as neccessary. If relocatable blocs are in use, this means
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 relocating them. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 POINTER
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 r_alloc_sbrk (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 long size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 POINTER ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 if (! use_relocatable_buffers)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 return sbrk (size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 if (size > 0)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 obtain (size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 if (first_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 relocate_some_blocs (first_bloc, first_bloc->data + size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 bzero (virtual_break_value, size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 else if (size < 0)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 if (first_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 relocate_some_blocs (first_bloc, first_bloc->data + size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 relinquish (- size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 ptr = virtual_break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 virtual_break_value += size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 return ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 /* Allocate a relocatable bloc of storage of size SIZE. A pointer to
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 the data is returned in *PTR. PTR is thus the address of some variable
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 which will use the data area. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 POINTER
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 r_alloc (ptr, size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 POINTER *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 register bloc_ptr new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 BLOCK_INPUT;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 new_bloc = get_bloc (size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 new_bloc->variable = ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 *ptr = new_bloc->data;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 UNBLOCK_INPUT;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 return *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 /* Free a bloc of relocatable storage whose data is pointed to by PTR. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 r_alloc_free (ptr)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 register POINTER *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 register bloc_ptr dead_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 BLOCK_INPUT;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 dead_bloc = find_bloc (ptr);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 if (dead_bloc == NIL_BLOC)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 free_bloc (dead_bloc);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 UNBLOCK_INPUT;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 /* Given a pointer at address PTR to relocatable data, resize it
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 to SIZE. This is done by obtaining a new block and freeing the
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 old, unless SIZE is less than or equal to the current bloc size,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 in which case nothing happens and the current value is returned.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 The contents of PTR is changed to reflect the new bloc, and this
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 value is returned. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 POINTER
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 r_re_alloc (ptr, size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 POINTER *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 register bloc_ptr old_bloc, new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 BLOCK_INPUT;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 old_bloc = find_bloc (ptr);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 if (old_bloc == NIL_BLOC)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 if (size <= old_bloc->size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 return *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 new_bloc = get_bloc (size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 new_bloc->variable = ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 safe_bcopy (old_bloc->data, new_bloc->data, old_bloc->size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 *ptr = new_bloc->data;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 free_bloc (old_bloc);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 UNBLOCK_INPUT;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 return *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 /* The hook `malloc' uses for the function which gets more space
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 from the system. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 extern POINTER (*__morecore) ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 /* Intialize various things for memory allocation. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402 malloc_init (start, warn_func)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 POINTER start;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 void (*warn_func) ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 static int malloc_initialized = 0;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 if (start)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 data_space_start = start;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 if (malloc_initialized)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 return;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 malloc_initialized = 1;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 __morecore = r_alloc_sbrk;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 virtual_break_value = break_value = sbrk (0);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 page_break_value = (POINTER) ROUNDUP (break_value);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 bzero (break_value, (page_break_value - break_value));
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 use_relocatable_buffers = 1;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 lim_data = 0;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 warnlevel = 0;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 warnfunction = warn_func;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 get_lim_data ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 }