aboutsummaryrefslogtreecommitdiffstats
path: root/src/ralloc.c
diff options
context:
space:
mode:
authorJim Blandy1992-03-14 19:09:32 +0000
committerJim Blandy1992-03-14 19:09:32 +0000
commit956ace37a8ec4df40a07940c08d5aa6d10e8b073 (patch)
tree47a79680bb2980f34271e67401a3c0f545045a51 /src/ralloc.c
parentfb955dfadd6fd6031b50561e184610c56f04a2cc (diff)
downloademacs-956ace37a8ec4df40a07940c08d5aa6d10e8b073.tar.gz
emacs-956ace37a8ec4df40a07940c08d5aa6d10e8b073.zip
*** empty log message ***
Diffstat (limited to 'src/ralloc.c')
-rw-r--r--src/ralloc.c66
1 files changed, 45 insertions, 21 deletions
diff --git a/src/ralloc.c b/src/ralloc.c
index d2dae3637a0..fe22ae4ffe1 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -1,5 +1,5 @@
1/* Block-relocating memory allocator. 1/* Block-relocating memory allocator.
2 Copyright (C) 1990 Free Software Foundation, Inc. 2 Copyright (C) 1992 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -24,14 +24,15 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24 hole between the first bloc and the end of malloc storage. */ 24 hole between the first bloc and the end of malloc storage. */
25 25
26#include "config.h" 26#include "config.h"
27#include "lisp.h" /* Needed for xterm.h */ 27#include "lisp.h" /* Needed for VALBITS. */
28#undef NULL 28#undef NULL
29#include "mem_limits.h" 29#include "mem_limits.h"
30#include "xterm.h" /* Needed for BLOCK_INPUT */
31 30
32#define NIL ((POINTER) 0) 31#define NIL ((POINTER) 0)
33 32
34 33
34/* Declarations for working with the malloc, ralloc, and system breaks. */
35
35/* System call to set the break value. */ 36/* System call to set the break value. */
36extern POINTER sbrk (); 37extern POINTER sbrk ();
37 38
@@ -52,6 +53,8 @@ static POINTER page_break_value;
52#define ROUND_TO_PAGE(addr) (addr & (~(PAGE - 1))) 53#define ROUND_TO_PAGE(addr) (addr & (~(PAGE - 1)))
53#define EXCEEDS_ELISP_PTR(ptr) ((unsigned int) (ptr) >> VALBITS) 54#define EXCEEDS_ELISP_PTR(ptr) ((unsigned int) (ptr) >> VALBITS)
54 55
56/* Managing "almost out of memory" warnings. */
57
55/* Level of warnings issued. */ 58/* Level of warnings issued. */
56static int warnlevel; 59static int warnlevel;
57 60
@@ -100,6 +103,8 @@ check_memory_limits (address)
100 memory_full (); 103 memory_full ();
101} 104}
102 105
106/* Functions to get and return memory from the system. */
107
103/* Obtain SIZE bytes of space. If enough space is not presently available 108/* Obtain SIZE bytes of space. If enough space is not presently available
104 in our process reserve, (i.e., (page_break_value - break_value)), 109 in our process reserve, (i.e., (page_break_value - break_value)),
105 this means getting more page-aligned space from the system. */ 110 this means getting more page-aligned space from the system. */
@@ -112,7 +117,7 @@ obtain (size)
112 117
113 if (already_available < size) 118 if (already_available < size)
114 { 119 {
115 SIZE get = ROUNDUP (size); 120 SIZE get = ROUNDUP (size - already_available);
116 121
117 if (warnfunction) 122 if (warnfunction)
118 check_memory_limits (page_break_value); 123 check_memory_limits (page_break_value);
@@ -138,26 +143,37 @@ get_more_space (size)
138} 143}
139 144
140/* Note that SIZE bytes of space have been relinquished by the process. 145/* Note that SIZE bytes of space have been relinquished by the process.
141 If SIZE is more than a page, return the space the system. */ 146 If SIZE is more than a page, return the space to the system. */
142 147
143static void 148static void
144relinquish (size) 149relinquish (size)
145 SIZE size; 150 SIZE size;
146{ 151{
147 SIZE page_part = ROUND_TO_PAGE (size); 152 POINTER new_page_break;
148 153
149 if (page_part) 154 break_value -= size;
155 new_page_break = (POINTER) ROUNDUP (break_value);
156
157 if (new_page_break != page_break_value)
150 { 158 {
151 if (((int) (sbrk (- page_part))) < 0) 159 if (((int) (sbrk ((char *) new_page_break
160 - (char *) page_break_value))) < 0)
152 abort (); 161 abort ();
153 162
154 page_break_value -= page_part; 163 page_break_value = new_page_break;
155 } 164 }
156 165
157 break_value -= size; 166 /* Zero the space from the end of the "official" break to the actual
158 bzero (break_value, (size - page_part)); 167 break, so that bugs show up faster. */
168 bzero (break_value, ((char *) page_break_value - (char *) break_value));
159} 169}
160 170
171/* The meat - allocating, freeing, and relocating blocs. */
172
173/* These structures are allocated in the malloc arena.
174 The linked list is kept in order of increasing '.data' members.
175 The data blocks abut each other; if b->next is non-nil, then
176 b->data + b->size == b->next->data. */
161typedef struct bp 177typedef struct bp
162{ 178{
163 struct bp *next; 179 struct bp *next;
@@ -173,10 +189,11 @@ typedef struct bp
173/* Head and tail of the list of relocatable blocs. */ 189/* Head and tail of the list of relocatable blocs. */
174static bloc_ptr first_bloc, last_bloc; 190static bloc_ptr first_bloc, last_bloc;
175 191
176/* Declared in dispnew.c, this version dosen't fuck up if regions overlap. */ 192/* Declared in dispnew.c, this version doesn't screw up if regions
193 overlap. */
177extern void safe_bcopy (); 194extern void safe_bcopy ();
178 195
179/* Find the bloc reference by the address in PTR. Returns a pointer 196/* Find the bloc referenced by the address in PTR. Returns a pointer
180 to that block. */ 197 to that block. */
181 198
182static bloc_ptr 199static bloc_ptr
@@ -285,6 +302,8 @@ free_bloc (bloc)
285 free (bloc); 302 free (bloc);
286} 303}
287 304
305/* Interface routines. */
306
288static int use_relocatable_buffers; 307static int use_relocatable_buffers;
289 308
290/* Obtain SIZE bytes of storage from the free pool, or the system, 309/* Obtain SIZE bytes of storage from the free pool, or the system,
@@ -306,6 +325,9 @@ r_alloc_sbrk (size)
306 if (first_bloc) 325 if (first_bloc)
307 { 326 {
308 relocate_some_blocs (first_bloc, first_bloc->data + size); 327 relocate_some_blocs (first_bloc, first_bloc->data + size);
328
329 /* Zero out the space we just allocated, to help catch bugs
330 quickly. */
309 bzero (virtual_break_value, size); 331 bzero (virtual_break_value, size);
310 } 332 }
311 } 333 }
@@ -332,11 +354,9 @@ r_alloc (ptr, size)
332{ 354{
333 register bloc_ptr new_bloc; 355 register bloc_ptr new_bloc;
334 356
335 BLOCK_INPUT;
336 new_bloc = get_bloc (size); 357 new_bloc = get_bloc (size);
337 new_bloc->variable = ptr; 358 new_bloc->variable = ptr;
338 *ptr = new_bloc->data; 359 *ptr = new_bloc->data;
339 UNBLOCK_INPUT;
340 360
341 return *ptr; 361 return *ptr;
342} 362}
@@ -349,13 +369,11 @@ r_alloc_free (ptr)
349{ 369{
350 register bloc_ptr dead_bloc; 370 register bloc_ptr dead_bloc;
351 371
352 BLOCK_INPUT;
353 dead_bloc = find_bloc (ptr); 372 dead_bloc = find_bloc (ptr);
354 if (dead_bloc == NIL_BLOC) 373 if (dead_bloc == NIL_BLOC)
355 abort (); 374 abort ();
356 375
357 free_bloc (dead_bloc); 376 free_bloc (dead_bloc);
358 UNBLOCK_INPUT;
359} 377}
360 378
361/* Given a pointer at address PTR to relocatable data, resize it 379/* Given a pointer at address PTR to relocatable data, resize it
@@ -373,12 +391,12 @@ r_re_alloc (ptr, size)
373{ 391{
374 register bloc_ptr old_bloc, new_bloc; 392 register bloc_ptr old_bloc, new_bloc;
375 393
376 BLOCK_INPUT;
377 old_bloc = find_bloc (ptr); 394 old_bloc = find_bloc (ptr);
378 if (old_bloc == NIL_BLOC) 395 if (old_bloc == NIL_BLOC)
379 abort (); 396 abort ();
380 397
381 if (size <= old_bloc->size) 398 if (size <= old_bloc->size)
399 /* Wouldn't it be useful to actually resize the bloc here? */
382 return *ptr; 400 return *ptr;
383 401
384 new_bloc = get_bloc (size); 402 new_bloc = get_bloc (size);
@@ -387,7 +405,6 @@ r_re_alloc (ptr, size)
387 *ptr = new_bloc->data; 405 *ptr = new_bloc->data;
388 406
389 free_bloc (old_bloc); 407 free_bloc (old_bloc);
390 UNBLOCK_INPUT;
391 408
392 return *ptr; 409 return *ptr;
393} 410}
@@ -396,6 +413,15 @@ r_re_alloc (ptr, size)
396 from the system. */ 413 from the system. */
397extern POINTER (*__morecore) (); 414extern POINTER (*__morecore) ();
398 415
416/* A flag to indicate whether we have initialized ralloc yet. For
417 Emacs's sake, please do not make this local to malloc_init; on some
418 machines, the dumping procedure makes all static variables
419 read-only. On these machines, the word static is #defined to be
420 the empty string, meaning that malloc_initialized becomes an
421 automatic variable, and loses its value each time Emacs is started
422 up. */
423static int malloc_initialized = 0;
424
399/* Intialize various things for memory allocation. */ 425/* Intialize various things for memory allocation. */
400 426
401void 427void
@@ -403,8 +429,6 @@ malloc_init (start, warn_func)
403 POINTER start; 429 POINTER start;
404 void (*warn_func) (); 430 void (*warn_func) ();
405{ 431{
406 static int malloc_initialized = 0;
407
408 if (start) 432 if (start)
409 data_space_start = start; 433 data_space_start = start;
410 434