annotate src/ralloc.c @ 1537:8531c6d96e5c

(make-directory): Renamed from make-directory-path. Optional argument says whether to create parent dirs. Invoke file-name handler here. (after-find-file): Delete code that offers to create dir. Instead, just print a message.
author Richard M. Stallman <rms@gnu.org>
date Tue, 03 Nov 1992 07:07:02 +0000
parents 6359d8850fa3
children ac1be1d32868
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Block-relocating memory allocator.
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
2 Copyright (C) 1992 Free Software Foundation, Inc.
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 the Free Software Foundation; either version 1, or (at your option)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 any later version.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 GNU General Public License for more details.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 /* NOTES:
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 Only relocate the blocs neccessary for SIZE in r_alloc_sbrk,
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 rather than all of them. This means allowing for a possible
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 hole between the first bloc and the end of malloc storage. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
26 #ifdef emacs
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
27
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 #include "config.h"
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
29 #include "lisp.h" /* Needed for VALBITS. */
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
30
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
31 #undef NULL
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
32
1451
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
33 /* The important properties of this type are that 1) it's a pointer, and
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
34 2) arithmetic on it should work as if the size of the object pointed
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
35 to has a size of 1. */
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
36 #ifdef __STDC__
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
37 typedef void *POINTER;
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
38 #else
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
39 typedef char *POINTER;
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
40 #endif
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
41
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
42 typedef unsigned long SIZE;
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
43
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
44 /* 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
45 overlap. */
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
46 extern void safe_bcopy ();
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
47
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
48 #include "getpagesize.h"
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
49
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
50 #else /* Not emacs. */
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
51
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
52 #include <stddef.h>
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
53
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
54 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
55 typedef void *POINTER;
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
56
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
57 #include <unistd.h>
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
58 #include <malloc.h>
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
59 #include <string.h>
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
60
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
61 #define safe_bcopy(x, y, z) memmove (y, x, z)
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
62
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
63 #endif /* emacs. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 #define NIL ((POINTER) 0)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
67 /* 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
68 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
69 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
70 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
71 the empty string, meaning that r_alloc_initialized becomes an
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
72 automatic variable, and loses its value each time Emacs is started up. */
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
73 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
74
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
75 static void r_alloc_init ();
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
77 /* Declarations for working with the malloc, ralloc, and system breaks. */
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
78
1401
9689db083f88 (sbrk): Removed decl.
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
79 /* Function to set the real break value. */
9689db083f88 (sbrk): Removed decl.
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
80 static POINTER (*real_morecore) ();
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 /* The break value, as seen by malloc (). */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 static POINTER virtual_break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 /* The break value, viewed by the relocatable blocs. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 static POINTER break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 /* The REAL (i.e., page aligned) break value of the process. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 static POINTER page_break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
91 /* 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
92 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
93
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
94 /* Whenever we get memory from the system, get this many 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
95 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
96
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 /* Macros for rounding. Note that rounding to any value is possible
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 by changing the definition of PAGE. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 #define PAGE (getpagesize ())
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
100 #define ALIGNED(addr) (((unsigned int) (addr) & (page_size - 1)) == 0)
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
101 #define ROUNDUP(size) (((unsigned int) (size) + page_size - 1) & ~(page_size - 1))
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
102 #define ROUND_TO_PAGE(addr) (addr & (~(page_size - 1)))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
104 /* Functions to get and return memory from the system. */
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
105
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 /* Obtain SIZE bytes of space. If enough space is not presently available
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 in our process reserve, (i.e., (page_break_value - break_value)),
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
108 this means getting more page-aligned space from the system.
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
110 Return non-zero if all went well, 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
111 the memory. */
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
112 static int
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 obtain (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 SIZE already_available = page_break_value - break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 if (already_available < size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 {
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
120 SIZE get = ROUNDUP (size - already_available);
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
121 /* Get some extra, so we can come here less often. */
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
122 get += extra_bytes;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123
1401
9689db083f88 (sbrk): Removed decl.
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
124 if ((*real_morecore) (get) == 0)
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
125 return 0;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 page_break_value += get;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 break_value += size;
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
131
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
132 return 1;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
135 /* Obtain SIZE bytes of space and return a pointer to the new area.
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
136 If we could not allocate the space, return zero. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 static POINTER
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 get_more_space (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 POINTER ptr = break_value;
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
143 if (obtain (size))
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
144 return ptr;
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
145 else
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
146 return 0;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 /* Note that SIZE bytes of space have been relinquished by the process.
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
150 If SIZE is more than a page, return the space to the system. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 static void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 relinquish (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 {
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
156 POINTER new_page_break;
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
157 int excess;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
159 break_value -= size;
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
160 new_page_break = (POINTER) ROUNDUP (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
161 excess = (char *) page_break_value - (char *) new_page_break;
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
162
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
163 if (excess > extra_bytes * 2)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 {
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
165 /* Keep extra_bytes worth of empty space.
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
166 And don't free anything unless we can free at least 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
167 if ((*real_morecore) (extra_bytes - excess) == 0)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
170 page_break_value += extra_bytes - excess;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
173 /* Zero the space from the end of the "official" break to the actual
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
174 break, so that bugs show up faster. */
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
175 bzero (break_value, ((char *) page_break_value - (char *) break_value));
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
178 /* The meat - allocating, freeing, and relocating blocs. */
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
179
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
180 /* These structures are allocated in the malloc arena.
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
181 The linked list is kept in order of increasing '.data' members.
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
182 The data blocks abut each other; if b->next is non-nil, then
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
183 b->data + b->size == b->next->data. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 typedef struct bp
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 struct bp *next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 struct bp *prev;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 POINTER *variable;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 POINTER data;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 } *bloc_ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 #define NIL_BLOC ((bloc_ptr) 0)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 #define BLOC_PTR_SIZE (sizeof (struct bp))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 /* Head and tail of the list of relocatable blocs. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 static bloc_ptr first_bloc, last_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
199 /* Find the bloc referenced by the address in PTR. Returns a pointer
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 to that block. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 static bloc_ptr
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 find_bloc (ptr)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 POINTER *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 register bloc_ptr p = first_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 while (p != NIL_BLOC)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 if (p->variable == ptr && p->data == *ptr)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 return p;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 p = p->next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 return p;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 /* 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
220 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
221 memory for the new block. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 static bloc_ptr
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 get_bloc (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 {
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
227 register bloc_ptr new_bloc;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
229 if (! (new_bloc = (bloc_ptr) malloc (BLOC_PTR_SIZE))
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
230 || ! (new_bloc->data = get_more_space (size)))
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
231 {
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
232 if (new_bloc)
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
233 free (new_bloc);
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
234
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
235 return 0;
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
236 }
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
237
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 new_bloc->size = size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 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
240 new_bloc->variable = (POINTER *) NIL;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 if (first_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 new_bloc->prev = last_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 last_bloc->next = new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 last_bloc = new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 else
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 first_bloc = last_bloc = new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 new_bloc->prev = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 return new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 /* Relocate all blocs from BLOC on upward in the list to the zone
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 indicated by ADDRESS. Direction of relocation is determined by
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 the position of ADDRESS relative to BLOC->data.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 Note that ordering of blocs is not affected by this function. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 static void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 relocate_some_blocs (bloc, address)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 bloc_ptr bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 POINTER address;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 register bloc_ptr b;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 POINTER data_zone = bloc->data;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 register SIZE data_zone_size = 0;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 register SIZE offset = bloc->data - address;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 POINTER new_data_zone = data_zone - offset;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 for (b = bloc; b != NIL_BLOC; b = b->next)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 data_zone_size += b->size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 b->data -= offset;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 *b->variable = b->data;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 safe_bcopy (data_zone, new_data_zone, data_zone_size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 /* Free BLOC from the chain of blocs, relocating any blocs above it
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 and returning BLOC->size bytes to the free area. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 static void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 free_bloc (bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 bloc_ptr bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 if (bloc == first_bloc && bloc == last_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 first_bloc = last_bloc = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 else if (bloc == last_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 last_bloc = bloc->prev;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 last_bloc->next = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 else if (bloc == first_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 first_bloc = bloc->next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 first_bloc->prev = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 relocate_some_blocs (bloc->next, bloc->data);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 else
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 bloc->next->prev = bloc->prev;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 bloc->prev->next = bloc->next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 relocate_some_blocs (bloc->next, bloc->data);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 relinquish (bloc->size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 free (bloc);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
317 /* Interface routines. */
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
318
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 static int use_relocatable_buffers;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
321 /* 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
322 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
323 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
324 hook.
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
325
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
326 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
327
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
328 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
329 __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
330 GNU malloc package. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 POINTER
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 r_alloc_sbrk (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 long size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 {
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
336 /* This is the first address not currently available for the heap. */
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
337 POINTER top;
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
338 /* Amount of empty space below that. */
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
339 SIZE already_available;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 POINTER ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 if (! use_relocatable_buffers)
1401
9689db083f88 (sbrk): Removed decl.
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
343 return (*real_morecore) (size);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
345 top = first_bloc ? first_bloc->data : page_break_value;
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
346 already_available = (char *) top - (char *) virtual_break_value;
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
347
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
348 /* Do we not have enough gap already? */
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
349 if (size > 0 && already_available < size)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 {
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
351 /* Get what we need, plus some extra so we can come here less often. */
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
352 SIZE get = size - already_available + 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
353
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
354 if (! obtain (get))
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
355 return 0;
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
356
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 if (first_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 {
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
359 relocate_some_blocs (first_bloc, first_bloc->data + get);
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
360
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
361 /* Zero out the space we just allocated, to help catch bugs
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
362 quickly. */
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
363 bzero (virtual_break_value, get);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 }
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
366 /* Can we keep extra_bytes of gap while freeing at least 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
367 else if (size < 0 && already_available - size > 2 * extra_bytes)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 {
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
369 /* Ok, do so. This is how many to free. */
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
370 SIZE give_back = already_available - size - 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
371
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 if (first_bloc)
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
373 relocate_some_blocs (first_bloc, first_bloc->data - give_back);
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
374 relinquish (give_back);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 ptr = virtual_break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 virtual_break_value += 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
379
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 return ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 /* Allocate a relocatable bloc of storage of size SIZE. A pointer to
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 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
385 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
386
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
387 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
388 return zero. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 POINTER
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 r_alloc (ptr, size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 POINTER *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 register bloc_ptr new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
397 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
398 r_alloc_init ();
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
399
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 new_bloc = get_bloc (size);
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
401 if (new_bloc)
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
402 {
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
403 new_bloc->variable = ptr;
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
404 *ptr = new_bloc->data;
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
405 }
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
406 else
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
407 *ptr = 0;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 return *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
412 /* 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
413 Store 0 in *PTR to show there's no block allocated. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 r_alloc_free (ptr)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 register POINTER *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 register bloc_ptr dead_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 dead_bloc = find_bloc (ptr);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 if (dead_bloc == NIL_BLOC)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 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
426 *ptr = 0;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428
1087
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
429 /* 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
430 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
431 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
432 do nothing.
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
434 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
435
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
436 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
437 return zero. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 POINTER
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 r_re_alloc (ptr, size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 POINTER *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 {
1087
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
444 register bloc_ptr bloc;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445
1087
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
446 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
447 if (bloc == NIL_BLOC)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449
1087
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
450 if (size <= bloc->size)
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
451 /* Wouldn't it be useful to actually resize the bloc here? */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 return *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
454 if (! obtain (size - bloc->size))
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
455 return 0;
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
456
1087
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
457 relocate_some_blocs (bloc->next, bloc->data + size);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458
1087
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
459 /* Zero out the new space in the bloc, to help catch bugs faster. */
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
460 bzero (bloc->data + bloc->size, size - bloc->size);
1121
4b61400a5195 Fix typo.
Jim Blandy <jimb@redhat.com>
parents: 1087
diff changeset
461
1087
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
462 /* Indicate that this block has a new size. */
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
463 bloc->size = size;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 return *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468 /* The hook `malloc' uses for the function which gets more space
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 from the system. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 extern POINTER (*__morecore) ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 /* Intialize various things for memory allocation. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
474 static void
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
475 r_alloc_init ()
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
476 {
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
477 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
478 return;
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
479
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
480 r_alloc_initialized = 1;
1401
9689db083f88 (sbrk): Removed decl.
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
481 real_morecore = __morecore;
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
482 __morecore = r_alloc_sbrk;
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
483
1401
9689db083f88 (sbrk): Removed decl.
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
484 virtual_break_value = break_value = (*real_morecore) (0);
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
485 if (break_value == NIL)
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
486 abort ();
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
487
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
488 page_size = PAGE;
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
489 extra_bytes = ROUNDUP (50000);
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
490
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
491 page_break_value = (POINTER) ROUNDUP (break_value);
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
492 /* Clear the rest of the last page; this memory is in our address space
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
493 even though it is after the sbrk value. */
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
494 bzero (break_value, (page_break_value - break_value));
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
495 use_relocatable_buffers = 1;
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
496 }