comparison src/ntheap.c @ 361:7347b34c275b r21-1-10

Import from CVS: tag r21-1-10
author cvs
date Mon, 13 Aug 2007 10:58:40 +0200
parents 8e84bee8ddd0
children 30d2cfa1092a
comparison
equal deleted inserted replaced
360:0f00b38cfccb 361:7347b34c275b
267 /* Recreate the heap from the data that was dumped to the executable. 267 /* Recreate the heap from the data that was dumped to the executable.
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 unsigned char *tmp;
273
274 /* First reserve the upper part of our heap. (We reserve first 272 /* First reserve the upper part of our heap. (We reserve first
275 because there have been problems in the past where doing the 273 because there have been problems in the past where doing the
276 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.) */
277 tmp = VirtualAlloc ((void *) get_heap_end (), 275
278 get_reserved_heap_size () - get_committed_heap_size (), 276 /* Query the region at the end of the committed heap */
279 MEM_RESERVE, 277 void *tmp;
280 PAGE_NOACCESS); 278 MEMORY_BASIC_INFORMATION info;
279 SIZE_T 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 wsprintf(buf,
288 "XEmacs cannot start because the memory region required by the heap is not available.\n"
289 "(BaseAddress = 0x%lx, AllocationBase = 0x%lx, Size = 0x%lx, State = %s, Type = %s)",
290 info.BaseAddress, info.AllocationBase, info.RegionSize,
291 info.State == MEM_COMMIT ? "COMMITED" : "RESERVED",
292 info.Type == MEM_IMAGE ? "IMAGE" : info.Type == MEM_MAPPED ? "MAPPED" : "PRIVATE");
293 MessageBox(NULL, buf, "XEmacs", MB_OK | MB_ICONSTOP);
294 exit(1);
295 }
296
297 /* Now try and reserve as much as possible */
298 size = min (info.RegionSize, end - base);
299 tmp = VirtualAlloc (base, size, MEM_RESERVE, PAGE_NOACCESS);
281 if (!tmp) 300 if (!tmp)
282 exit (1); 301 {
302 /* Can't reserve it, nothing we can do but exit */
303 char buf[256];
304 wsprintf(buf,
305 "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());
307 MessageBox(NULL, buf, "XEmacs", MB_OK | MB_ICONSTOP);
308 exit (1);
309 }
283 310
284 /* We read in the data for the .bss section from the executable 311 /* We read in the data for the .bss section from the executable
285 first and map in the heap from the executable second to prevent 312 first and map in the heap from the executable second to prevent
286 any funny interactions between file I/O and file mapping. */ 313 any funny interactions between file I/O and file mapping. */
287 read_in_bss (executable_path); 314 read_in_bss (executable_path);