annotate src/ntheap.c @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents 8626e4521993
children a86b2b5e0111
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
1 /* Heap management routines for XEmacs on Windows NT.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
2 Copyright (C) 1994 Free Software Foundation, Inc.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
3
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
4 This file is part of XEmacs.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
5
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
9 later version.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
10
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
14 for more details.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
15
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to the Free
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
19 02111-1307, USA.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
20
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
21 Geoff Voelker (voelker@cs.washington.edu) 7-29-94 */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
22
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
23 /* Adapted for XEmacs by David Hobley <david@spook-le0.cia.com.au> */
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
24 /* Synced with FSF Emacs 19.34.6 by Marc Paquette <marcpa@cam.org> */
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
25
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
26 #include <config.h>
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
27 #include "lisp.h" /* for VALMASK */
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
28
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
29 #include <stdlib.h>
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
30
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
31 #include "ntheap.h"
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
32
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
33 /* This gives us the page size and the size of the allocation unit on NT. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
34 SYSTEM_INFO sysinfo_cache;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
35 unsigned long syspage_mask = 0;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
36
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
37 /* These are defined to get Emacs to compile, but are not used. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
38 int edata;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
39 int etext;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
40
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
41 /* Cache information describing the NT system for later use. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
42 void
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
43 cache_system_info (void)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
44 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
45 /* Cache page size, allocation unit, processor type, etc. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
46 GetSystemInfo (&sysinfo_cache);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
47 syspage_mask = sysinfo_cache.dwPageSize - 1;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
48 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
49
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
50 /* Round ADDRESS up to be aligned with ALIGN. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
51 unsigned char *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
52 round_to_next (unsigned char *address, unsigned long align)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
53 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
54 unsigned long tmp;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
55
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
56 tmp = (unsigned long) address;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
57 tmp = (tmp + align - 1) / align;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
58
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
59 return (unsigned char *) (tmp * align);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
60 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
61
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
62 /* Info for keeping track of our heap. */
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 100
diff changeset
63 unsigned char *data_region_base = UNINIT_PTR;
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 100
diff changeset
64 unsigned char *data_region_end = UNINIT_PTR;
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 100
diff changeset
65 unsigned char *real_data_region_end = UNINIT_PTR;
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 100
diff changeset
66 unsigned long data_region_size = UNINIT_LONG;
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 100
diff changeset
67 unsigned long reserved_heap_size = UNINIT_LONG;
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
68
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
69 /* The start of the data segment. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
70 unsigned char *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
71 get_data_start (void)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
72 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
73 return data_region_base;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
74 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
75
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
76 /* The end of the data segment. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
77 unsigned char *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
78 get_data_end (void)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
79 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
80 return data_region_end;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
81 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
82
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
83 static char *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
84 allocate_heap (void)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
85 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
86 /* The base address for our GNU malloc heap is chosen in conjunction
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
87 with the link settings for temacs.exe which control the stack size,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
88 the initial default process heap size and the executable image base
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
89 address. The link settings and the malloc heap base below must all
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
90 correspond; the relationship between these values depends on how NT
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
91 and Win95 arrange the virtual address space for a process (and on
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
92 the size of the code and data segments in temacs.exe).
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
93
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
94 The most important thing is to make base address for the executable
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
95 image high enough to leave enough room between it and the 4MB floor
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
96 of the process address space on Win95 for the primary thread stack,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
97 the process default heap, and other assorted odds and ends
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
98 (eg. environment strings, private system dll memory etc) that are
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
99 allocated before temacs has a chance to grab its malloc arena. The
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
100 malloc heap base can then be set several MB higher than the
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
101 executable image base, leaving enough room for the code and data
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
102 segments.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
103
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
104 Because some parts of Emacs can use rather a lot of stack space
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
105 (for instance, the regular expression routines can potentially
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
106 allocate several MB of stack space) we allow 8MB for the stack.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
107
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
108 Allowing 1MB for the default process heap, and 1MB for odds and
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
109 ends, we can base the executable at 16MB and still have a generous
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
110 safety margin. At the moment, the executable has about 810KB of
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
111 code (for x86) and about 550KB of data - on RISC platforms the code
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
112 size could be roughly double, so if we allow 4MB for the executable
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
113 we will have plenty of room for expansion.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
114
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
115 Thus we would like to set the malloc heap base to 20MB. However,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
116 Win95 refuses to allocate the heap starting at this address, so we
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
117 set the base to 27MB to make it happy. Since Emacs now leaves
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
118 28 bits available for pointers, this lets us use the remainder of
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
119 the region below the 256MB line for our malloc arena - 229MB is
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
120 still a pretty decent arena to play in! */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
121
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
122 unsigned long base = 0x01B00000; /* 27MB */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
123 /* Temporary hack for the non-starting problem - use 28 (256Mb) rather than VALBITS (1Gb) */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
124 unsigned long end = 1 << 28; /* 256MB */
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
125 void *ptr = NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
126
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 100
diff changeset
127 #define NTHEAP_PROBE_BASE 1
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
128 #if NTHEAP_PROBE_BASE /* This is never normally defined */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
129 /* Try various addresses looking for one the kernel will let us have. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
130 while (!ptr && (base < end))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
131 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
132 reserved_heap_size = end - base;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
133 ptr = VirtualAlloc ((void *) base,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
134 get_reserved_heap_size (),
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
135 MEM_RESERVE,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
136 PAGE_NOACCESS);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
137 base += 0x00100000; /* 1MB increment */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
138 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
139 #else
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
140 reserved_heap_size = end - base;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
141 ptr = VirtualAlloc ((void *) base,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
142 get_reserved_heap_size (),
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
143 MEM_RESERVE,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
144 PAGE_NOACCESS);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
145 #endif
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
146
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
147 return ptr;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
148 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
149
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
150
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
151 /* Emulate Unix sbrk. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
152 void *
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
153 sbrk (unsigned long increment)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
154 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
155 void *result;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
156 long size = (long) increment;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
157
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
158 /* Allocate our heap if we haven't done so already. */
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 100
diff changeset
159 if (data_region_base == UNINIT_PTR)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
160 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
161 data_region_base = allocate_heap ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
162 if (!data_region_base)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
163 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
164
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
165 data_region_end = data_region_base;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
166 real_data_region_end = data_region_end;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
167 data_region_size = get_reserved_heap_size ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
168 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
169
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
170 result = data_region_end;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
171
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
172 /* If size is negative, shrink the heap by decommitting pages. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
173 if (size < 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
174 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
175 int new_size;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
176 unsigned char *new_data_region_end;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
177
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
178 size = -size;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
179
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
180 /* Sanity checks. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
181 if ((data_region_end - size) < data_region_base)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
182 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
183
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
184 /* We can only decommit full pages, so allow for
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
185 partial deallocation [cga]. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
186 new_data_region_end = (data_region_end - size);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
187 new_data_region_end = (unsigned char *)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
188 ((long) (new_data_region_end + syspage_mask) & ~syspage_mask);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
189 new_size = real_data_region_end - new_data_region_end;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
190 real_data_region_end = new_data_region_end;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
191 if (new_size > 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
192 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
193 /* Decommit size bytes from the end of the heap. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
194 if (!VirtualFree (real_data_region_end, new_size, MEM_DECOMMIT))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
195 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
196 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
197
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
198 data_region_end -= size;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
199 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
200 /* If size is positive, grow the heap by committing reserved pages. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
201 else if (size > 0)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
202 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
203 /* Sanity checks. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
204 if ((data_region_end + size) >
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
205 (data_region_base + get_reserved_heap_size ()))
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
206 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
207
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
208 /* Commit more of our heap. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
209 if (VirtualAlloc (data_region_end, size, MEM_COMMIT,
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
210 PAGE_READWRITE) == NULL)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
211 return NULL;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
212 data_region_end += size;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
213
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
214 /* We really only commit full pages, so record where
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
215 the real end of committed memory is [cga]. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
216 real_data_region_end = (unsigned char *)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
217 ((long) (data_region_end + syspage_mask) & ~syspage_mask);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
218 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
219
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
220 return result;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
221 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
222
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
223 #if !defined (CANNOT_DUMP) && !defined(HEAP_IN_DATA) && !defined(PDUMP)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
224
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
225 /* Recreate the heap from the data that was dumped to the executable.
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
226 EXECUTABLE_PATH tells us where to find the executable. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
227 void
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
228 recreate_heap (char *executable_path)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
229 {
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
230 unsigned char *tmp;
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
231
361
7347b34c275b Import from CVS: tag r21-1-10
cvs
parents: 359
diff changeset
232 /* First reserve the upper part of our heap. (We reserve first
365
30d2cfa1092a Import from CVS: tag r21-1-12
cvs
parents: 361
diff changeset
233 because there have been problems in the past where doing the
30d2cfa1092a Import from CVS: tag r21-1-12
cvs
parents: 361
diff changeset
234 mapping first has loaded DLLs into the VA space of our heap.) */
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
235 tmp = VirtualAlloc ((void *) get_heap_end (),
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
236 get_reserved_heap_size () - get_committed_heap_size (),
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
237 MEM_RESERVE,
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
238 PAGE_NOACCESS);
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
239 if (!tmp)
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
240 exit (1);
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
241
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
242 /* We read in the data for the .bss section from the executable
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
243 first and map in the heap from the executable second to prevent
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
244 any funny interactions between file I/O and file mapping. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
245 read_in_bss (executable_path);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
246 map_in_heap (executable_path);
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
247
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
248 /* Update system version information to match current system. */
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
249 cache_system_info ();
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
250 }
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
251 #endif /* CANNOT_DUMP */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
252
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
253 /* Round the heap up to the given alignment. */
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
254 void
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
255 round_heap (unsigned long align)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
256 {
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
257 unsigned long needs_to_be;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
258 unsigned long need_to_alloc;
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
259
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
260 needs_to_be = (unsigned long) round_to_next (get_heap_end (), align);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
261 need_to_alloc = needs_to_be - (unsigned long) get_heap_end ();
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
262
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
263 if (need_to_alloc)
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
264 sbrk (need_to_alloc);
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents:
diff changeset
265 }
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
266
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
267 #if (_MSC_VER >= 1000)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
268
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
269 /* MSVC 4.2 invokes these functions from mainCRTStartup to initialize
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
270 a heap via HeapCreate. They are normally defined by the runtime,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
271 but we override them here so that the unnecessary HeapCreate call
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
272 is not performed. */
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
273
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
274 int __cdecl
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
275 _heap_init (void)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
276 {
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
277 /* Stepping through the assembly indicates that mainCRTStartup is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
278 expecting a nonzero success return value. */
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
279 return 1;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
280 }
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
281
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
282 void __cdecl
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
283 _heap_term (void)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
284 {
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
285 return;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
286 }
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
287
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 169
diff changeset
288 #endif