Mercurial > emacs
annotate src/w32heap.c @ 18941:3fcfe59102ac
Customized.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 24 Jul 1997 07:43:07 +0000 |
parents | bcc706aedcea |
children | 16e69fbdbf0f |
rev | line source |
---|---|
16884
36babc489b0c
Change all uses of win95, winnt, and win32
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
1 /* Heap management routines for GNU Emacs on the Microsoft W32 API. |
9803 | 2 Copyright (C) 1994 Free Software Foundation, Inc. |
3 | |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
12452
diff
changeset
|
4 This file is part of GNU Emacs. |
9803 | 5 |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
12452
diff
changeset
|
6 GNU Emacs is free software; you can redistribute it and/or modify |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
12452
diff
changeset
|
7 it under the terms of the GNU General Public License as published by |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
12452
diff
changeset
|
8 the Free Software Foundation; either version 2, or (at your option) |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
12452
diff
changeset
|
9 any later version. |
9803 | 10 |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
12452
diff
changeset
|
11 GNU Emacs is distributed in the hope that it will be useful, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
12452
diff
changeset
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
12452
diff
changeset
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
12452
diff
changeset
|
14 GNU General Public License for more details. |
9803 | 15 |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
12452
diff
changeset
|
16 You should have received a copy of the GNU General Public License |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
12452
diff
changeset
|
17 along with GNU Emacs; see the file COPYING. If not, write to |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
12452
diff
changeset
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
12452
diff
changeset
|
19 Boston, MA 02111-1307, USA. |
9803 | 20 |
21 Geoff Voelker (voelker@cs.washington.edu) 7-29-94 | |
22 */ | |
23 | |
12452
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
24 #include "config.h" |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
25 |
9803 | 26 #include <stdlib.h> |
27 #include <stdio.h> | |
28 | |
16593
4ed80eda6fac
Use new names for w32 files
Geoff Voelker <voelker@cs.washington.edu>
parents:
16588
diff
changeset
|
29 #include "w32heap.h" |
15143
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
30 #include "lisp.h" /* for VALMASK */ |
9803 | 31 |
32 /* This gives us the page size and the size of the allocation unit on NT. */ | |
33 SYSTEM_INFO sysinfo_cache; | |
12452
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
34 unsigned long syspage_mask = 0; |
9803 | 35 |
36 /* These are defined to get Emacs to compile, but are not used. */ | |
37 int edata; | |
38 int etext; | |
39 | |
40 /* The major and minor versions of NT. */ | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15228
diff
changeset
|
41 int w32_major_version; |
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15228
diff
changeset
|
42 int w32_minor_version; |
9803 | 43 |
44 /* Cache information describing the NT system for later use. */ | |
45 void | |
46 cache_system_info (void) | |
47 { | |
48 union | |
49 { | |
50 struct info | |
51 { | |
52 char major; | |
53 char minor; | |
54 short platform; | |
55 } info; | |
56 DWORD data; | |
57 } version; | |
58 | |
59 /* Cache the version of the operating system. */ | |
60 version.data = GetVersion (); | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15228
diff
changeset
|
61 w32_major_version = version.info.major; |
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15228
diff
changeset
|
62 w32_minor_version = version.info.minor; |
9803 | 63 |
64 /* Cache page size, allocation unit, processor type, etc. */ | |
65 GetSystemInfo (&sysinfo_cache); | |
12452
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
66 syspage_mask = sysinfo_cache.dwPageSize - 1; |
9803 | 67 } |
68 | |
18506
bcc706aedcea
Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
69 /* Emulate getpagesize. */ |
bcc706aedcea
Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
70 int |
bcc706aedcea
Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
71 getpagesize (void) |
bcc706aedcea
Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
72 { |
bcc706aedcea
Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
73 return sysinfo_cache.dwPageSize; |
bcc706aedcea
Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
74 } |
bcc706aedcea
Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
75 |
9803 | 76 /* Round ADDRESS up to be aligned with ALIGN. */ |
77 unsigned char * | |
78 round_to_next (unsigned char *address, unsigned long align) | |
79 { | |
80 unsigned long tmp; | |
81 | |
82 tmp = (unsigned long) address; | |
83 tmp = (tmp + align - 1) / align; | |
84 | |
85 return (unsigned char *) (tmp * align); | |
86 } | |
87 | |
18506
bcc706aedcea
Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
88 /* Force zero initialized variables to be placed in the .data segment; |
bcc706aedcea
Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
89 MSVC 5.0 otherwise places them in .bss, which breaks the dumping code. */ |
bcc706aedcea
Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
90 #pragma data_seg(".data") |
bcc706aedcea
Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
91 |
9803 | 92 /* Info for keeping track of our heap. */ |
93 unsigned char *data_region_base = NULL; | |
94 unsigned char *data_region_end = NULL; | |
12452
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
95 unsigned char *real_data_region_end = NULL; |
9803 | 96 unsigned long data_region_size = 0; |
11943
ea533622fb8b
(reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11385
diff
changeset
|
97 unsigned long reserved_heap_size = 0; |
9803 | 98 |
99 /* The start of the data segment. */ | |
100 unsigned char * | |
101 get_data_start (void) | |
102 { | |
103 return data_region_base; | |
104 } | |
105 | |
106 /* The end of the data segment. */ | |
107 unsigned char * | |
108 get_data_end (void) | |
109 { | |
110 return data_region_end; | |
111 } | |
112 | |
11943
ea533622fb8b
(reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11385
diff
changeset
|
113 static char * |
ea533622fb8b
(reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11385
diff
changeset
|
114 allocate_heap (void) |
ea533622fb8b
(reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11385
diff
changeset
|
115 { |
15143
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
116 /* The base address for our GNU malloc heap is chosen in conjuction |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
117 with the link settings for temacs.exe which control the stack size, |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
118 the initial default process heap size and the executable image base |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
119 address. The link settings and the malloc heap base below must all |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
120 correspond; the relationship between these values depends on how NT |
16884
36babc489b0c
Change all uses of win95, winnt, and win32
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
121 and Windows 95 arrange the virtual address space for a process (and on |
15143
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
122 the size of the code and data segments in temacs.exe). |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
123 |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
124 The most important thing is to make base address for the executable |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
125 image high enough to leave enough room between it and the 4MB floor |
16884
36babc489b0c
Change all uses of win95, winnt, and win32
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
126 of the process address space on Windows 95 for the primary thread stack, |
15143
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
127 the process default heap, and other assorted odds and ends |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
128 (eg. environment strings, private system dll memory etc) that are |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
129 allocated before temacs has a chance to grab its malloc arena. The |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
130 malloc heap base can then be set several MB higher than the |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
131 executable image base, leaving enough room for the code and data |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
132 segments. |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
133 |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
134 Because some parts of Emacs can use rather a lot of stack space |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
135 (for instance, the regular expression routines can potentially |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
136 allocate several MB of stack space) we allow 8MB for the stack. |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
137 |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
138 Allowing 1MB for the default process heap, and 1MB for odds and |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
139 ends, we can base the executable at 16MB and still have a generous |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
140 safety margin. At the moment, the executable has about 810KB of |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
141 code (for x86) and about 550KB of data - on RISC platforms the code |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
142 size could be roughly double, so if we allow 4MB for the executable |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
143 we will have plenty of room for expansion. |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
144 |
15208
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
145 Thus we would like to set the malloc heap base to 20MB. However, |
16884
36babc489b0c
Change all uses of win95, winnt, and win32
Geoff Voelker <voelker@cs.washington.edu>
parents:
16593
diff
changeset
|
146 Windows 95 refuses to allocate the heap starting at this address, so we |
15208
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
147 set the base to 27MB to make it happy. Since Emacs now leaves |
15143
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
148 28 bits available for pointers, this lets us use the remainder of |
15208
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
149 the region below the 256MB line for our malloc arena - 229MB is |
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
150 still a pretty decent arena to play in! */ |
15143
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
151 |
15208
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
152 unsigned long base = 0x01B00000; /* 27MB */ |
15143
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
153 unsigned long end = 1 << VALBITS; /* 256MB */ |
15208
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
154 void *ptr = NULL; |
11943
ea533622fb8b
(reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11385
diff
changeset
|
155 |
15228
ae9888a75348
(allocate_heap): Clean up conditional.
Richard M. Stallman <rms@gnu.org>
parents:
15208
diff
changeset
|
156 #if NTHEAP_PROBE_BASE /* This is never normally defined */ |
ae9888a75348
(allocate_heap): Clean up conditional.
Richard M. Stallman <rms@gnu.org>
parents:
15208
diff
changeset
|
157 /* Try various addresses looking for one the kernel will let us have. */ |
15208
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
158 while (!ptr && (base < end)) |
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
159 { |
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
160 reserved_heap_size = end - base; |
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
161 ptr = VirtualAlloc ((void *) base, |
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
162 get_reserved_heap_size (), |
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
163 MEM_RESERVE, |
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
164 PAGE_NOACCESS); |
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
165 base += 0x00100000; /* 1MB increment */ |
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
166 } |
15228
ae9888a75348
(allocate_heap): Clean up conditional.
Richard M. Stallman <rms@gnu.org>
parents:
15208
diff
changeset
|
167 #else |
ae9888a75348
(allocate_heap): Clean up conditional.
Richard M. Stallman <rms@gnu.org>
parents:
15208
diff
changeset
|
168 reserved_heap_size = end - base; |
ae9888a75348
(allocate_heap): Clean up conditional.
Richard M. Stallman <rms@gnu.org>
parents:
15208
diff
changeset
|
169 ptr = VirtualAlloc ((void *) base, |
ae9888a75348
(allocate_heap): Clean up conditional.
Richard M. Stallman <rms@gnu.org>
parents:
15208
diff
changeset
|
170 get_reserved_heap_size (), |
ae9888a75348
(allocate_heap): Clean up conditional.
Richard M. Stallman <rms@gnu.org>
parents:
15208
diff
changeset
|
171 MEM_RESERVE, |
ae9888a75348
(allocate_heap): Clean up conditional.
Richard M. Stallman <rms@gnu.org>
parents:
15208
diff
changeset
|
172 PAGE_NOACCESS); |
15208
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
173 #endif |
15228
ae9888a75348
(allocate_heap): Clean up conditional.
Richard M. Stallman <rms@gnu.org>
parents:
15208
diff
changeset
|
174 |
15208
01588278fceb
(allocate_heap): Bump heap base up to 27MB to
Geoff Voelker <voelker@cs.washington.edu>
parents:
15143
diff
changeset
|
175 return ptr; |
11943
ea533622fb8b
(reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11385
diff
changeset
|
176 } |
ea533622fb8b
(reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11385
diff
changeset
|
177 |
ea533622fb8b
(reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11385
diff
changeset
|
178 |
9803 | 179 /* Emulate Unix sbrk. */ |
180 void * | |
181 sbrk (unsigned long increment) | |
182 { | |
183 void *result; | |
184 long size = (long) increment; | |
185 | |
186 /* Allocate our heap if we haven't done so already. */ | |
187 if (!data_region_base) | |
188 { | |
11943
ea533622fb8b
(reserved_heap_size,allocate_heap): Defined.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11385
diff
changeset
|
189 data_region_base = allocate_heap (); |
9803 | 190 if (!data_region_base) |
191 return NULL; | |
192 | |
15143
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
193 /* Ensure that the addresses don't use the upper tag bits since |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
194 the Lisp type goes there. */ |
d7d0413e95e2
Include lisp.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
14186
diff
changeset
|
195 if (((unsigned long) data_region_base & ~VALMASK) != 0) |
9803 | 196 { |
197 printf ("Error: The heap was allocated in upper memory.\n"); | |
198 exit (1); | |
199 } | |
200 | |
201 data_region_end = data_region_base; | |
12452
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
202 real_data_region_end = data_region_end; |
9803 | 203 data_region_size = get_reserved_heap_size (); |
204 } | |
205 | |
206 result = data_region_end; | |
207 | |
208 /* If size is negative, shrink the heap by decommitting pages. */ | |
209 if (size < 0) | |
210 { | |
12452
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
211 int new_size; |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
212 unsigned char *new_data_region_end; |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
213 |
9803 | 214 size = -size; |
215 | |
216 /* Sanity checks. */ | |
217 if ((data_region_end - size) < data_region_base) | |
218 return NULL; | |
219 | |
12452
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
220 /* We can only decommit full pages, so allow for |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
221 partial deallocation [cga]. */ |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
222 new_data_region_end = (data_region_end - size); |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
223 new_data_region_end = (unsigned char *) |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
224 ((long) (new_data_region_end + syspage_mask) & ~syspage_mask); |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
225 new_size = real_data_region_end - new_data_region_end; |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
226 real_data_region_end = new_data_region_end; |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
227 if (new_size > 0) |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
228 { |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
229 /* Decommit size bytes from the end of the heap. */ |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
230 if (!VirtualFree (real_data_region_end, new_size, MEM_DECOMMIT)) |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
231 return NULL; |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
232 } |
9803 | 233 |
234 data_region_end -= size; | |
235 } | |
236 /* If size is positive, grow the heap by committing reserved pages. */ | |
237 else if (size > 0) | |
238 { | |
239 /* Sanity checks. */ | |
240 if ((data_region_end + size) > | |
241 (data_region_base + get_reserved_heap_size ())) | |
242 return NULL; | |
243 | |
244 /* Commit more of our heap. */ | |
245 if (VirtualAlloc (data_region_end, size, MEM_COMMIT, | |
246 PAGE_READWRITE) == NULL) | |
247 return NULL; | |
248 data_region_end += size; | |
12452
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
249 |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
250 /* We really only commit full pages, so record where |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
251 the real end of committed memory is [cga]. */ |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
252 real_data_region_end = (unsigned char *) |
bd304be0b491
Include config.h.
Geoff Voelker <voelker@cs.washington.edu>
parents:
11943
diff
changeset
|
253 ((long) (data_region_end + syspage_mask) & ~syspage_mask); |
9803 | 254 } |
255 | |
256 return result; | |
257 } | |
258 | |
259 /* Recreate the heap from the data that was dumped to the executable. | |
260 EXECUTABLE_PATH tells us where to find the executable. */ | |
261 void | |
262 recreate_heap (char *executable_path) | |
263 { | |
264 unsigned char *tmp; | |
265 | |
266 /* First reserve the upper part of our heap. (We reserve first | |
267 because there have been problems in the past where doing the | |
268 mapping first has loaded DLLs into the VA space of our heap.) */ | |
269 tmp = VirtualAlloc ((void *) get_heap_end (), | |
270 get_reserved_heap_size () - get_committed_heap_size (), | |
271 MEM_RESERVE, | |
272 PAGE_NOACCESS); | |
273 if (!tmp) | |
274 exit (1); | |
275 | |
276 /* We read in the data for the .bss section from the executable | |
277 first and map in the heap from the executable second to prevent | |
278 any funny interactions between file I/O and file mapping. */ | |
279 read_in_bss (executable_path); | |
280 map_in_heap (executable_path); | |
281 } | |
282 | |
283 /* Round the heap up to the given alignment. */ | |
284 void | |
285 round_heap (unsigned long align) | |
286 { | |
287 unsigned long needs_to_be; | |
288 unsigned long need_to_alloc; | |
289 | |
290 needs_to_be = (unsigned long) round_to_next (get_heap_end (), align); | |
291 need_to_alloc = needs_to_be - (unsigned long) get_heap_end (); | |
292 | |
293 if (need_to_alloc) | |
294 sbrk (need_to_alloc); | |
295 } |