Mercurial > hg > xemacs-beta
comparison src/ntheap.c @ 442:abe6d1db359e r21-2-36
Import from CVS: tag r21-2-36
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:35:02 +0200 |
parents | 8de8e3f6228a |
children | b39c14581166 |
comparison
equal
deleted
inserted
replaced
441:72a7cfa4a488 | 442:abe6d1db359e |
---|---|
78 get_data_end (void) | 78 get_data_end (void) |
79 { | 79 { |
80 return data_region_end; | 80 return data_region_end; |
81 } | 81 } |
82 | 82 |
83 static char * | 83 static unsigned char * |
84 allocate_heap (void) | 84 allocate_heap (void) |
85 { | 85 { |
86 /* The base address for our GNU malloc heap is chosen in conjunction | 86 /* The base address for our GNU malloc heap is chosen in conjunction |
87 with the link settings for temacs.exe which control the stack size, | 87 with the link settings for temacs.exe which control the stack size, |
88 the initial default process heap size and the executable image base | 88 the initial default process heap size and the executable image base |
142 get_reserved_heap_size (), | 142 get_reserved_heap_size (), |
143 MEM_RESERVE, | 143 MEM_RESERVE, |
144 PAGE_NOACCESS); | 144 PAGE_NOACCESS); |
145 #endif | 145 #endif |
146 | 146 |
147 return ptr; | 147 return (unsigned char*) ptr; |
148 } | 148 } |
149 | 149 |
150 | 150 |
151 /* Emulate Unix sbrk. */ | 151 /* Emulate Unix sbrk. */ |
152 void * | 152 void * |
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 unsigned char *tmp; | |
231 | |
232 /* First reserve the upper part of our heap. (We reserve first | 230 /* First reserve the upper part of our heap. (We reserve first |
233 because there have been problems in the past where doing the | 231 because there have been problems in the past where doing the |
234 mapping first has loaded DLLs into the VA space of our heap.) */ | 232 mapping first has loaded DLLs into the VA space of our heap.) */ |
235 tmp = VirtualAlloc ((void *) get_heap_end (), | 233 |
236 get_reserved_heap_size () - get_committed_heap_size (), | 234 /* Query the region at the end of the committed heap */ |
237 MEM_RESERVE, | 235 void *tmp; |
238 PAGE_NOACCESS); | 236 MEMORY_BASIC_INFORMATION info; |
237 DWORD size; | |
238 unsigned char* base = get_heap_end (); | |
239 unsigned char* end = base + get_reserved_heap_size () - get_committed_heap_size (); | |
240 VirtualQuery (base, &info, sizeof info); | |
241 if (info.State != MEM_FREE) | |
242 { | |
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); |