Mercurial > hg > xemacs-beta
comparison src/ntheap.c @ 412:697ef44129c6 r21-2-14
Import from CVS: tag r21-2-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:20:41 +0200 |
parents | 501cfd01ee6d |
children |
comparison
equal
deleted
inserted
replaced
411:12e008d41344 | 412:697ef44129c6 |
---|---|
36 | 36 |
37 /* These are defined to get Emacs to compile, but are not used. */ | 37 /* These are defined to get Emacs to compile, but are not used. */ |
38 int edata; | 38 int edata; |
39 int etext; | 39 int etext; |
40 | 40 |
41 /* The major and minor versions of NT. */ | |
42 int nt_major_version; | |
43 int nt_minor_version; | |
44 | |
45 /* Distinguish between Windows NT and Windows 95. */ | |
46 int os_subtype; | |
47 | |
41 /* Cache information describing the NT system for later use. */ | 48 /* Cache information describing the NT system for later use. */ |
42 void | 49 void |
43 cache_system_info (void) | 50 cache_system_info (void) |
44 { | 51 { |
52 union | |
53 { | |
54 struct info | |
55 { | |
56 char major; | |
57 char minor; | |
58 short platform; | |
59 } info; | |
60 DWORD data; | |
61 } version; | |
62 | |
63 /* Cache the version of the operating system. */ | |
64 version.data = GetVersion (); | |
65 nt_major_version = version.info.major; | |
66 nt_minor_version = version.info.minor; | |
67 | |
68 if (version.info.platform & 0x8000) | |
69 os_subtype = OS_WIN95; | |
70 else | |
71 os_subtype = OS_NT; | |
72 | |
45 /* Cache page size, allocation unit, processor type, etc. */ | 73 /* Cache page size, allocation unit, processor type, etc. */ |
46 GetSystemInfo (&sysinfo_cache); | 74 GetSystemInfo (&sysinfo_cache); |
47 syspage_mask = sysinfo_cache.dwPageSize - 1; | 75 syspage_mask = sysinfo_cache.dwPageSize - 1; |
48 } | 76 } |
49 | 77 |
78 get_data_end (void) | 106 get_data_end (void) |
79 { | 107 { |
80 return data_region_end; | 108 return data_region_end; |
81 } | 109 } |
82 | 110 |
83 static unsigned char * | 111 static char * |
84 allocate_heap (void) | 112 allocate_heap (void) |
85 { | 113 { |
86 /* The base address for our GNU malloc heap is chosen in conjunction | 114 /* 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, | 115 with the link settings for temacs.exe which control the stack size, |
88 the initial default process heap size and the executable image base | 116 the initial default process heap size and the executable image base |
118 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 |
119 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 |
120 still a pretty decent arena to play in! */ | 148 still a pretty decent arena to play in! */ |
121 | 149 |
122 unsigned long base = 0x01B00000; /* 27MB */ | 150 unsigned long base = 0x01B00000; /* 27MB */ |
123 /* Temporary hack for the non-starting problem - use 28 (256Mb) rather than VALBITS (1Gb) */ | 151 unsigned long end = 1 << VALBITS; /* 256MB */ |
124 unsigned long end = 1 << 28; /* 256MB */ | |
125 void *ptr = NULL; | 152 void *ptr = NULL; |
126 | 153 |
127 #define NTHEAP_PROBE_BASE 1 | 154 #define NTHEAP_PROBE_BASE 1 |
128 #if NTHEAP_PROBE_BASE /* This is never normally defined */ | 155 #if NTHEAP_PROBE_BASE /* This is never normally defined */ |
129 /* 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. */ |
142 get_reserved_heap_size (), | 169 get_reserved_heap_size (), |
143 MEM_RESERVE, | 170 MEM_RESERVE, |
144 PAGE_NOACCESS); | 171 PAGE_NOACCESS); |
145 #endif | 172 #endif |
146 | 173 |
147 return (unsigned char*) ptr; | 174 return ptr; |
148 } | 175 } |
149 | 176 |
150 | 177 |
151 /* Emulate Unix sbrk. */ | 178 /* Emulate Unix sbrk. */ |
152 void * | 179 void * |
218 } | 245 } |
219 | 246 |
220 return result; | 247 return result; |
221 } | 248 } |
222 | 249 |
223 #if !defined (CANNOT_DUMP) && !defined(HEAP_IN_DATA) && !defined(PDUMP) | 250 #if !defined (CANNOT_DUMP) && !defined(HEAP_IN_DATA) |
224 | 251 |
225 /* Recreate the heap from the data that was dumped to the executable. | 252 /* Recreate the heap from the data that was dumped to the executable. |
226 EXECUTABLE_PATH tells us where to find the executable. */ | 253 EXECUTABLE_PATH tells us where to find the executable. */ |
227 void | 254 void |
228 recreate_heap (char *executable_path) | 255 recreate_heap (char *executable_path) |
229 { | 256 { |
257 unsigned char *tmp; | |
258 | |
230 /* First reserve the upper part of our heap. (We reserve first | 259 /* First reserve the upper part of our heap. (We reserve first |
231 because there have been problems in the past where doing the | 260 because there have been problems in the past where doing the |
232 mapping first has loaded DLLs into the VA space of our heap.) */ | 261 mapping first has loaded DLLs into the VA space of our heap.) */ |
233 | 262 tmp = VirtualAlloc ((void *) get_heap_end (), |
234 /* Query the region at the end of the committed heap */ | 263 get_reserved_heap_size () - get_committed_heap_size (), |
235 void *tmp; | 264 MEM_RESERVE, |
236 MEMORY_BASIC_INFORMATION info; | 265 PAGE_NOACCESS); |
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); | |
258 if (!tmp) | 266 if (!tmp) |
259 { | 267 exit (1); |
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 } | |
268 | 268 |
269 /* 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 |
270 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 |
271 any funny interactions between file I/O and file mapping. */ | 271 any funny interactions between file I/O and file mapping. */ |
272 read_in_bss (executable_path); | 272 read_in_bss (executable_path); |