Mercurial > hg > xemacs-beta
comparison src/ntheap.c @ 365:30d2cfa1092a r21-1-12
Import from CVS: tag r21-1-12
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:00:12 +0200 |
parents | 7347b34c275b |
children | a4f53d9b3154 |
comparison
equal
deleted
inserted
replaced
364:63c3368d1275 | 365:30d2cfa1092a |
---|---|
268 EXECUTABLE_PATH tells us where to find the executable. */ | 268 EXECUTABLE_PATH tells us where to find the executable. */ |
269 void | 269 void |
270 recreate_heap (char *executable_path) | 270 recreate_heap (char *executable_path) |
271 { | 271 { |
272 /* First reserve the upper part of our heap. (We reserve first | 272 /* First reserve the upper part of our heap. (We reserve first |
273 because there have been problems in the past where doing the | 273 because there have been problems in the past where doing the |
274 mapping first has loaded DLLs into the VA space of our heap.) */ | 274 mapping first has loaded DLLs into the VA space of our heap.) */ |
275 | 275 |
276 /* Query the region at the end of the committed heap */ | 276 /* Query the region at the end of the committed heap */ |
277 void *tmp; | 277 void *tmp; |
278 MEMORY_BASIC_INFORMATION info; | 278 MEMORY_BASIC_INFORMATION info; |
279 SIZE_T size; | 279 SIZE_T size; |
280 unsigned char* base = get_heap_end (); | 280 unsigned char* base = get_heap_end (); |
281 unsigned char* end = base + get_reserved_heap_size () - get_committed_heap_size (); | 281 unsigned char* end = base + get_reserved_heap_size () - get_committed_heap_size (); |
282 VirtualQuery (base, &info, sizeof info); | 282 VirtualQuery (base, &info, sizeof info); |
283 if (info.State != MEM_FREE) | 283 if (info.State != MEM_FREE) |
284 { | 284 { |
285 /* Oops, something has already reserved or commited it, nothing we can do but exit */ | 285 /* Oops, something has already reserved or commited it, nothing we can do but exit */ |
286 char buf[256]; | 286 char buf[256]; |
287 wsprintf(buf, | 287 char modnambuf[80]; |
288 "XEmacs cannot start because the memory region required by the heap is not available.\n" | 288 |
289 "(BaseAddress = 0x%lx, AllocationBase = 0x%lx, Size = 0x%lx, State = %s, Type = %s)", | 289 /* Find the filename of any DLL mapped at that address. This is a bit |
290 info.BaseAddress, info.AllocationBase, info.RegionSize, | 290 of a hack in that it relies on HMODULEs being pointers to the image |
291 info.State == MEM_COMMIT ? "COMMITED" : "RESERVED", | 291 base. However, this will almost certainly be the case for the |
292 info.Type == MEM_IMAGE ? "IMAGE" : info.Type == MEM_MAPPED ? "MAPPED" : "PRIVATE"); | 292 forseeable future in MS operating systems. |
293 MessageBox(NULL, buf, "XEmacs", MB_OK | MB_ICONSTOP); | 293 |
294 exit(1); | 294 Note that we don't check for MEM_IMAGE first because it doesn't |
295 } | 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 } | |
296 | 312 |
297 /* Now try and reserve as much as possible */ | 313 /* Now try and reserve as much as possible */ |
298 size = min (info.RegionSize, end - base); | 314 size = min (info.RegionSize, end - base); |
299 tmp = VirtualAlloc (base, size, MEM_RESERVE, PAGE_NOACCESS); | 315 tmp = VirtualAlloc (base, size, MEM_RESERVE, PAGE_NOACCESS); |
300 if (!tmp) | 316 if (!tmp) |
301 { | 317 { |
302 /* Can't reserve it, nothing we can do but exit */ | 318 /* Can't reserve it, nothing we can do but exit */ |
303 char buf[256]; | 319 char buf[256]; |
304 wsprintf(buf, | 320 wsprintf(buf, |
305 "XEmacs cannot start because it couldn't reserve space required for the heap.\n" | 321 "XEmacs cannot start because it couldn't reserve space required for the heap.\n" |
306 "(VirtualAlloc at 0x%lx of 0x%lx failed (%d))", base, size, GetLastError()); | 322 "(VirtualAlloc at 0x%lx of 0x%lx failed (%d))", base, size, GetLastError()); |
307 MessageBox(NULL, buf, "XEmacs", MB_OK | MB_ICONSTOP); | 323 MessageBox(NULL, buf, "XEmacs", MB_OK | MB_ICONSTOP); |
308 exit (1); | 324 exit (1); |
309 } | 325 } |
310 | 326 |
311 /* We read in the data for the .bss section from the executable | 327 /* We read in the data for the .bss section from the executable |
312 first and map in the heap from the executable second to prevent | 328 first and map in the heap from the executable second to prevent |
313 any funny interactions between file I/O and file mapping. */ | 329 any funny interactions between file I/O and file mapping. */ |
314 read_in_bss (executable_path); | 330 read_in_bss (executable_path); |