Mercurial > emacs
annotate src/ralloc.c @ 31447:12a61566fea1
(Qdisplay): Declare extern.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Thu, 07 Sep 2000 11:36:52 +0000 |
parents | 76dcf201d009 |
children | 78540f2db51b |
rev | line source |
---|---|
118 | 1 /* Block-relocating memory allocator. |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
2 Copyright (C) 1993, 1995, 2000 Free Software Foundation, Inc. |
118 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
10432
15d01ad97928
(r_alloc_init): Remove unused variable END.
Roland McGrath <roland@gnu.org>
parents:
9666
diff
changeset
|
8 the Free Software Foundation; either version 2, or (at your option) |
118 | 9 any later version. |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
19 Boston, MA 02111-1307, USA. */ |
118 | 20 |
21 /* NOTES: | |
22 | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3136
diff
changeset
|
23 Only relocate the blocs necessary for SIZE in r_alloc_sbrk, |
118 | 24 rather than all of them. This means allowing for a possible |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
25 hole between the first bloc and the end of malloc storage. */ |
118 | 26 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
27 #ifdef emacs |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
28 |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
4230
diff
changeset
|
29 #include <config.h> |
577 | 30 #include "lisp.h" /* Needed for VALBITS. */ |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
31 |
29917 | 32 #ifdef HAVE_UNISTD_H |
33 #include <unistd.h> | |
34 #endif | |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
35 |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
36 typedef POINTER_TYPE *POINTER; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
37 typedef size_t SIZE; |
1451
107c9b227e7f
[emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents:
1403
diff
changeset
|
38 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
39 /* Declared in dispnew.c, this version doesn't screw up if regions |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
40 overlap. */ |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
41 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
42 extern void safe_bcopy (); |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
43 |
17845
ac6367122ee2
(mallopt): Declare, if appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
14953
diff
changeset
|
44 #ifdef DOUG_LEA_MALLOC |
ac6367122ee2
(mallopt): Declare, if appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
14953
diff
changeset
|
45 #define M_TOP_PAD -2 |
ac6367122ee2
(mallopt): Declare, if appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
14953
diff
changeset
|
46 extern int mallopt (); |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
47 #else /* not DOUG_LEA_MALLOC */ |
10785
f3a45c2e57c2
(r_alloc_init): Set __malloc_extra_blocks.
Richard M. Stallman <rms@gnu.org>
parents:
10767
diff
changeset
|
48 extern int __malloc_extra_blocks; |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
49 #endif /* not DOUG_LEA_MALLOC */ |
10785
f3a45c2e57c2
(r_alloc_init): Set __malloc_extra_blocks.
Richard M. Stallman <rms@gnu.org>
parents:
10767
diff
changeset
|
50 |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
51 #else /* not emacs */ |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
52 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
53 #include <stddef.h> |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
54 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
55 typedef size_t SIZE; |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
56 typedef void *POINTER; |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
57 |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
58 #include <unistd.h> |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
59 #include <malloc.h> |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
60 #include <string.h> |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
61 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
62 #define safe_bcopy(x, y, z) memmove (y, x, z) |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
63 #define bzero(x, len) memset (x, 0, len) |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
64 |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
65 #endif /* not emacs */ |
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
66 |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
67 |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
68 #include "getpagesize.h" |
118 | 69 |
70 #define NIL ((POINTER) 0) | |
71 | |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
72 /* A flag to indicate whether we have initialized ralloc yet. For |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
73 Emacs's sake, please do not make this local to malloc_init; on some |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
74 machines, the dumping procedure makes all static variables |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
75 read-only. On these machines, the word static is #defined to be |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
76 the empty string, meaning that r_alloc_initialized becomes an |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
77 automatic variable, and loses its value each time Emacs is started |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
78 up. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
79 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
80 static int r_alloc_initialized = 0; |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
81 |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
82 static void r_alloc_init (); |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
83 |
118 | 84 |
577 | 85 /* Declarations for working with the malloc, ralloc, and system breaks. */ |
86 | |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
87 /* Function to set the real break value. */ |
30061
3de459e6c652
Make real_morecore non-static.
Andrew Innes <andrewi@gnu.org>
parents:
29917
diff
changeset
|
88 POINTER (*real_morecore) (); |
118 | 89 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
90 /* The break value, as seen by malloc. */ |
118 | 91 static POINTER virtual_break_value; |
92 | |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
93 /* The address of the end of the last data in use by ralloc, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
94 including relocatable blocs as well as malloc data. */ |
118 | 95 static POINTER break_value; |
96 | |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
97 /* This is the size of a page. We round memory requests to this boundary. */ |
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
98 static int page_size; |
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
99 |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
100 /* Whenever we get memory from the system, get this many extra bytes. This |
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
101 must be a multiple of page_size. */ |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
102 static int extra_bytes; |
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
103 |
118 | 104 /* Macros for rounding. Note that rounding to any value is possible |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
105 by changing the definition of PAGE. */ |
118 | 106 #define PAGE (getpagesize ()) |
4230
df4d091e603e
(ALIGNED, ROUNDUP): Use `unsigned long int' instead of `unsigned int' for
Roland McGrath <roland@gnu.org>
parents:
3591
diff
changeset
|
107 #define ALIGNED(addr) (((unsigned long int) (addr) & (page_size - 1)) == 0) |
df4d091e603e
(ALIGNED, ROUNDUP): Use `unsigned long int' instead of `unsigned int' for
Roland McGrath <roland@gnu.org>
parents:
3591
diff
changeset
|
108 #define ROUNDUP(size) (((unsigned long int) (size) + page_size - 1) \ |
df4d091e603e
(ALIGNED, ROUNDUP): Use `unsigned long int' instead of `unsigned int' for
Roland McGrath <roland@gnu.org>
parents:
3591
diff
changeset
|
109 & ~(page_size - 1)) |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
110 #define ROUND_TO_PAGE(addr) (addr & (~(page_size - 1))) |
118 | 111 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
112 #define MEM_ALIGN sizeof(double) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
113 #define MEM_ROUNDUP(addr) (((unsigned long int)(addr) + MEM_ALIGN - 1) \ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
114 & ~(MEM_ALIGN - 1)) |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
115 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
116 |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
117 /*********************************************************************** |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
118 Implementation using sbrk |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
119 ***********************************************************************/ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
120 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
121 /* Data structures of heaps and blocs. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
122 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
123 /* The relocatable objects, or blocs, and the malloc data |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
124 both reside within one or more heaps. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
125 Each heap contains malloc data, running from `start' to `bloc_start', |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
126 and relocatable objects, running from `bloc_start' to `free'. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
127 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
128 Relocatable objects may relocate within the same heap |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
129 or may move into another heap; the heaps themselves may grow |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
130 but they never move. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
131 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
132 We try to make just one heap and make it larger as necessary. |
14036 | 133 But sometimes we can't do that, because we can't get contiguous |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
134 space to add onto the heap. When that happens, we start a new heap. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
135 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
136 typedef struct heap |
118 | 137 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
138 struct heap *next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
139 struct heap *prev; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
140 /* Start of memory range of this heap. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
141 POINTER start; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
142 /* End of memory range of this heap. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
143 POINTER end; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
144 /* Start of relocatable data in this heap. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
145 POINTER bloc_start; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
146 /* Start of unused space in this heap. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
147 POINTER free; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
148 /* First bloc in this heap. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
149 struct bp *first_bloc; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
150 /* Last bloc in this heap. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
151 struct bp *last_bloc; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
152 } *heap_ptr; |
118 | 153 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
154 #define NIL_HEAP ((heap_ptr) 0) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
155 #define HEAP_PTR_SIZE (sizeof (struct heap)) |
118 | 156 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
157 /* This is the first heap object. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
158 If we need additional heap objects, each one resides at the beginning of |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
159 the space it covers. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
160 static struct heap heap_base; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
161 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
162 /* Head and tail of the list of heaps. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
163 static heap_ptr first_heap, last_heap; |
577 | 164 |
165 /* These structures are allocated in the malloc arena. | |
166 The linked list is kept in order of increasing '.data' members. | |
167 The data blocks abut each other; if b->next is non-nil, then | |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
168 b->data + b->size == b->next->data. |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
169 |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
170 An element with variable==NIL denotes a freed block, which has not yet |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
171 been collected. They may only appear while r_alloc_freeze > 0, and will be |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
172 freed when the arena is thawed. Currently, these blocs are not reusable, |
14036 | 173 while the arena is frozen. Very inefficient. */ |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
174 |
118 | 175 typedef struct bp |
176 { | |
177 struct bp *next; | |
178 struct bp *prev; | |
179 POINTER *variable; | |
180 POINTER data; | |
181 SIZE size; | |
14036 | 182 POINTER new_data; /* temporarily used for relocation */ |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
183 struct heap *heap; /* Heap this bloc is in. */ |
118 | 184 } *bloc_ptr; |
185 | |
186 #define NIL_BLOC ((bloc_ptr) 0) | |
187 #define BLOC_PTR_SIZE (sizeof (struct bp)) | |
188 | |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
189 /* Head and tail of the list of relocatable blocs. */ |
118 | 190 static bloc_ptr first_bloc, last_bloc; |
191 | |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
192 static int use_relocatable_buffers; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
193 |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
194 /* If >0, no relocation whatsoever takes place. */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
195 static int r_alloc_freeze_level; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
196 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
197 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
198 /* Functions to get and return memory from the system. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
199 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
200 /* Find the heap that ADDRESS falls within. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
201 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
202 static heap_ptr |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
203 find_heap (address) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
204 POINTER address; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
205 { |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
206 heap_ptr heap; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
207 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
208 for (heap = last_heap; heap; heap = heap->prev) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
209 { |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
210 if (heap->start <= address && address <= heap->end) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
211 return heap; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
212 } |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
213 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
214 return NIL_HEAP; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
215 } |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
216 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
217 /* Find SIZE bytes of space in a heap. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
218 Try to get them at ADDRESS (which must fall within some heap's range) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
219 if we can get that many within one heap. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
220 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
221 If enough space is not presently available in our reserve, this means |
14036 | 222 getting more page-aligned space from the system. If the returned space |
223 is not contiguous to the last heap, allocate a new heap, and append it | |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
224 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
225 obtain does not try to keep track of whether space is in use |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
226 or not in use. It just returns the address of SIZE bytes that |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
227 fall within a single heap. If you call obtain twice in a row |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
228 with the same arguments, you typically get the same value. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
229 to the heap list. It's the caller's responsibility to keep |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
230 track of what space is in use. |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
231 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
232 Return the address of the space if all went well, or zero if we couldn't |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
233 allocate the memory. */ |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
234 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
235 static POINTER |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
236 obtain (address, size) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
237 POINTER address; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
238 SIZE size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
239 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
240 heap_ptr heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
241 SIZE already_available; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
242 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
243 /* Find the heap that ADDRESS falls within. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
244 for (heap = last_heap; heap; heap = heap->prev) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
245 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
246 if (heap->start <= address && address <= heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
247 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
248 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
249 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
250 if (! heap) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
251 abort (); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
252 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
253 /* If we can't fit SIZE bytes in that heap, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
254 try successive later heaps. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
255 while (heap && address + size > heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
256 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
257 heap = heap->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
258 if (heap == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
259 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
260 address = heap->bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
261 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
262 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
263 /* If we can't fit them within any existing heap, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
264 get more space. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
265 if (heap == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
266 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
267 POINTER new = (*real_morecore)(0); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
268 SIZE get; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
269 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
270 already_available = (char *)last_heap->end - (char *)address; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
271 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
272 if (new != last_heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
273 { |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
274 /* Someone else called sbrk. Make a new heap. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
275 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
276 heap_ptr new_heap = (heap_ptr) MEM_ROUNDUP (new); |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
277 POINTER bloc_start = (POINTER) MEM_ROUNDUP ((POINTER)(new_heap + 1)); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
278 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
279 if ((*real_morecore) (bloc_start - new) != new) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
280 return 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
281 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
282 new_heap->start = new; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
283 new_heap->end = bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
284 new_heap->bloc_start = bloc_start; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
285 new_heap->free = bloc_start; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
286 new_heap->next = NIL_HEAP; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
287 new_heap->prev = last_heap; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
288 new_heap->first_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
289 new_heap->last_bloc = NIL_BLOC; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
290 last_heap->next = new_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
291 last_heap = new_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
292 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
293 address = bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
294 already_available = 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
295 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
296 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
297 /* Add space to the last heap (which we may have just created). |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
298 Get some extra, so we can come here less often. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
299 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
300 get = size + extra_bytes - already_available; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
301 get = (char *) ROUNDUP ((char *)last_heap->end + get) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
302 - (char *) last_heap->end; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
303 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
304 if ((*real_morecore) (get) != last_heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
305 return 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
306 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
307 last_heap->end += get; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
308 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
309 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
310 return address; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
311 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
312 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
313 /* Return unused heap space to the system |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
314 if there is a lot of unused space now. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
315 This can make the last heap smaller; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
316 it can also eliminate the last heap entirely. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
317 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
318 static void |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
319 relinquish () |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
320 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
321 register heap_ptr h; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
322 int excess = 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
323 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
324 /* Add the amount of space beyond break_value |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
325 in all heaps which have extend beyond break_value at all. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
326 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
327 for (h = last_heap; h && break_value < h->end; h = h->prev) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
328 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
329 excess += (char *) h->end - (char *) ((break_value < h->bloc_start) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
330 ? h->bloc_start : break_value); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
331 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
332 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
333 if (excess > extra_bytes * 2 && (*real_morecore) (0) == last_heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
334 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
335 /* Keep extra_bytes worth of empty space. |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
336 And don't free anything unless we can free at least extra_bytes. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
337 excess -= extra_bytes; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
338 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
339 if ((char *)last_heap->end - (char *)last_heap->bloc_start <= excess) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
340 { |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
341 /* This heap should have no blocs in it. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
342 if (last_heap->first_bloc != NIL_BLOC |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
343 || last_heap->last_bloc != NIL_BLOC) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
344 abort (); |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
345 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
346 /* Return the last heap, with its header, to the system. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
347 excess = (char *)last_heap->end - (char *)last_heap->start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
348 last_heap = last_heap->prev; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
349 last_heap->next = NIL_HEAP; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
350 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
351 else |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
352 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
353 excess = (char *) last_heap->end |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
354 - (char *) ROUNDUP ((char *)last_heap->end - excess); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
355 last_heap->end -= excess; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
356 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
357 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
358 if ((*real_morecore) (- excess) == 0) |
19999
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
359 { |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
360 /* If the system didn't want that much memory back, adjust |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
361 the end of the last heap to reflect that. This can occur |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
362 if break_value is still within the original data segment. */ |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
363 last_heap->end += excess; |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
364 /* Make sure that the result of the adjustment is accurate. |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
365 It should be, for the else clause above; the other case, |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
366 which returns the entire last heap to the system, seems |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
367 unlikely to trigger this mode of failure. */ |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
368 if (last_heap->end != (*real_morecore) (0)) |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
369 abort (); |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
370 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
371 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
372 } |
10682
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
373 |
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
374 /* Return the total size in use by relocating allocator, |
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
375 above where malloc gets space. */ |
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
376 |
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
377 long |
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
378 r_alloc_size_in_use () |
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
379 { |
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
380 return break_value - virtual_break_value; |
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
381 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
382 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
383 /* The meat - allocating, freeing, and relocating blocs. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
384 |
577 | 385 /* Find the bloc referenced by the address in PTR. Returns a pointer |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
386 to that block. */ |
118 | 387 |
388 static bloc_ptr | |
389 find_bloc (ptr) | |
390 POINTER *ptr; | |
391 { | |
392 register bloc_ptr p = first_bloc; | |
393 | |
394 while (p != NIL_BLOC) | |
395 { | |
396 if (p->variable == ptr && p->data == *ptr) | |
397 return p; | |
398 | |
399 p = p->next; | |
400 } | |
401 | |
402 return p; | |
403 } | |
404 | |
405 /* Allocate a bloc of SIZE bytes and append it to the chain of blocs. | |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
406 Returns a pointer to the new bloc, or zero if we couldn't allocate |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
407 memory for the new block. */ |
118 | 408 |
409 static bloc_ptr | |
410 get_bloc (size) | |
411 SIZE size; | |
412 { | |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
413 register bloc_ptr new_bloc; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
414 register heap_ptr heap; |
118 | 415 |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
416 if (! (new_bloc = (bloc_ptr) malloc (BLOC_PTR_SIZE)) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
417 || ! (new_bloc->data = obtain (break_value, size))) |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
418 { |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
419 if (new_bloc) |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
420 free (new_bloc); |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
421 |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
422 return 0; |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
423 } |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
424 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
425 break_value = new_bloc->data + size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
426 |
118 | 427 new_bloc->size = size; |
428 new_bloc->next = NIL_BLOC; | |
1013
6bf2c4766d4c
* ralloc.c (get_bloc): When initializing new_bloc->variable, cast
Jim Blandy <jimb@redhat.com>
parents:
734
diff
changeset
|
429 new_bloc->variable = (POINTER *) NIL; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
430 new_bloc->new_data = 0; |
118 | 431 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
432 /* Record in the heap that this space is in use. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
433 heap = find_heap (new_bloc->data); |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
434 heap->free = break_value; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
435 |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
436 /* Maintain the correspondence between heaps and blocs. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
437 new_bloc->heap = heap; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
438 heap->last_bloc = new_bloc; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
439 if (heap->first_bloc == NIL_BLOC) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
440 heap->first_bloc = new_bloc; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
441 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
442 /* Put this bloc on the doubly-linked list of blocs. */ |
118 | 443 if (first_bloc) |
444 { | |
445 new_bloc->prev = last_bloc; | |
446 last_bloc->next = new_bloc; | |
447 last_bloc = new_bloc; | |
448 } | |
449 else | |
450 { | |
451 first_bloc = last_bloc = new_bloc; | |
452 new_bloc->prev = NIL_BLOC; | |
453 } | |
454 | |
455 return new_bloc; | |
456 } | |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
457 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
458 /* Calculate new locations of blocs in the list beginning with BLOC, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
459 relocating it to start at ADDRESS, in heap HEAP. If enough space is |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
460 not presently available in our reserve, call obtain for |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
461 more space. |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
462 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
463 Store the new location of each bloc in its new_data field. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
464 Do not touch the contents of blocs or break_value. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
465 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
466 static int |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
467 relocate_blocs (bloc, heap, address) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
468 bloc_ptr bloc; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
469 heap_ptr heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
470 POINTER address; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
471 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
472 register bloc_ptr b = bloc; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
473 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
474 /* No need to ever call this if arena is frozen, bug somewhere! */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
475 if (r_alloc_freeze_level) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
476 abort(); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
477 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
478 while (b) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
479 { |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
480 /* If bloc B won't fit within HEAP, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
481 move to the next heap and try again. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
482 while (heap && address + b->size > heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
483 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
484 heap = heap->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
485 if (heap == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
486 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
487 address = heap->bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
488 } |
118 | 489 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
490 /* If BLOC won't fit in any heap, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
491 get enough new space to hold BLOC and all following blocs. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
492 if (heap == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
493 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
494 register bloc_ptr tb = b; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
495 register SIZE s = 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
496 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
497 /* Add up the size of all the following blocs. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
498 while (tb != NIL_BLOC) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
499 { |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
500 if (tb->variable) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
501 s += tb->size; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
502 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
503 tb = tb->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
504 } |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
505 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
506 /* Get that space. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
507 address = obtain (address, s); |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
508 if (address == 0) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
509 return 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
510 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
511 heap = last_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
512 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
513 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
514 /* Record the new address of this bloc |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
515 and update where the next bloc can start. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
516 b->new_data = address; |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
517 if (b->variable) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
518 address += b->size; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
519 b = b->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
520 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
521 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
522 return 1; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
523 } |
118 | 524 |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
525 /* Reorder the bloc BLOC to go before bloc BEFORE in the doubly linked list. |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
526 This is necessary if we put the memory of space of BLOC |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
527 before that of BEFORE. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
528 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
529 static void |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
530 reorder_bloc (bloc, before) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
531 bloc_ptr bloc, before; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
532 { |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
533 bloc_ptr prev, next; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
534 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
535 /* Splice BLOC out from where it is. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
536 prev = bloc->prev; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
537 next = bloc->next; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
538 |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
539 if (prev) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
540 prev->next = next; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
541 if (next) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
542 next->prev = prev; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
543 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
544 /* Splice it in before BEFORE. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
545 prev = before->prev; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
546 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
547 if (prev) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
548 prev->next = bloc; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
549 bloc->prev = prev; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
550 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
551 before->prev = bloc; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
552 bloc->next = before; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
553 } |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
554 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
555 /* Update the records of which heaps contain which blocs, starting |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
556 with heap HEAP and bloc BLOC. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
557 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
558 static void |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
559 update_heap_bloc_correspondence (bloc, heap) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
560 bloc_ptr bloc; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
561 heap_ptr heap; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
562 { |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
563 register bloc_ptr b; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
564 |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
565 /* Initialize HEAP's status to reflect blocs before BLOC. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
566 if (bloc != NIL_BLOC && bloc->prev != NIL_BLOC && bloc->prev->heap == heap) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
567 { |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
568 /* The previous bloc is in HEAP. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
569 heap->last_bloc = bloc->prev; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
570 heap->free = bloc->prev->data + bloc->prev->size; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
571 } |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
572 else |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
573 { |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
574 /* HEAP contains no blocs before BLOC. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
575 heap->first_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
576 heap->last_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
577 heap->free = heap->bloc_start; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
578 } |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
579 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
580 /* Advance through blocs one by one. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
581 for (b = bloc; b != NIL_BLOC; b = b->next) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
582 { |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
583 /* Advance through heaps, marking them empty, |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
584 till we get to the one that B is in. */ |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
585 while (heap) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
586 { |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
587 if (heap->bloc_start <= b->data && b->data <= heap->end) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
588 break; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
589 heap = heap->next; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
590 /* We know HEAP is not null now, |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
591 because there has to be space for bloc B. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
592 heap->first_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
593 heap->last_bloc = NIL_BLOC; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
594 heap->free = heap->bloc_start; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
595 } |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
596 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
597 /* Update HEAP's status for bloc B. */ |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
598 heap->free = b->data + b->size; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
599 heap->last_bloc = b; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
600 if (heap->first_bloc == NIL_BLOC) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
601 heap->first_bloc = b; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
602 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
603 /* Record that B is in HEAP. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
604 b->heap = heap; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
605 } |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
606 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
607 /* If there are any remaining heaps and no blocs left, |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
608 mark those heaps as empty. */ |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
609 heap = heap->next; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
610 while (heap) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
611 { |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
612 heap->first_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
613 heap->last_bloc = NIL_BLOC; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
614 heap->free = heap->bloc_start; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
615 heap = heap->next; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
616 } |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
617 } |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
618 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
619 /* Resize BLOC to SIZE bytes. This relocates the blocs |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
620 that come after BLOC in memory. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
621 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
622 static int |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
623 resize_bloc (bloc, size) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
624 bloc_ptr bloc; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
625 SIZE size; |
118 | 626 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
627 register bloc_ptr b; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
628 heap_ptr heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
629 POINTER address; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
630 SIZE old_size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
631 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
632 /* No need to ever call this if arena is frozen, bug somewhere! */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
633 if (r_alloc_freeze_level) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
634 abort(); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
635 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
636 if (bloc == NIL_BLOC || size == bloc->size) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
637 return 1; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
638 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
639 for (heap = first_heap; heap != NIL_HEAP; heap = heap->next) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
640 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
641 if (heap->bloc_start <= bloc->data && bloc->data <= heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
642 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
643 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
644 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
645 if (heap == NIL_HEAP) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
646 abort (); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
647 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
648 old_size = bloc->size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
649 bloc->size = size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
650 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
651 /* Note that bloc could be moved into the previous heap. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
652 address = (bloc->prev ? bloc->prev->data + bloc->prev->size |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
653 : first_heap->bloc_start); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
654 while (heap) |
118 | 655 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
656 if (heap->bloc_start <= address && address <= heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
657 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
658 heap = heap->prev; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
659 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
660 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
661 if (! relocate_blocs (bloc, heap, address)) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
662 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
663 bloc->size = old_size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
664 return 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
665 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
666 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
667 if (size > old_size) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
668 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
669 for (b = last_bloc; b != bloc; b = b->prev) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
670 { |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
671 if (!b->variable) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
672 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
673 b->size = 0; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
674 b->data = b->new_data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
675 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
676 else |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
677 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
678 safe_bcopy (b->data, b->new_data, b->size); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
679 *b->variable = b->data = b->new_data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
680 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
681 } |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
682 if (!bloc->variable) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
683 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
684 bloc->size = 0; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
685 bloc->data = bloc->new_data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
686 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
687 else |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
688 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
689 safe_bcopy (bloc->data, bloc->new_data, old_size); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
690 bzero (bloc->new_data + old_size, size - old_size); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
691 *bloc->variable = bloc->data = bloc->new_data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
692 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
693 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
694 else |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
695 { |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
696 for (b = bloc; b != NIL_BLOC; b = b->next) |
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
697 { |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
698 if (!b->variable) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
699 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
700 b->size = 0; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
701 b->data = b->new_data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
702 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
703 else |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
704 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
705 safe_bcopy (b->data, b->new_data, b->size); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
706 *b->variable = b->data = b->new_data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
707 } |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
708 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
709 } |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
710 |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
711 update_heap_bloc_correspondence (bloc, heap); |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
712 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
713 break_value = (last_bloc ? last_bloc->data + last_bloc->size |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
714 : first_heap->bloc_start); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
715 return 1; |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
716 } |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
717 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
718 /* Free BLOC from the chain of blocs, relocating any blocs above it. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
719 This may return space to the system. */ |
118 | 720 |
721 static void | |
722 free_bloc (bloc) | |
723 bloc_ptr bloc; | |
724 { | |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
725 heap_ptr heap = bloc->heap; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
726 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
727 if (r_alloc_freeze_level) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
728 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
729 bloc->variable = (POINTER *) NIL; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
730 return; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
731 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
732 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
733 resize_bloc (bloc, 0); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
734 |
118 | 735 if (bloc == first_bloc && bloc == last_bloc) |
736 { | |
737 first_bloc = last_bloc = NIL_BLOC; | |
738 } | |
739 else if (bloc == last_bloc) | |
740 { | |
741 last_bloc = bloc->prev; | |
742 last_bloc->next = NIL_BLOC; | |
743 } | |
744 else if (bloc == first_bloc) | |
745 { | |
746 first_bloc = bloc->next; | |
747 first_bloc->prev = NIL_BLOC; | |
748 } | |
749 else | |
750 { | |
751 bloc->next->prev = bloc->prev; | |
752 bloc->prev->next = bloc->next; | |
753 } | |
754 | |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
755 /* Update the records of which blocs are in HEAP. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
756 if (heap->first_bloc == bloc) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
757 { |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
758 if (bloc->next != 0 && bloc->next->heap == heap) |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
759 heap->first_bloc = bloc->next; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
760 else |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
761 heap->first_bloc = heap->last_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
762 } |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
763 if (heap->last_bloc == bloc) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
764 { |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
765 if (bloc->prev != 0 && bloc->prev->heap == heap) |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
766 heap->last_bloc = bloc->prev; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
767 else |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
768 heap->first_bloc = heap->last_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
769 } |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
770 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
771 relinquish (); |
118 | 772 free (bloc); |
773 } | |
774 | |
577 | 775 /* Interface routines. */ |
776 | |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
777 /* Obtain SIZE bytes of storage from the free pool, or the system, as |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
778 necessary. If relocatable blocs are in use, this means relocating |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
779 them. This function gets plugged into the GNU malloc's __morecore |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
780 hook. |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
781 |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
782 We provide hysteresis, never relocating by less than extra_bytes. |
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
783 |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
784 If we're out of memory, we should return zero, to imitate the other |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
785 __morecore hook values - in particular, __default_morecore in the |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
786 GNU malloc package. */ |
118 | 787 |
788 POINTER | |
789 r_alloc_sbrk (size) | |
790 long size; | |
791 { | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
792 register bloc_ptr b; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
793 POINTER address; |
118 | 794 |
10767
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
795 if (! r_alloc_initialized) |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
796 r_alloc_init (); |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
797 |
118 | 798 if (! use_relocatable_buffers) |
1401 | 799 return (*real_morecore) (size); |
118 | 800 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
801 if (size == 0) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
802 return virtual_break_value; |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
803 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
804 if (size > 0) |
118 | 805 { |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
806 /* Allocate a page-aligned space. GNU malloc would reclaim an |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
807 extra space if we passed an unaligned one. But we could |
14036 | 808 not always find a space which is contiguous to the previous. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
809 POINTER new_bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
810 heap_ptr h = first_heap; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
811 SIZE get = ROUNDUP (size); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
812 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
813 address = (POINTER) ROUNDUP (virtual_break_value); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
814 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
815 /* Search the list upward for a heap which is large enough. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
816 while ((char *) h->end < (char *) MEM_ROUNDUP ((char *)address + get)) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
817 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
818 h = h->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
819 if (h == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
820 break; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
821 address = (POINTER) ROUNDUP (h->start); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
822 } |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
823 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
824 /* If not found, obtain more space. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
825 if (h == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
826 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
827 get += extra_bytes + page_size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
828 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
829 if (! obtain (address, get)) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
830 return 0; |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
831 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
832 if (first_heap == last_heap) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
833 address = (POINTER) ROUNDUP (virtual_break_value); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
834 else |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
835 address = (POINTER) ROUNDUP (last_heap->start); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
836 h = last_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
837 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
838 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
839 new_bloc_start = (POINTER) MEM_ROUNDUP ((char *)address + get); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
840 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
841 if (first_heap->bloc_start < new_bloc_start) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
842 { |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
843 /* This is no clean solution - no idea how to do it better. */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
844 if (r_alloc_freeze_level) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
845 return NIL; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
846 |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
847 /* There is a bug here: if the above obtain call succeeded, but the |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
848 relocate_blocs call below does not succeed, we need to free |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
849 the memory that we got with obtain. */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
850 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
851 /* Move all blocs upward. */ |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
852 if (! relocate_blocs (first_bloc, h, new_bloc_start)) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
853 return 0; |
577 | 854 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
855 /* Note that (POINTER)(h+1) <= new_bloc_start since |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
856 get >= page_size, so the following does not destroy the heap |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
857 header. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
858 for (b = last_bloc; b != NIL_BLOC; b = b->prev) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
859 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
860 safe_bcopy (b->data, b->new_data, b->size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
861 *b->variable = b->data = b->new_data; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
862 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
863 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
864 h->bloc_start = new_bloc_start; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
865 |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
866 update_heap_bloc_correspondence (first_bloc, h); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
867 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
868 if (h != first_heap) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
869 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
870 /* Give up managing heaps below the one the new |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
871 virtual_break_value points to. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
872 first_heap->prev = NIL_HEAP; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
873 first_heap->next = h->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
874 first_heap->start = h->start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
875 first_heap->end = h->end; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
876 first_heap->free = h->free; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
877 first_heap->first_bloc = h->first_bloc; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
878 first_heap->last_bloc = h->last_bloc; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
879 first_heap->bloc_start = h->bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
880 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
881 if (first_heap->next) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
882 first_heap->next->prev = first_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
883 else |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
884 last_heap = first_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
885 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
886 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
887 bzero (address, size); |
118 | 888 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
889 else /* size < 0 */ |
118 | 890 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
891 SIZE excess = (char *)first_heap->bloc_start |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
892 - ((char *)virtual_break_value + size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
893 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
894 address = virtual_break_value; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
895 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
896 if (r_alloc_freeze_level == 0 && excess > 2 * extra_bytes) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
897 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
898 excess -= extra_bytes; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
899 first_heap->bloc_start |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
900 = (POINTER) MEM_ROUNDUP ((char *)first_heap->bloc_start - excess); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
901 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
902 relocate_blocs (first_bloc, first_heap, first_heap->bloc_start); |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
903 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
904 for (b = first_bloc; b != NIL_BLOC; b = b->next) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
905 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
906 safe_bcopy (b->data, b->new_data, b->size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
907 *b->variable = b->data = b->new_data; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
908 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
909 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
910 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
911 if ((char *)virtual_break_value + size < (char *)first_heap->start) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
912 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
913 /* We found an additional space below the first heap */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
914 first_heap->start = (POINTER) ((char *)virtual_break_value + size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
915 } |
118 | 916 } |
917 | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
918 virtual_break_value = (POINTER) ((char *)address + size); |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
919 break_value = (last_bloc |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
920 ? last_bloc->data + last_bloc->size |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
921 : first_heap->bloc_start); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
922 if (size < 0) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
923 relinquish (); |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
924 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
925 return address; |
118 | 926 } |
927 | |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
928 #ifndef REL_ALLOC_MMAP |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
929 |
118 | 930 /* Allocate a relocatable bloc of storage of size SIZE. A pointer to |
931 the data is returned in *PTR. PTR is thus the address of some variable | |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
932 which will use the data area. |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
933 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
934 The allocation of 0 bytes is valid. |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
935 In case r_alloc_freeze is set, a best fit of unused blocs could be done |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
936 before allocating a new area. Not yet done. |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
937 |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
938 If we can't allocate the necessary memory, set *PTR to zero, and |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
939 return zero. */ |
118 | 940 |
941 POINTER | |
942 r_alloc (ptr, size) | |
943 POINTER *ptr; | |
944 SIZE size; | |
945 { | |
946 register bloc_ptr new_bloc; | |
947 | |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
948 if (! r_alloc_initialized) |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
949 r_alloc_init (); |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
950 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
951 new_bloc = get_bloc (MEM_ROUNDUP (size)); |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
952 if (new_bloc) |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
953 { |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
954 new_bloc->variable = ptr; |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
955 *ptr = new_bloc->data; |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
956 } |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
957 else |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
958 *ptr = 0; |
118 | 959 |
960 return *ptr; | |
961 } | |
962 | |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
963 /* Free a bloc of relocatable storage whose data is pointed to by PTR. |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
964 Store 0 in *PTR to show there's no block allocated. */ |
118 | 965 |
966 void | |
967 r_alloc_free (ptr) | |
968 register POINTER *ptr; | |
969 { | |
970 register bloc_ptr dead_bloc; | |
971 | |
10767
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
972 if (! r_alloc_initialized) |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
973 r_alloc_init (); |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
974 |
118 | 975 dead_bloc = find_bloc (ptr); |
976 if (dead_bloc == NIL_BLOC) | |
977 abort (); | |
978 | |
979 free_bloc (dead_bloc); | |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
980 *ptr = 0; |
10682
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
981 |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
982 #ifdef emacs |
10682
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
983 refill_memory_reserve (); |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
984 #endif |
118 | 985 } |
986 | |
1087
6c410cc87574
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents:
1013
diff
changeset
|
987 /* Given a pointer at address PTR to relocatable data, resize it to SIZE. |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
988 Do this by shifting all blocks above this one up in memory, unless |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
989 SIZE is less than or equal to the current bloc size, in which case |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
990 do nothing. |
118 | 991 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
992 In case r_alloc_freeze is set, a new bloc is allocated, and the |
14036 | 993 memory copied to it. Not very efficient. We could traverse the |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
994 bloc_list for a best fit of free blocs first. |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
995 |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
996 Change *PTR to reflect the new bloc, and return this value. |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
997 |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
998 If more memory cannot be allocated, then leave *PTR unchanged, and |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
999 return zero. */ |
118 | 1000 |
1001 POINTER | |
1002 r_re_alloc (ptr, size) | |
1003 POINTER *ptr; | |
1004 SIZE size; | |
1005 { | |
1087
6c410cc87574
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents:
1013
diff
changeset
|
1006 register bloc_ptr bloc; |
118 | 1007 |
10767
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
1008 if (! r_alloc_initialized) |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
1009 r_alloc_init (); |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
1010 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1011 if (!*ptr) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1012 return r_alloc (ptr, size); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1013 if (!size) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1014 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1015 r_alloc_free (ptr); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1016 return r_alloc (ptr, 0); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1017 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1018 |
1087
6c410cc87574
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents:
1013
diff
changeset
|
1019 bloc = find_bloc (ptr); |
6c410cc87574
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents:
1013
diff
changeset
|
1020 if (bloc == NIL_BLOC) |
118 | 1021 abort (); |
1022 | |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1023 if (size < bloc->size) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1024 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1025 /* Wouldn't it be useful to actually resize the bloc here? */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1026 /* I think so too, but not if it's too expensive... */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1027 if ((bloc->size - MEM_ROUNDUP (size) >= page_size) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1028 && r_alloc_freeze_level == 0) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1029 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1030 resize_bloc (bloc, MEM_ROUNDUP (size)); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1031 /* Never mind if this fails, just do nothing... */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1032 /* It *should* be infallible! */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1033 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1034 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1035 else if (size > bloc->size) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1036 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1037 if (r_alloc_freeze_level) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1038 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1039 bloc_ptr new_bloc; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1040 new_bloc = get_bloc (MEM_ROUNDUP (size)); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1041 if (new_bloc) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1042 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1043 new_bloc->variable = ptr; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1044 *ptr = new_bloc->data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1045 bloc->variable = (POINTER *) NIL; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1046 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1047 else |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1048 return NIL; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1049 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1050 else |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1051 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1052 if (! resize_bloc (bloc, MEM_ROUNDUP (size))) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1053 return NIL; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1054 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1055 } |
118 | 1056 return *ptr; |
1057 } | |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1058 |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1059 /* Disable relocations, after making room for at least SIZE bytes |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1060 of non-relocatable heap if possible. The relocatable blocs are |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1061 guaranteed to hold still until thawed, even if this means that |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1062 malloc must return a null pointer. */ |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
1063 |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1064 void |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1065 r_alloc_freeze (size) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1066 long size; |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1067 { |
10767
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
1068 if (! r_alloc_initialized) |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
1069 r_alloc_init (); |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
1070 |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1071 /* If already frozen, we can't make any more room, so don't try. */ |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1072 if (r_alloc_freeze_level > 0) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1073 size = 0; |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1074 /* If we can't get the amount requested, half is better than nothing. */ |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1075 while (size > 0 && r_alloc_sbrk (size) == 0) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1076 size /= 2; |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1077 ++r_alloc_freeze_level; |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1078 if (size > 0) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1079 r_alloc_sbrk (-size); |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1080 } |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1081 |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1082 void |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1083 r_alloc_thaw () |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1084 { |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1085 |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1086 if (! r_alloc_initialized) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1087 r_alloc_init (); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1088 |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1089 if (--r_alloc_freeze_level < 0) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1090 abort (); |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1091 |
14036 | 1092 /* This frees all unused blocs. It is not too inefficient, as the resize |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1093 and bcopy is done only once. Afterwards, all unreferenced blocs are |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1094 already shrunk to zero size. */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1095 if (!r_alloc_freeze_level) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1096 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1097 bloc_ptr *b = &first_bloc; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1098 while (*b) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1099 if (!(*b)->variable) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1100 free_bloc (*b); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1101 else |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1102 b = &(*b)->next; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1103 } |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1104 } |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1105 |
18757
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1106 |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1107 #if defined (emacs) && defined (DOUG_LEA_MALLOC) |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1108 |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1109 /* Reinitialize the morecore hook variables after restarting a dumped |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1110 Emacs. This is needed when using Doug Lea's malloc from GNU libc. */ |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1111 void |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1112 r_alloc_reinit () |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1113 { |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1114 /* Only do this if the hook has been reset, so that we don't get an |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1115 infinite loop, in case Emacs was linked statically. */ |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1116 if (__morecore != r_alloc_sbrk) |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1117 { |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1118 real_morecore = __morecore; |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1119 __morecore = r_alloc_sbrk; |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1120 } |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1121 } |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1122 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1123 #endif /* emacs && DOUG_LEA_MALLOC */ |
18757
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1124 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1125 #ifdef DEBUG |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1126 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1127 #include <assert.h> |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1128 |
10767
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
1129 void |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1130 r_alloc_check () |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1131 { |
10766 | 1132 int found = 0; |
1133 heap_ptr h, ph = 0; | |
1134 bloc_ptr b, pb = 0; | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1135 |
10766 | 1136 if (!r_alloc_initialized) |
1137 return; | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1138 |
10766 | 1139 assert (first_heap); |
1140 assert (last_heap->end <= (POINTER) sbrk (0)); | |
1141 assert ((POINTER) first_heap < first_heap->start); | |
1142 assert (first_heap->start <= virtual_break_value); | |
1143 assert (virtual_break_value <= first_heap->end); | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1144 |
10766 | 1145 for (h = first_heap; h; h = h->next) |
1146 { | |
1147 assert (h->prev == ph); | |
1148 assert ((POINTER) ROUNDUP (h->end) == h->end); | |
14953
36e4b3043730
(r_alloc_check): Don't check alignment of h->start.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
1149 #if 0 /* ??? The code in ralloc.c does not really try to ensure |
36e4b3043730
(r_alloc_check): Don't check alignment of h->start.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
1150 the heap start has any sort of alignment. |
36e4b3043730
(r_alloc_check): Don't check alignment of h->start.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
1151 Perhaps it should. */ |
10766 | 1152 assert ((POINTER) MEM_ROUNDUP (h->start) == h->start); |
14953
36e4b3043730
(r_alloc_check): Don't check alignment of h->start.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
1153 #endif |
10766 | 1154 assert ((POINTER) MEM_ROUNDUP (h->bloc_start) == h->bloc_start); |
1155 assert (h->start <= h->bloc_start && h->bloc_start <= h->end); | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1156 |
10766 | 1157 if (ph) |
1158 { | |
1159 assert (ph->end < h->start); | |
1160 assert (h->start <= (POINTER)h && (POINTER)(h+1) <= h->bloc_start); | |
1161 } | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1162 |
10766 | 1163 if (h->bloc_start <= break_value && break_value <= h->end) |
1164 found = 1; | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1165 |
10766 | 1166 ph = h; |
1167 } | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1168 |
10766 | 1169 assert (found); |
1170 assert (last_heap == ph); | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1171 |
10766 | 1172 for (b = first_bloc; b; b = b->next) |
1173 { | |
1174 assert (b->prev == pb); | |
1175 assert ((POINTER) MEM_ROUNDUP (b->data) == b->data); | |
1176 assert ((SIZE) MEM_ROUNDUP (b->size) == b->size); | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1177 |
10766 | 1178 ph = 0; |
1179 for (h = first_heap; h; h = h->next) | |
1180 { | |
1181 if (h->bloc_start <= b->data && b->data + b->size <= h->end) | |
1182 break; | |
1183 ph = h; | |
1184 } | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1185 |
10766 | 1186 assert (h); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1187 |
10766 | 1188 if (pb && pb->data + pb->size != b->data) |
1189 { | |
1190 assert (ph && b->data == h->bloc_start); | |
1191 while (ph) | |
1192 { | |
1193 if (ph->bloc_start <= pb->data | |
1194 && pb->data + pb->size <= ph->end) | |
1195 { | |
1196 assert (pb->data + pb->size + b->size > ph->end); | |
1197 break; | |
1198 } | |
1199 else | |
1200 { | |
1201 assert (ph->bloc_start + b->size > ph->end); | |
1202 } | |
1203 ph = ph->prev; | |
1204 } | |
1205 } | |
1206 pb = b; | |
1207 } | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1208 |
10766 | 1209 assert (last_bloc == pb); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1210 |
10766 | 1211 if (last_bloc) |
1212 assert (last_bloc->data + last_bloc->size == break_value); | |
1213 else | |
1214 assert (first_heap->bloc_start == break_value); | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1215 } |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1216 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1217 #endif /* DEBUG */ |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1218 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1219 #endif /* not REL_ALLOC_MMAP */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1220 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1221 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1222 /*********************************************************************** |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1223 Implementation based on mmap |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1224 ***********************************************************************/ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1225 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1226 #ifdef REL_ALLOC_MMAP |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1227 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1228 #include <sys/types.h> |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1229 #include <sys/mman.h> |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1230 #include <stdio.h> |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1231 #include <errno.h> |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1232 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1233 /* Memory is allocated in regions which are mapped using mmap(2). |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1234 The current implementation let's the system select mapped |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1235 addresses; we're not using MAP_FIXED in general, except when |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1236 trying to enlarge regions. |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1237 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1238 Each mapped region starts with a mmap_region structure, the user |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1239 area starts after that structure, aligned to MEM_ALIGN. |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1240 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1241 +-----------------------+ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1242 | struct mmap_info + | |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1243 | padding | |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1244 +-----------------------+ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1245 | user data | |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1246 | | |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1247 | | |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1248 +-----------------------+ */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1249 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1250 struct mmap_region |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1251 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1252 /* User-specified size. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1253 size_t nbytes_specified; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1254 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1255 /* Number of bytes mapped */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1256 size_t nbytes_mapped; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1257 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1258 /* Pointer to the location holding the address of the memory |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1259 allocated with the mmap'd block. The variable actually points |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1260 after this structure. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1261 POINTER_TYPE **var; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1262 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1263 /* Next and previous in list of all mmap'd regions. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1264 struct mmap_region *next, *prev; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1265 }; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1266 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1267 /* Doubly-linked list of mmap'd regions. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1268 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1269 static struct mmap_region *mmap_regions; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1270 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1271 /* Temporary storage for mmap_set_vars, see there. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1272 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1273 static struct mmap_region *mmap_regions_1; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1274 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1275 /* Value is X rounded up to the next multiple of N. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1276 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1277 #define ROUND(X, N) (((X) + (N) - 1) / (N) * (N)) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1278 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1279 /* Size of mmap_region structure plus padding. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1280 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1281 #define MMAP_REGION_STRUCT_SIZE \ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1282 ROUND (sizeof (struct mmap_region), MEM_ALIGN) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1283 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1284 /* Given a pointer P to the start of the user-visible part of a mapped |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1285 region, return a pointer to the start of the region. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1286 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1287 #define MMAP_REGION(P) \ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1288 ((struct mmap_region *) ((char *) (P) - MMAP_REGION_STRUCT_SIZE)) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1289 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1290 /* Given a pointer P to the start of a mapped region, return a pointer |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1291 to the start of the user-visible part of the region. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1292 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1293 #define MMAP_USER_AREA(P) \ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1294 ((POINTER_TYPE *) ((char *) (P) + MMAP_REGION_STRUCT_SIZE)) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1295 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1296 /* Function prototypes. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1297 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1298 static int mmap_free P_ ((struct mmap_region *)); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1299 static int mmap_enlarge P_ ((struct mmap_region *, int)); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1300 static struct mmap_region *mmap_find P_ ((POINTER_TYPE *, POINTER_TYPE *)); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1301 POINTER_TYPE *r_alloc P_ ((POINTER_TYPE **, size_t)); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1302 POINTER_TYPE *r_re_alloc P_ ((POINTER_TYPE **, size_t)); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1303 void r_alloc_free P_ ((POINTER_TYPE **ptr)); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1304 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1305 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1306 /* Return a region overlapping with the address range START...END, or |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1307 null if none. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1308 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1309 static struct mmap_region * |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1310 mmap_find (start, end) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1311 POINTER_TYPE *start, *end; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1312 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1313 struct mmap_region *r; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1314 char *s = (char *) start, *e = (char *) end; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1315 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1316 for (r = mmap_regions; r; r = r->next) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1317 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1318 char *rstart = (char *) r; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1319 char *rend = rstart + r->nbytes_mapped; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1320 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1321 if ((s >= rstart && s < rend) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1322 || (e >= rstart && e < rend) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1323 || (rstart >= s && rstart < e) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1324 || (rend >= s && rend < e)) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1325 break; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1326 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1327 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1328 return r; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1329 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1330 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1331 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1332 /* Unmap a region. P is a pointer to the start of the user-araa of |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1333 the region. Value is non-zero if successful. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1334 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1335 static int |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1336 mmap_free (r) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1337 struct mmap_region *r; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1338 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1339 if (r->next) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1340 r->next->prev = r->prev; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1341 if (r->prev) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1342 r->prev->next = r->next; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1343 else |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1344 mmap_regions = r->next; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1345 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1346 if (munmap (r, r->nbytes_mapped) == -1) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1347 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1348 fprintf (stderr, "munmap: %s\n", emacs_strerror (errno)); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1349 return 0; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1350 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1351 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1352 return 1; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1353 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1354 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1355 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1356 /* Enlarge region R by NPAGES pages. NPAGES < 0 means shrink R. |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1357 Value is non-zero if successful. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1358 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1359 static int |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1360 mmap_enlarge (r, npages) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1361 struct mmap_region *r; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1362 int npages; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1363 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1364 char *region_end = (char *) r + r->nbytes_mapped; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1365 size_t nbytes; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1366 int success = 1; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1367 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1368 if (npages < 0) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1369 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1370 /* Unmap pages at the end of the region. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1371 nbytes = - npages * page_size; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1372 if (munmap (region_end - nbytes, nbytes) == -1) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1373 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1374 fprintf (stderr, "munmap: %s\n", emacs_strerror (errno)); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1375 success = 0; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1376 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1377 else |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1378 r->nbytes_mapped -= nbytes; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1379 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1380 else if (npages > 0) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1381 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1382 /* Try to map additional pages at the end of the region. We |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1383 cannot do this if the address range is already occupied by |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1384 something else because mmap deletes any previous mapping. |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1385 I'm not sure this is worth doing, let's see. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1386 if (mmap_find (region_end, region_end + nbytes)) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1387 success = 0; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1388 else |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1389 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1390 POINTER_TYPE *p; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1391 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1392 nbytes = npages * page_size; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1393 p = mmap (region_end, nbytes, PROT_READ | PROT_WRITE, |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1394 MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1395 if (p == MAP_FAILED) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1396 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1397 fprintf (stderr, "mmap: %s\n", emacs_strerror (errno)); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1398 success = 0; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1399 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1400 else if (p != (POINTER_TYPE *) region_end) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1401 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1402 /* Kernels are free to choose a different address. In |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1403 that case, unmap what we've mapped above; we have |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1404 no use for it. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1405 if (munmap (p, nbytes) == -1) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1406 fprintf (stderr, "munmap: %s\n", emacs_strerror (errno)); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1407 success = 0; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1408 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1409 else |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1410 r->nbytes_mapped += nbytes; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1411 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1412 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1413 success = 0; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1414 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1415 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1416 return success; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1417 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1418 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1419 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1420 /* Set or reset variables holding references to mapped regions. If |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1421 RESTORE_P is zero, set all variables to null. If RESTORE_P is |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1422 non-zero, set all variables to the start of the user-areas |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1423 of mapped regions. |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1424 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1425 This function is called from Fdump_emacs to ensure that the dumped |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1426 Emacs doesn't contain references to memory that won't be mapped |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1427 when Emacs starts. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1428 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1429 void |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1430 mmap_set_vars (restore_p) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1431 int restore_p; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1432 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1433 struct mmap_region *r; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1434 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1435 if (restore_p) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1436 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1437 mmap_regions = mmap_regions_1; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1438 for (r = mmap_regions; r; r = r->next) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1439 *r->var = MMAP_USER_AREA (r); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1440 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1441 else |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1442 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1443 for (r = mmap_regions; r; r = r->next) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1444 *r->var = NULL; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1445 mmap_regions_1 = mmap_regions; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1446 mmap_regions = NULL; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1447 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1448 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1449 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1450 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1451 /* Return total number of bytes mapped. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1452 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1453 size_t |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1454 mmap_mapped_bytes () |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1455 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1456 struct mmap_region *r; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1457 size_t n = 0; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1458 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1459 for (r = mmap_regions; r; r = r->next) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1460 n += r->nbytes_mapped; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1461 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1462 return n; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1463 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1464 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1465 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1466 /* Allocate a block of storage large enough to hold NBYTES bytes of |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1467 data. A pointer to the data is returned in *VAR. VAR is thus the |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1468 address of some variable which will use the data area. |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1469 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1470 The allocation of 0 bytes is valid. |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1471 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1472 If we can't allocate the necessary memory, set *VAR to null, and |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1473 return null. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1474 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1475 POINTER_TYPE * |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1476 r_alloc (var, nbytes) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1477 POINTER_TYPE **var; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1478 size_t nbytes; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1479 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1480 void *p; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1481 size_t map; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1482 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1483 if (!r_alloc_initialized) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1484 r_alloc_init (); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1485 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1486 map = ROUND (nbytes + MMAP_REGION_STRUCT_SIZE, page_size); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1487 p = mmap (NULL, map, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1488 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1489 if (p == MAP_FAILED) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1490 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1491 if (errno != ENOMEM) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1492 fprintf (stderr, "mmap: %s\n", emacs_strerror (errno)); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1493 p = NULL; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1494 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1495 else |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1496 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1497 struct mmap_region *r = (struct mmap_region *) p; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1498 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1499 r->nbytes_specified = nbytes; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1500 r->nbytes_mapped = map; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1501 r->var = var; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1502 r->prev = NULL; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1503 r->next = mmap_regions; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1504 if (r->next) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1505 r->next->prev = r; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1506 mmap_regions = r; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1507 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1508 p = MMAP_USER_AREA (p); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1509 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1510 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1511 return *var = p; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1512 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1513 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1514 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1515 /* Given a pointer at address VAR to data allocated with r_alloc, |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1516 resize it to size NBYTES. Change *VAR to reflect the new block, |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1517 and return this value. If more memory cannot be allocated, then |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1518 leave *VAR unchanged, and return null. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1519 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1520 POINTER_TYPE * |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1521 r_re_alloc (var, nbytes) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1522 POINTER_TYPE **var; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1523 size_t nbytes; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1524 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1525 POINTER_TYPE *result; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1526 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1527 if (!r_alloc_initialized) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1528 r_alloc_init (); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1529 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1530 if (*var == NULL) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1531 result = r_alloc (var, nbytes); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1532 else if (nbytes == 0) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1533 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1534 r_alloc_free (var); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1535 result = r_alloc (var, nbytes); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1536 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1537 else |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1538 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1539 struct mmap_region *r = MMAP_REGION (*var); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1540 size_t room = r->nbytes_mapped - MMAP_REGION_STRUCT_SIZE; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1541 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1542 if (room < nbytes) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1543 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1544 /* Must enlarge. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1545 POINTER_TYPE *old_ptr = *var; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1546 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1547 /* Try to map additional pages at the end of the region. |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1548 If that fails, allocate a new region, copy data |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1549 from the old region, then free it. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1550 if (mmap_enlarge (r, ROUND (nbytes - room, page_size))) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1551 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1552 r->nbytes_specified = nbytes; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1553 *var = result = old_ptr; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1554 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1555 else if (r_alloc (var, nbytes)) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1556 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1557 bcopy (old_ptr, *var, r->nbytes_specified); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1558 mmap_free (MMAP_REGION (old_ptr)); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1559 result = *var; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1560 r = MMAP_REGION (result); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1561 r->nbytes_specified = nbytes; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1562 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1563 else |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1564 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1565 *var = old_ptr; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1566 result = NULL; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1567 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1568 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1569 else if (room - nbytes >= page_size) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1570 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1571 /* Shrinking by at least a page. Let's give some |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1572 memory back to the system. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1573 mmap_enlarge (r, - (room - nbytes) / page_size); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1574 result = *var; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1575 r->nbytes_specified = nbytes; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1576 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1577 else |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1578 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1579 /* Leave it alone. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1580 result = *var; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1581 r->nbytes_specified = nbytes; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1582 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1583 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1584 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1585 return result; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1586 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1587 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1588 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1589 /* Free a block of relocatable storage whose data is pointed to by |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1590 PTR. Store 0 in *PTR to show there's no block allocated. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1591 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1592 void |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1593 r_alloc_free (var) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1594 POINTER_TYPE **var; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1595 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1596 if (!r_alloc_initialized) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1597 r_alloc_init (); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1598 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1599 if (*var) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1600 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1601 mmap_free (MMAP_REGION (*var)); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1602 *var = NULL; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1603 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1604 } |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1605 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1606 #endif /* REL_ALLOC_MMAP */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1607 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1608 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1609 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1610 /*********************************************************************** |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1611 Initialization |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1612 ***********************************************************************/ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1613 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1614 /* The hook `malloc' uses for the function which gets more space |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1615 from the system. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1616 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1617 extern POINTER (*__morecore) (); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1618 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1619 /* Initialize various things for memory allocation. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1620 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1621 static void |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1622 r_alloc_init () |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1623 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1624 if (r_alloc_initialized) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1625 return; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1626 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1627 r_alloc_initialized = 1; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1628 real_morecore = __morecore; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1629 __morecore = r_alloc_sbrk; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1630 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1631 first_heap = last_heap = &heap_base; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1632 first_heap->next = first_heap->prev = NIL_HEAP; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1633 first_heap->start = first_heap->bloc_start |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1634 = virtual_break_value = break_value = (*real_morecore) (0); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1635 if (break_value == NIL) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1636 abort (); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1637 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1638 page_size = PAGE; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1639 extra_bytes = ROUNDUP (50000); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1640 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1641 #ifdef DOUG_LEA_MALLOC |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1642 mallopt (M_TOP_PAD, 64 * 4096); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1643 #else |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1644 /* Give GNU malloc's morecore some hysteresis |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1645 so that we move all the relocatable blocks much less often. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1646 __malloc_extra_blocks = 64; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1647 #endif |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1648 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1649 first_heap->end = (POINTER) ROUNDUP (first_heap->start); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1650 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1651 /* The extra call to real_morecore guarantees that the end of the |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1652 address space is a multiple of page_size, even if page_size is |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1653 not really the page size of the system running the binary in |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1654 which page_size is stored. This allows a binary to be built on a |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1655 system with one page size and run on a system with a smaller page |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1656 size. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1657 (*real_morecore) (first_heap->end - first_heap->start); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1658 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1659 /* Clear the rest of the last page; this memory is in our address space |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1660 even though it is after the sbrk value. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1661 /* Doubly true, with the additional call that explicitly adds the |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1662 rest of that page to the address space. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1663 bzero (first_heap->start, first_heap->end - first_heap->start); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1664 virtual_break_value = break_value = first_heap->bloc_start = first_heap->end; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1665 use_relocatable_buffers = 1; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1666 } |