annotate src/ralloc.c @ 8275:4fdf77f4e45c

type-break-mode: New variable and function. type-break-interval: Increase default to 1 hour. type-break-query-interval: Variable renamed from type-break-delay-interval. type-break-keystroke-interval: Variable deleted. type-break-keystroke-threshold: New variable. type-break-demo-life: Function renamed from type-break-life. type-break-demo-hanoi: Function renamed from type-break-hanoi. type-break-alarm-p: Variable renamed from type-break-p. type-break: Don't query. type-break-query: (New function) query here. type-break-check: Call type-break-query, not type-break. Do nothing if type-break-mode is nil. Increment type-break-keystroke-count with the length of this-command-keys, not just 1. Query for break when keystroke count exceeds cdr of keystroke threshold variable. Query for break after an alarm only if keystroke count exceeds car of keystroke threshold variable. type-break-select: Function deleted. type-break: Move that code here. type-break-cancel-schedule: Function renamed from cancel-type-break. Reset type-break-alarm-p. type-break-alarm: Function renamed from type-break-soon. (top level): Call type-break-mode; don't set up hook explicitly.
author Noah Friedman <friedman@splode.com>
date Mon, 18 Jul 1994 07:37:18 +0000
parents 9ab921a16318
children b628561b185b
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.
2961
e94a593c3952 Updated copyright years.
Jim Blandy <jimb@redhat.com>
parents: 1729
diff changeset
2 Copyright (C) 1993 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
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3136
diff changeset
22 Only relocate the blocs necessary for SIZE in r_alloc_sbrk,
118
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
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 4230
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. */
3109
cd1bbe721cb5 (POINTER): Always use char *.
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
36 #if 0 /* Arithmetic on void* is a GCC extension. */
1451
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
37 #ifdef __STDC__
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
38 typedef void *POINTER;
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
39 #else
1729
5c3898c5aa2d [! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents: 1595
diff changeset
40
5c3898c5aa2d [! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents: 1595
diff changeset
41 #ifdef HAVE_CONFIG_H
5c3898c5aa2d [! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents: 1595
diff changeset
42 #include "config.h"
5c3898c5aa2d [! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents: 1595
diff changeset
43 #endif
5c3898c5aa2d [! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents: 1595
diff changeset
44
1451
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
45 typedef char *POINTER;
1729
5c3898c5aa2d [! emacs] [HAVE_CONFIG_H]: #include "config.h"
Roland McGrath <roland@gnu.org>
parents: 1595
diff changeset
46
1451
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
47 #endif
3109
cd1bbe721cb5 (POINTER): Always use char *.
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
48 #endif /* 0 */
cd1bbe721cb5 (POINTER): Always use char *.
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
49
cd1bbe721cb5 (POINTER): Always use char *.
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
50 /* Unconditionally use char * for this. */
cd1bbe721cb5 (POINTER): Always use char *.
Richard M. Stallman <rms@gnu.org>
parents: 2961
diff changeset
51 typedef char *POINTER;
1451
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
52
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
diff changeset
53 typedef unsigned long SIZE;
107c9b227e7f [emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 1403
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 /* 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
56 overlap. */
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
57 extern void safe_bcopy ();
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
58
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
59 #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
60
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
61 #else /* Not emacs. */
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
62
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
63 #include <stddef.h>
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
64
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
65 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
66 typedef void *POINTER;
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
67
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
68 #include <unistd.h>
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
69 #include <malloc.h>
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
70 #include <string.h>
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
71
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
72 #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
73
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
74 #endif /* emacs. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 #define NIL ((POINTER) 0)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
78 /* 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
79 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
80 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
81 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
82 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
83 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
84 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
85
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
86 static void r_alloc_init ();
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
88 /* Declarations for working with the malloc, ralloc, and system breaks. */
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
89
1401
9689db083f88 (sbrk): Removed decl.
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
90 /* Function to set the real break value. */
9689db083f88 (sbrk): Removed decl.
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
91 static POINTER (*real_morecore) ();
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 /* The break value, as seen by malloc (). */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 static POINTER virtual_break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 /* The break value, viewed by the relocatable blocs. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 static POINTER break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 /* The REAL (i.e., page aligned) break value of the process. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 static POINTER page_break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101
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 /* 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
103 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
104
1595
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
105 /* 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
106 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
107 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
108
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 /* Macros for rounding. Note that rounding to any value is possible
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 by changing the definition of PAGE. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 #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
112 #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
113 #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
114 & ~(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
115 #define ROUND_TO_PAGE(addr) (addr & (~(page_size - 1)))
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
117 /* Functions to get and return memory from the system. */
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
118
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 /* Obtain SIZE bytes of space. If enough space is not presently available
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 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
121 this means getting more page-aligned space from the system.
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
123 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
124 the memory. */
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
125 static int
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 obtain (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 SIZE already_available = page_break_value - break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 if (already_available < size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 {
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
133 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
134 /* 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
135 get += extra_bytes;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136
1401
9689db083f88 (sbrk): Removed decl.
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
137 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
138 return 0;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 page_break_value += get;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 break_value += size;
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
144
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
145 return 1;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
148 /* 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
149 If we could not allocate the space, return zero. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 static POINTER
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 get_more_space (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 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
156 if (obtain (size))
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
157 return ptr;
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
158 else
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
159 return 0;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 /* 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
163 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
164
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 static void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 relinquish (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 {
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
169 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
170 int excess;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
172 break_value -= size;
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
173 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
174 excess = (char *) page_break_value - (char *) new_page_break;
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
175
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
176 if (excess > extra_bytes * 2)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 {
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
178 /* 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
179 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
180 if ((*real_morecore) (extra_bytes - excess) == 0)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
183 page_break_value += extra_bytes - excess;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
186 /* 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
187 break, so that bugs show up faster. */
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
188 bzero (break_value, ((char *) page_break_value - (char *) break_value));
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
191 /* The meat - allocating, freeing, and relocating blocs. */
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
192
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
193 /* These structures are allocated in the malloc arena.
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
194 The linked list is kept in order of increasing '.data' members.
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
195 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
196 b->data + b->size == b->next->data. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 typedef struct bp
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 struct bp *next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 struct bp *prev;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 POINTER *variable;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 POINTER data;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 } *bloc_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 #define NIL_BLOC ((bloc_ptr) 0)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 #define BLOC_PTR_SIZE (sizeof (struct bp))
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 /* Head and tail of the list of relocatable blocs. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 static bloc_ptr first_bloc, last_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
212 /* Find the bloc referenced by the address in PTR. Returns a pointer
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 to that block. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 static bloc_ptr
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 find_bloc (ptr)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 POINTER *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 register bloc_ptr p = first_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 while (p != NIL_BLOC)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 if (p->variable == ptr && p->data == *ptr)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 return p;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 p = p->next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 return p;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 /* 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
233 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
234 memory for the new block. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 static bloc_ptr
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 get_bloc (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 {
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
240 register bloc_ptr new_bloc;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
242 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
243 || ! (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
244 {
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
245 if (new_bloc)
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
246 free (new_bloc);
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
247
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
248 return 0;
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
249 }
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
250
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 new_bloc->size = size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 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
253 new_bloc->variable = (POINTER *) NIL;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 if (first_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 new_bloc->prev = last_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 last_bloc->next = new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 last_bloc = new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 else
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 first_bloc = last_bloc = new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 new_bloc->prev = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 return new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 /* Relocate all blocs from BLOC on upward in the list to the zone
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 indicated by ADDRESS. Direction of relocation is determined by
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 the position of ADDRESS relative to BLOC->data.
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273
1595
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
274 If BLOC is NIL_BLOC, nothing is done.
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
275
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 Note that ordering of blocs is not affected by this function. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 static void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 relocate_some_blocs (bloc, address)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 bloc_ptr bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 POINTER address;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 {
1595
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
283 if (bloc != NIL_BLOC)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 {
1595
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
285 register SIZE offset = address - bloc->data;
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
286 register SIZE data_size = 0;
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
287 register bloc_ptr b;
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
288
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
289 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
290 {
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
291 data_size += b->size;
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
292 b->data += offset;
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
293 *b->variable = b->data;
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
294 }
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
295
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
296 safe_bcopy (address - offset, address, data_size);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 }
1595
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
298 }
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 /* Free BLOC from the chain of blocs, relocating any blocs above it
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 and returning BLOC->size bytes to the free area. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 static void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 free_bloc (bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 bloc_ptr bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 if (bloc == first_bloc && bloc == last_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 first_bloc = last_bloc = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 else if (bloc == last_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 last_bloc = bloc->prev;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 last_bloc->next = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 else if (bloc == first_bloc)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 first_bloc = bloc->next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 first_bloc->prev = NIL_BLOC;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 else
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 bloc->next->prev = bloc->prev;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 bloc->prev->next = bloc->next;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327
1595
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
328 relocate_some_blocs (bloc->next, bloc->data);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 relinquish (bloc->size);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 free (bloc);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
333 /* Interface routines. */
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
334
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 static int use_relocatable_buffers;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
337 /* 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
338 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
339 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
340 hook.
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
341
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
342 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
343
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
344 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
345 __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
346 GNU malloc package. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 POINTER
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 r_alloc_sbrk (size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 long size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 {
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
352 /* 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
353 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
354 /* Amount of empty space below that. */
3136
76c8b5e00948 (r_alloc_sbrk): Declare already_available as long, not SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 3109
diff changeset
355 /* It is not correct to use SIZE here, because that is usually unsigned.
76c8b5e00948 (r_alloc_sbrk): Declare already_available as long, not SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 3109
diff changeset
356 ptrdiff_t would be okay, but is not always available.
76c8b5e00948 (r_alloc_sbrk): Declare already_available as long, not SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 3109
diff changeset
357 `long' will work in all cases, in practice. */
76c8b5e00948 (r_alloc_sbrk): Declare already_available as long, not SIZE.
Richard M. Stallman <rms@gnu.org>
parents: 3109
diff changeset
358 long already_available;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 POINTER ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 if (! use_relocatable_buffers)
1401
9689db083f88 (sbrk): Removed decl.
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
362 return (*real_morecore) (size);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
364 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
365 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
366
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
367 /* 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
368 if (size > 0 && already_available < size)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 {
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
370 /* 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
371 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
372
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
373 if (! obtain (get))
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
374 return 0;
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
375
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 if (first_bloc)
1595
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
377 relocate_some_blocs (first_bloc, first_bloc->data + get);
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
378
1595
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
379 /* Zero out the space we just allocated, to help catch bugs
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
380 quickly. */
ac1be1d32868 * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents: 1473
diff changeset
381 bzero (virtual_break_value, get);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 }
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
383 /* 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
384 else if (size < 0 && already_available - size > 2 * extra_bytes)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 {
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
386 /* 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
387 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
388
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 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
390 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
391 relinquish (give_back);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 ptr = virtual_break_value;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 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
396
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 return ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 /* Allocate a relocatable bloc of storage of size SIZE. A pointer to
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 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
402 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
403
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
404 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
405 return zero. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 POINTER
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 r_alloc (ptr, size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 POINTER *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 register bloc_ptr new_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
414 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
415 r_alloc_init ();
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
416
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 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
418 if (new_bloc)
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
419 {
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
420 new_bloc->variable = ptr;
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
421 *ptr = new_bloc->data;
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
422 }
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
423 else
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
424 *ptr = 0;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 return *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
429 /* 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
430 Store 0 in *PTR to show there's no block allocated. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 void
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 r_alloc_free (ptr)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 register POINTER *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 {
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 register bloc_ptr dead_bloc;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 dead_bloc = find_bloc (ptr);
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 if (dead_bloc == NIL_BLOC)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 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
443 *ptr = 0;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 }
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 /* 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
447 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
448 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
449 do nothing.
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
451 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
452
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
453 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
454 return zero. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 POINTER
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457 r_re_alloc (ptr, size)
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458 POINTER *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 SIZE size;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 {
1087
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
461 register bloc_ptr bloc;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462
1087
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 = 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
464 if (bloc == NIL_BLOC)
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 abort ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466
1087
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
467 if (size <= bloc->size)
577
53f29271d1b0 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 485
diff changeset
468 /* Wouldn't it be useful to actually resize the bloc here? */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 return *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470
1249
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
471 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
472 return 0;
761b9b4fd3ed * ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents: 1121
diff changeset
473
1087
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
474 relocate_some_blocs (bloc->next, bloc->data + size);
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475
1087
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
476 /* 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
477 bzero (bloc->data + bloc->size, size - bloc->size);
1121
4b61400a5195 Fix typo.
Jim Blandy <jimb@redhat.com>
parents: 1087
diff changeset
478
1087
6c410cc87574 * ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents: 1013
diff changeset
479 /* 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
480 bloc->size = size;
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
481
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
482 return *ptr;
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
483 }
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
484
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485 /* The hook `malloc' uses for the function which gets more space
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486 from the system. */
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 extern POINTER (*__morecore) ();
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 3136
diff changeset
489 /* Initialize various things for memory allocation. */
118
49342840ba00 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
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 static void
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
492 r_alloc_init ()
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
493 {
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
494 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
495 return;
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
496
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
497 r_alloc_initialized = 1;
1401
9689db083f88 (sbrk): Removed decl.
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
498 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
499 __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
500
1401
9689db083f88 (sbrk): Removed decl.
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
501 virtual_break_value = break_value = (*real_morecore) (0);
1403
f0ea279194f8 Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents: 1401
diff changeset
502 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
503 abort ();
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
504
1473
6359d8850fa3 (relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents: 1451
diff changeset
505 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
506 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
507
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
508 page_break_value = (POINTER) ROUNDUP (break_value);
5063
9ab921a16318 (r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
509
9ab921a16318 (r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
510 /* The extra call to real_morecore guarantees that the end of the
9ab921a16318 (r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
511 address space is a multiple of page_size, even if page_size is
9ab921a16318 (r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
512 not really the page size of the system running the binary in
9ab921a16318 (r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
513 which page_size is stored. This allows a binary to be built on a
9ab921a16318 (r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
514 system with one page size and run on a system with a smaller page
9ab921a16318 (r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
515 size. */
9ab921a16318 (r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
516 (*real_morecore) (page_break_value - break_value);
9ab921a16318 (r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
517
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
518 /* 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
519 even though it is after the sbrk value. */
5063
9ab921a16318 (r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
520 /* Doubly true, with the additional call that explicitly adds the
9ab921a16318 (r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
521 rest of that page to the address space. */
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
522 bzero (break_value, (page_break_value - break_value));
5063
9ab921a16318 (r_alloc_init): Explicitly use real_morecore
Richard M. Stallman <rms@gnu.org>
parents: 4696
diff changeset
523 virtual_break_value = break_value = page_break_value;
1390
92df75f4167f (check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 1249
diff changeset
524 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
525 }