Mercurial > hg > xemacs-beta
comparison src/ntheap.c @ 408:501cfd01ee6d r21-2-34
Import from CVS: tag r21-2-34
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:18:11 +0200 |
parents | 5a2589c672dc |
children | 697ef44129c6 |
comparison
equal
deleted
inserted
replaced
407:ed6218a7d4d3 | 408:501cfd01ee6d |
---|---|
225 /* Recreate the heap from the data that was dumped to the executable. | 225 /* Recreate the heap from the data that was dumped to the executable. |
226 EXECUTABLE_PATH tells us where to find the executable. */ | 226 EXECUTABLE_PATH tells us where to find the executable. */ |
227 void | 227 void |
228 recreate_heap (char *executable_path) | 228 recreate_heap (char *executable_path) |
229 { | 229 { |
230 /* First reserve the upper part of our heap. (We reserve first | |
231 because there have been problems in the past where doing the | |
232 mapping first has loaded DLLs into the VA space of our heap.) */ | |
233 | |
234 /* Query the region at the end of the committed heap */ | |
230 void *tmp; | 235 void *tmp; |
231 | 236 MEMORY_BASIC_INFORMATION info; |
232 /* First reserve the upper part of our heap. (We reserve first | 237 DWORD size; |
233 because there have been problems in the past where doing the | 238 unsigned char* base = get_heap_end (); |
234 mapping first has loaded DLLs into the VA space of our heap.) */ | 239 unsigned char* end = base + get_reserved_heap_size () - get_committed_heap_size (); |
235 tmp = VirtualAlloc ((void *) get_heap_end (), | 240 VirtualQuery (base, &info, sizeof info); |
236 get_reserved_heap_size () - get_committed_heap_size (), | 241 if (info.State != MEM_FREE) |
237 MEM_RESERVE, | 242 { |
238 PAGE_NOACCESS); | 243 /* Oops, something has already reserved or commited it, nothing we can do but exit */ |
244 char buf[256]; | |
245 wsprintf(buf, | |
246 "XEmacs cannot start because the memory region required by the heap is not available.\n" | |
247 "(BaseAddress = 0x%lx, AllocationBase = 0x%lx, Size = 0x%lx, State = %s, Type = %s)", | |
248 info.BaseAddress, info.AllocationBase, info.RegionSize, | |
249 info.State == MEM_COMMIT ? "COMMITED" : "RESERVED", | |
250 info.Type == MEM_IMAGE ? "IMAGE" : info.Type == MEM_MAPPED ? "MAPPED" : "PRIVATE"); | |
251 MessageBox(NULL, buf, "XEmacs", MB_OK | MB_ICONSTOP); | |
252 exit(1); | |
253 } | |
254 | |
255 /* Now try and reserve as much as possible */ | |
256 size = min (info.RegionSize, end - base); | |
257 tmp = VirtualAlloc (base, size, MEM_RESERVE, PAGE_NOACCESS); | |
239 if (!tmp) | 258 if (!tmp) |
240 exit (1); | 259 { |
260 /* Can't reserve it, nothing we can do but exit */ | |
261 char buf[256]; | |
262 wsprintf(buf, | |
263 "XEmacs cannot start because it couldn't reserve space required for the heap.\n" | |
264 "(VirtualAlloc at 0x%lx of 0x%lx failed (%d))", base, size, GetLastError()); | |
265 MessageBox(NULL, buf, "XEmacs", MB_OK | MB_ICONSTOP); | |
266 exit (1); | |
267 } | |
241 | 268 |
242 /* We read in the data for the .bss section from the executable | 269 /* We read in the data for the .bss section from the executable |
243 first and map in the heap from the executable second to prevent | 270 first and map in the heap from the executable second to prevent |
244 any funny interactions between file I/O and file mapping. */ | 271 any funny interactions between file I/O and file mapping. */ |
245 read_in_bss (executable_path); | 272 read_in_bss (executable_path); |