Mercurial > hg > xemacs-beta
comparison src/ntheap.c @ 371:cc15677e0335 r21-2b1
Import from CVS: tag r21-2b1
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:03:08 +0200 |
parents | a4f53d9b3154 |
children | 8626e4521993 |
comparison
equal
deleted
inserted
replaced
370:bd866891f083 | 371:cc15677e0335 |
---|---|
146 28 bits available for pointers, this lets us use the remainder of | 146 28 bits available for pointers, this lets us use the remainder of |
147 the region below the 256MB line for our malloc arena - 229MB is | 147 the region below the 256MB line for our malloc arena - 229MB is |
148 still a pretty decent arena to play in! */ | 148 still a pretty decent arena to play in! */ |
149 | 149 |
150 unsigned long base = 0x01B00000; /* 27MB */ | 150 unsigned long base = 0x01B00000; /* 27MB */ |
151 /* Temporary hack for the non-starting problem - use 28 (256Mb) rather than VALBITS (1Gb) */ | 151 unsigned long end = 1 << VALBITS; /* 256MB */ |
152 unsigned long end = 1 << 28; /* 256MB */ | |
153 void *ptr = NULL; | 152 void *ptr = NULL; |
154 | 153 |
155 #define NTHEAP_PROBE_BASE 1 | 154 #define NTHEAP_PROBE_BASE 1 |
156 #if NTHEAP_PROBE_BASE /* This is never normally defined */ | 155 #if NTHEAP_PROBE_BASE /* This is never normally defined */ |
157 /* Try various addresses looking for one the kernel will let us have. */ | 156 /* Try various addresses looking for one the kernel will let us have. */ |
267 /* Recreate the heap from the data that was dumped to the executable. | 266 /* Recreate the heap from the data that was dumped to the executable. |
268 EXECUTABLE_PATH tells us where to find the executable. */ | 267 EXECUTABLE_PATH tells us where to find the executable. */ |
269 void | 268 void |
270 recreate_heap (char *executable_path) | 269 recreate_heap (char *executable_path) |
271 { | 270 { |
271 unsigned char *tmp; | |
272 | |
272 /* First reserve the upper part of our heap. (We reserve first | 273 /* First reserve the upper part of our heap. (We reserve first |
273 because there have been problems in the past where doing the | 274 because there have been problems in the past where doing the |
274 mapping first has loaded DLLs into the VA space of our heap.) */ | 275 mapping first has loaded DLLs into the VA space of our heap.) */ |
275 | 276 tmp = VirtualAlloc ((void *) get_heap_end (), |
276 /* Query the region at the end of the committed heap */ | 277 get_reserved_heap_size () - get_committed_heap_size (), |
277 void *tmp; | 278 MEM_RESERVE, |
278 MEMORY_BASIC_INFORMATION info; | 279 PAGE_NOACCESS); |
279 DWORD size; | |
280 unsigned char* base = get_heap_end (); | |
281 unsigned char* end = base + get_reserved_heap_size () - get_committed_heap_size (); | |
282 VirtualQuery (base, &info, sizeof info); | |
283 if (info.State != MEM_FREE) | |
284 { | |
285 /* Oops, something has already reserved or commited it, nothing we can do but exit */ | |
286 char buf[256]; | |
287 char modnambuf[80]; | |
288 | |
289 /* Find the filename of any DLL mapped at that address. This is a bit | |
290 of a hack in that it relies on HMODULEs being pointers to the image | |
291 base. However, this will almost certainly be the case for the | |
292 forseeable future in MS operating systems. | |
293 | |
294 Note that we don't check for MEM_IMAGE first because it doesn't | |
295 exist on Win95 AFAIK - ajh */ | |
296 if (!GetModuleFileName ((HMODULE) info.AllocationBase, | |
297 modnambuf, | |
298 sizeof (modnambuf))) | |
299 strcpy (modnambuf, "<unknown>"); | |
300 | |
301 wsprintf(buf, | |
302 "XEmacs cannot start because the memory region required by the heap is not available.\n" | |
303 "(BaseAddress = 0x%lx, AllocationBase = 0x%lx, Size = 0x%lx, State = %s, Type = %s, ModuleName = \"%s\")", | |
304 info.BaseAddress, info.AllocationBase, info.RegionSize, | |
305 info.State == MEM_COMMIT ? "COMMITED" : "RESERVED", | |
306 info.Type == MEM_IMAGE ? "IMAGE" : info.Type == MEM_MAPPED ? "MAPPED" : "PRIVATE", | |
307 modnambuf); | |
308 | |
309 MessageBox(NULL, buf, "XEmacs", MB_OK | MB_ICONSTOP); | |
310 exit(1); | |
311 } | |
312 | |
313 /* Now try and reserve as much as possible */ | |
314 size = min (info.RegionSize, end - base); | |
315 tmp = VirtualAlloc (base, size, MEM_RESERVE, PAGE_NOACCESS); | |
316 if (!tmp) | 280 if (!tmp) |
317 { | 281 exit (1); |
318 /* Can't reserve it, nothing we can do but exit */ | |
319 char buf[256]; | |
320 wsprintf(buf, | |
321 "XEmacs cannot start because it couldn't reserve space required for the heap.\n" | |
322 "(VirtualAlloc at 0x%lx of 0x%lx failed (%d))", base, size, GetLastError()); | |
323 MessageBox(NULL, buf, "XEmacs", MB_OK | MB_ICONSTOP); | |
324 exit (1); | |
325 } | |
326 | 282 |
327 /* We read in the data for the .bss section from the executable | 283 /* We read in the data for the .bss section from the executable |
328 first and map in the heap from the executable second to prevent | 284 first and map in the heap from the executable second to prevent |
329 any funny interactions between file I/O and file mapping. */ | 285 any funny interactions between file I/O and file mapping. */ |
330 read_in_bss (executable_path); | 286 read_in_bss (executable_path); |