Mercurial > hg > xemacs-beta
annotate src/unexnt.c @ 5750:66d2f63df75f
Correct some spelling and formatting in behavior.el.
Mentioned in tracker issue 826, the third thing mentioned there (the file
name at the bottom of the file) had already been fixed.
lisp/ChangeLog addition:
2013-08-05 Aidan Kehoe <kehoea@parhasard.net>
* behavior.el:
(override-behavior):
Correct some spelling and formatting here, thank you Steven
Mitchell in tracker issue 826.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Mon, 05 Aug 2013 10:05:32 +0100 |
parents | 308d34e9f07d |
children |
rev | line source |
---|---|
613 | 1 /* unexec for XEmacs on Windows NT. |
428 | 2 Copyright (C) 1994 Free Software Foundation, Inc. |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
3 Copyright (C) 2002, 2010 Ben Wing. |
428 | 4 |
5 This file is part of XEmacs. | |
6 | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5050
diff
changeset
|
7 XEmacs is free software: you can redistribute it and/or modify it |
428 | 8 under the terms of the GNU General Public License as published by the |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5050
diff
changeset
|
9 Free Software Foundation, either version 3 of the License, or (at your |
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5050
diff
changeset
|
10 option) any later version. |
428 | 11 |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
5050
diff
changeset
|
18 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
428 | 19 Geoff Voelker (voelker@cs.washington.edu) 8-12-94 */ |
20 | |
21 /* Adapted for XEmacs by David Hobley <david@spook-le0.cia.com.au> */ | |
22 | |
814 | 23 /* This file has been Mule-ized, Ben Wing, 4-13-02. */ |
24 | |
428 | 25 /* The linkers that come with MSVC >= 4.0 merge .bss into .data and reorder |
26 * uninitialised data so that the .data section looks like: | |
27 * | |
28 * crt0 initialised data | |
29 * emacs initialised data | |
30 * <my_edata> | |
31 * library initialised data | |
32 * <start of bss part of .data> | |
33 * emacs static uninitialised data | |
34 * library static uninitialised data | |
35 * emacs global uninitialised data | |
36 * <my_ebss> | |
37 * library global uninitialised data | |
38 * | |
39 * This means that we can't use the normal my_ebss in lastfile.c trick to | |
40 * differentiate between unitialised data that belongs to emacs and | |
41 * uninitialised data that belongs to system libraries. This is bad because | |
42 * we do want to initialise the emacs data, but we don't want to initialise | |
43 * the system library data. | |
44 * | |
45 * To solve this problem using MSVC >= 5.0 we use a pragma directive to tell | |
46 * the compiler to put emacs's data (both initialised and uninitialised) in | |
47 * a separate section in the executable, and we only dump that section. This | |
48 * means that all files that define initialized data must include config.h | |
49 * to pick up the pragma. We don't try to make any part of that section | |
50 * read-only. | |
51 * | |
52 * This pragma directive isn't supported by the MSVC 4.x compiler. Instead, | |
53 * we dump crt0 initialised data and library static uninitialised data in | |
54 * addition to the emacs data. This is wrong, but we appear to be able to | |
55 * get away with it. A proper fix might involve the introduction of a static | |
56 * version of my_ebss in lastfile.c and a new firstfile.c file. jhar */ | |
57 | |
58 #include <config.h> | |
442 | 59 #include "lisp.h" |
60 | |
558 | 61 #include "sysfile.h" |
442 | 62 #include "syswindows.h" |
63 | |
428 | 64 /* From IMAGEHLP.H which is not installed by default by MSVC < 5 */ |
65 /* The IMAGEHLP.DLL library is not distributed by default with Windows95 */ | |
442 | 66 typedef PIMAGE_NT_HEADERS |
67 (__stdcall * pfnCheckSumMappedFile_t) (LPVOID BaseAddress, DWORD FileLength, | |
68 LPDWORD HeaderSum, LPDWORD CheckSum); | |
69 | |
428 | 70 |
71 #if 0 | |
72 extern BOOL ctrl_c_handler (unsigned long type); | |
73 #endif | |
74 | |
442 | 75 /* Sync with FSF Emacs 19.34.6 |
76 note: struct file_data is now defined in nt.h */ | |
428 | 77 |
78 enum { | |
79 HEAP_UNINITIALIZED = 1, | |
80 HEAP_UNLOADED, | |
81 HEAP_LOADED | |
82 }; | |
83 | |
84 /* Basically, our "initialized" flag. */ | |
85 int heap_state = HEAP_UNINITIALIZED; | |
86 | |
87 /* So we can find our heap in the file to recreate it. */ | |
88 unsigned long heap_index_in_executable = UNINIT_LONG; | |
89 | |
90 void get_section_info (file_data *p_file); | |
91 void copy_executable_and_dump_data_section (file_data *, file_data *); | |
92 void dump_bss_and_heap (file_data *p_infile, file_data *p_outfile); | |
93 | |
94 /* Cached info about the .data section in the executable. */ | |
95 PUCHAR data_start_va = UNINIT_PTR; | |
96 DWORD data_start_file = UNINIT_LONG; | |
97 DWORD data_size = UNINIT_LONG; | |
98 | |
99 /* Cached info about the .bss section in the executable. */ | |
100 PUCHAR bss_start = UNINIT_PTR; | |
101 DWORD bss_size = UNINIT_LONG; | |
102 | |
103 /* Startup code for running on NT. When we are running as the dumped | |
104 version, we need to bootstrap our heap and .bss section into our | |
105 address space before we can actually hand off control to the startup | |
106 code supplied by NT (primarily because that code relies upon malloc ()). */ | |
440 | 107 |
108 /* ********************** | |
1204 | 109 Hackers please remember, this _start() thingy is *not* called either |
110 when dumping portably, or when running from temacs! Do not put | |
440 | 111 significant XEmacs initialization here! |
112 ********************** */ | |
113 | |
1204 | 114 EXTERN_C void mainCRTStartup (void); |
115 | |
116 EXTERN_C int _start (void); | |
117 | |
118 int | |
428 | 119 _start (void) |
120 { | |
121 /* Cache system info, e.g., the NT page size. */ | |
122 cache_system_info (); | |
814 | 123 /* Set OS type, so that tchar stuff below works */ |
124 init_win32_very_early (); | |
428 | 125 |
126 /* If we're a dumped version of emacs then we need to recreate | |
127 our heap and play tricks with our .bss section. Do this before | |
128 start up. (WARNING: Do not put any code before this section | |
129 that relies upon malloc () and runs in the dumped version. It | |
130 won't work.) */ | |
131 if (heap_state == HEAP_UNLOADED) | |
132 { | |
4854 | 133 Extbyte executable_path[PATH_MAX_TCHAR]; |
428 | 134 |
814 | 135 /* Don't use mswindows_get_module_file_name() because it uses |
136 xmalloc() */ | |
2421 | 137 if (qxeGetModuleFileName (NULL, executable_path, _MAX_PATH) == 0) |
428 | 138 { |
139 exit (1); | |
140 } | |
141 | |
440 | 142 /* #### This is super-bogus. When I rename xemacs.exe, |
143 the renamed file still loads its heap from xemacs.exe --kkm */ | |
144 #if 0 | |
145 { | |
814 | 146 Extbyte *p; |
147 | |
440 | 148 /* To allow profiling, make sure executable_path names the .exe |
149 file, not the file created by the profiler */ | |
2421 | 150 p = qxetcsrchr (executable_path, '\\'); |
151 qxetcscpy (p + 1, XETEXT (PATH_PROGNAME ".exe")); | |
440 | 152 } |
153 #endif | |
428 | 154 |
155 recreate_heap (executable_path); | |
156 heap_state = HEAP_LOADED; | |
157 } | |
158 | |
440 | 159 /* #### This is bogus, too. _fmode is set to different values |
160 when we run `xemacs' and `temacs run-emacs'. The sooner we | |
161 hit and fix all the weirdities this causes us, the better --kkm */ | |
162 #if 0 | |
428 | 163 /* The default behavior is to treat files as binary and patch up |
442 | 164 text files appropriately. */ |
428 | 165 _fmode = O_BINARY; |
440 | 166 #endif |
428 | 167 |
168 #if 0 | |
169 /* This prevents ctrl-c's in shells running while we're suspended from | |
170 having us exit. */ | |
171 SetConsoleCtrlHandler ((PHANDLER_ROUTINE) ctrl_c_handler, TRUE); | |
172 #endif | |
173 | |
174 mainCRTStartup (); | |
1204 | 175 return 0; /* not reached? */ |
428 | 176 } |
177 | |
178 /* Dump out .data and .bss sections into a new executable. */ | |
442 | 179 int |
2286 | 180 unexec (Ibyte *new_name, Ibyte *old_name, unsigned int UNUSED (start_data), |
181 unsigned int UNUSED (start_bss), unsigned int UNUSED (entry_address)) | |
428 | 182 { |
183 file_data in_file, out_file; | |
867 | 184 Ibyte *out_filename = alloca_ibytes (qxestrlen (new_name) + 10); |
185 Ibyte *in_filename = alloca_ibytes (qxestrlen (old_name) + 10); | |
428 | 186 unsigned long size; |
867 | 187 Ibyte *ptr; |
442 | 188 HINSTANCE hImagehelp; |
428 | 189 |
190 /* Make sure that the input and output filenames have the | |
191 ".exe" extension...patch them up if they don't. */ | |
814 | 192 qxestrcpy (in_filename, old_name); |
193 ptr = in_filename + qxestrlen (in_filename) - 4; | |
2367 | 194 if (qxestrcmp_ascii (ptr, ".exe")) |
195 qxestrcat_ascii (in_filename, ".exe"); | |
428 | 196 |
814 | 197 qxestrcpy (out_filename, new_name); |
198 ptr = out_filename + qxestrlen (out_filename) - 4; | |
2367 | 199 if (qxestrcmp_ascii (ptr, ".exe")) |
200 qxestrcat_ascii (out_filename, ".exe"); | |
428 | 201 |
814 | 202 stdout_out ("Dumping from %s\n", in_filename); |
203 stdout_out (" to %s\n", out_filename); | |
428 | 204 |
205 /* We need to round off our heap to NT's allocation unit (64KB). */ | |
206 round_heap (get_allocation_unit ()); | |
207 | |
208 /* Open the undumped executable file. */ | |
209 if (!open_input_file (&in_file, in_filename)) | |
210 { | |
814 | 211 stdout_out ("Failed to open %s (%d)...bailing.\n", |
212 in_filename, GetLastError ()); | |
428 | 213 exit (1); |
214 } | |
215 | |
216 /* Get the interesting section info, like start and size of .bss... */ | |
217 get_section_info (&in_file); | |
218 | |
219 /* The size of the dumped executable is the size of the original | |
220 executable plus the size of the heap and the size of the .bss section. */ | |
221 heap_index_in_executable = (unsigned long) | |
2367 | 222 round_to_next ((Rawbyte *) in_file.size, get_allocation_unit ()); |
428 | 223 size = heap_index_in_executable + get_committed_heap_size () + bss_size; |
224 if (!open_output_file (&out_file, out_filename, size)) | |
225 { | |
814 | 226 stdout_out ("Failed to open %s (%d)...bailing.\n", |
227 out_filename, GetLastError ()); | |
428 | 228 exit (1); |
229 } | |
230 | |
231 /* Set the flag (before dumping). */ | |
232 heap_state = HEAP_UNLOADED; | |
233 | |
234 copy_executable_and_dump_data_section (&in_file, &out_file); | |
235 dump_bss_and_heap (&in_file, &out_file); | |
236 | |
237 /* Patch up header fields; profiler is picky about this. */ | |
812 | 238 hImagehelp = LoadLibraryA ("imagehlp.dll"); |
428 | 239 if (hImagehelp) |
240 { | |
241 PIMAGE_DOS_HEADER dos_header; | |
242 PIMAGE_NT_HEADERS nt_header; | |
442 | 243 |
428 | 244 DWORD headersum; |
245 DWORD checksum; | |
442 | 246 pfnCheckSumMappedFile_t pfnCheckSumMappedFile; |
428 | 247 |
248 dos_header = (PIMAGE_DOS_HEADER) out_file.file_base; | |
2367 | 249 nt_header = (PIMAGE_NT_HEADERS) ((Rawbyte *) dos_header + |
814 | 250 dos_header->e_lfanew); |
428 | 251 |
252 nt_header->OptionalHeader.CheckSum = 0; | |
442 | 253 #if 0 |
254 nt_header->FileHeader.TimeDateStamp = time (NULL); | |
255 dos_header->e_cp = size / 512; | |
256 nt_header->OptionalHeader.SizeOfImage = size; | |
257 #endif | |
428 | 258 |
442 | 259 pfnCheckSumMappedFile = |
260 (pfnCheckSumMappedFile_t) GetProcAddress (hImagehelp, | |
261 "CheckSumMappedFile"); | |
428 | 262 if (pfnCheckSumMappedFile) |
263 { | |
442 | 264 #if 0 |
265 nt_header->FileHeader.TimeDateStamp = time (NULL); | |
266 #endif | |
428 | 267 pfnCheckSumMappedFile (out_file.file_base, |
268 out_file.size, | |
269 &headersum, | |
270 &checksum); | |
271 nt_header->OptionalHeader.CheckSum = checksum; | |
272 } | |
273 FreeLibrary (hImagehelp); | |
274 } | |
275 | |
276 close_file_data (&in_file); | |
277 close_file_data (&out_file); | |
278 | |
442 | 279 return 0; |
428 | 280 } |
281 | |
282 /* Routines to manipulate NT executable file sections. */ | |
283 | |
284 #ifndef DUMP_SEPARATE_SECTION | |
285 static void | |
286 get_bss_info_from_map_file (file_data *p_infile, PUCHAR *p_bss_start, | |
287 DWORD *p_bss_size) | |
288 { | |
289 int n, start, len; | |
867 | 290 Ibyte *map_filename = alloca_ibytes (qxestrlen (p_infile->name) + 10); |
814 | 291 Extbyte buffer[256]; |
428 | 292 FILE *map; |
293 | |
294 /* Overwrite the .exe extension on the executable file name with | |
295 the .map extension. */ | |
814 | 296 qxestrcpy (map_filename, p_infile->name); |
297 n = qxestrlen (map_filename) - 3; | |
298 qxestrcpy (&map_filename[n], "map"); | |
428 | 299 |
814 | 300 map = qxe_fopen (map_filename, "r"); |
428 | 301 if (!map) |
302 { | |
814 | 303 stdout_out ("Failed to open map file %s, error %d...bailing out.\n", |
304 map_filename, GetLastError ()); | |
428 | 305 exit (-1); |
306 } | |
307 | |
308 while (fgets (buffer, sizeof (buffer), map)) | |
309 { | |
310 if (!(strstr (buffer, ".bss") && strstr (buffer, "DATA"))) | |
311 continue; | |
312 n = sscanf (buffer, " %*d:%x %x", &start, &len); | |
313 if (n != 2) | |
314 { | |
814 | 315 /* printf with external data, stdout_out with internal */ |
428 | 316 printf ("Failed to scan the .bss section line:\n%s", buffer); |
317 exit (-1); | |
318 } | |
319 break; | |
320 } | |
321 *p_bss_start = (PUCHAR) start; | |
322 *p_bss_size = (DWORD) len; | |
323 } | |
324 #endif | |
325 | |
326 /* Flip through the executable and cache the info necessary for dumping. */ | |
327 static void | |
328 get_section_info (file_data *p_infile) | |
329 { | |
330 PIMAGE_DOS_HEADER dos_header; | |
331 PIMAGE_NT_HEADERS nt_header; | |
332 PIMAGE_SECTION_HEADER section, data_section; | |
2367 | 333 Rawbyte *ptr; |
428 | 334 int i; |
335 | |
336 dos_header = (PIMAGE_DOS_HEADER) p_infile->file_base; | |
337 if (dos_header->e_magic != IMAGE_DOS_SIGNATURE) | |
338 { | |
814 | 339 stdout_out ("Unknown EXE header in %s...bailing.\n", p_infile->name); |
428 | 340 exit (1); |
341 } | |
342 nt_header = (PIMAGE_NT_HEADERS) (((unsigned long) dos_header) + | |
343 dos_header->e_lfanew); | |
344 if (nt_header == NULL) | |
345 { | |
814 | 346 stdout_out ("Failed to find IMAGE_NT_HEADER in %s...bailing.\n", |
347 p_infile->name); | |
428 | 348 exit (1); |
349 } | |
350 | |
351 /* Check the NT header signature ... */ | |
352 if (nt_header->Signature != IMAGE_NT_SIGNATURE) | |
353 { | |
814 | 354 stdout_out ("Invalid IMAGE_NT_SIGNATURE 0x%x in %s...bailing.\n", |
355 nt_header->Signature, p_infile->name); | |
428 | 356 } |
357 | |
358 /* Flip through the sections for .data and .bss ... */ | |
359 section = (PIMAGE_SECTION_HEADER) IMAGE_FIRST_SECTION (nt_header); | |
360 for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++) | |
361 { | |
362 #ifndef DUMP_SEPARATE_SECTION | |
2367 | 363 if (!qxestrcmp_ascii (section->Name, ".bss")) |
428 | 364 { |
365 extern int my_ebss; /* From lastfile.c */ | |
366 | |
2367 | 367 ptr = (Rawbyte *) nt_header->OptionalHeader.ImageBase + |
428 | 368 section->VirtualAddress; |
369 bss_start = ptr; | |
2367 | 370 bss_size = (Rawbyte*) &my_ebss - (Rawbyte*) bss_start; |
428 | 371 } |
372 | |
2367 | 373 if (!qxestrcmp_ascii (section->Name, ".data")) |
428 | 374 #else |
2367 | 375 if (!qxestrcmp_ascii (section->Name, "xdata")) |
428 | 376 #endif |
377 { | |
2367 | 378 extern Rawbyte my_edata[]; /* From lastfile.c */ |
428 | 379 |
380 /* The .data section. */ | |
381 data_section = section; | |
2367 | 382 ptr = (Rawbyte *) nt_header->OptionalHeader.ImageBase + |
428 | 383 section->VirtualAddress; |
384 data_start_va = ptr; | |
385 data_start_file = section->PointerToRawData; | |
386 | |
387 #ifndef DUMP_SEPARATE_SECTION | |
388 /* Write only the part of the section that contains emacs data. */ | |
389 data_size = my_edata - data_start_va; | |
390 #else | |
391 /* Write back the full section. */ | |
392 data_size = section->SizeOfRawData; | |
393 | |
394 /* This code doesn't know how to grow the raw size of a section. */ | |
395 if (section->SizeOfRawData < section->Misc.VirtualSize) | |
396 { | |
814 | 397 stdout_out ("The emacs data section is smaller than expected" |
398 "...bailing.\n"); | |
428 | 399 exit (1); |
400 } | |
401 #endif | |
402 } | |
403 section++; | |
404 } | |
405 | |
406 #ifndef DUMP_SEPARATE_SECTION | |
407 if (bss_start == UNINIT_PTR) | |
408 { | |
409 /* Starting with MSVC 4.0, the .bss section has been eliminated | |
410 and appended virtually to the end of the .data section. Our | |
411 only hint about where the .bss section starts in the address | |
412 comes from the SizeOfRawData field in the .data section | |
413 header. Unfortunately, this field is only approximate, as it | |
414 is a rounded number and is typically rounded just beyond the | |
415 start of the .bss section. To find the start and size of the | |
416 .bss section exactly, we have to peek into the map file. */ | |
417 extern int my_ebss; | |
418 | |
419 get_bss_info_from_map_file (p_infile, &ptr, &bss_size); | |
420 bss_start = ptr + nt_header->OptionalHeader.ImageBase | |
421 + data_section->VirtualAddress; | |
2367 | 422 bss_size = (Rawbyte *) &my_ebss - (Rawbyte *) bss_start; |
428 | 423 } |
424 #else | |
425 bss_size = 0; | |
426 #endif | |
427 } | |
428 | |
429 | |
430 /* The dump routines. */ | |
431 | |
432 #ifdef DEBUG_XEMACS | |
814 | 433 /* printf with external data, stdout_out with internal */ |
428 | 434 #define DUMP_MSG(x) printf x |
435 #else | |
436 #define DUMP_MSG(x) | |
437 #endif | |
438 | |
439 static void | |
440 copy_executable_and_dump_data_section (file_data *p_infile, | |
441 file_data *p_outfile) | |
442 { | |
2367 | 443 Rawbyte *data_file, *data_va; |
428 | 444 unsigned long size, index; |
445 | |
446 /* Get a pointer to where the raw data should go in the executable file. */ | |
2367 | 447 data_file = (Rawbyte *) p_outfile->file_base + data_start_file; |
428 | 448 |
449 /* Get a pointer to the raw data in our address space. */ | |
450 data_va = data_start_va; | |
451 | |
452 size = (DWORD) data_file - (DWORD) p_outfile->file_base; | |
453 DUMP_MSG (("Copying executable up to data section...\n")); | |
454 DUMP_MSG (("\t0x%08x Offset in input file.\n", 0)); | |
455 DUMP_MSG (("\t0x%08x Offset in output file.\n", 0)); | |
456 DUMP_MSG (("\t0x%08x Size in bytes.\n", size)); | |
457 memcpy (p_outfile->file_base, p_infile->file_base, size); | |
458 | |
459 size = data_size; | |
460 DUMP_MSG (("Dumping data section...\n")); | |
461 DUMP_MSG (("\t0x%08x Address in process.\n", data_va)); | |
462 DUMP_MSG (("\t0x%08x Offset in output file.\n", | |
2367 | 463 (Rawbyte *) data_file - |
464 (Rawbyte *) p_outfile->file_base)); | |
428 | 465 DUMP_MSG (("\t0x%08x Size in bytes.\n", size)); |
466 memcpy (data_file, data_va, size); | |
467 | |
468 index = (DWORD) data_file + size - (DWORD) p_outfile->file_base; | |
469 size = p_infile->size - index; | |
470 DUMP_MSG (("Copying rest of executable...\n")); | |
471 DUMP_MSG (("\t0x%08x Offset in input file.\n", index)); | |
472 DUMP_MSG (("\t0x%08x Offset in output file.\n", index)); | |
473 DUMP_MSG (("\t0x%08x Size in bytes.\n", size)); | |
2367 | 474 memcpy ((Rawbyte *) p_outfile->file_base + index, |
475 (Rawbyte *) p_infile->file_base + index, size); | |
428 | 476 } |
477 | |
478 static void | |
2286 | 479 dump_bss_and_heap (file_data *UNUSED (p_infile), file_data *p_outfile) |
428 | 480 { |
2367 | 481 Rawbyte *heap_data; |
814 | 482 unsigned long size, index; |
428 | 483 |
814 | 484 DUMP_MSG (("Dumping heap onto end of executable...\n")); |
428 | 485 |
814 | 486 index = heap_index_in_executable; |
487 size = get_committed_heap_size (); | |
488 heap_data = get_heap_start (); | |
428 | 489 |
814 | 490 DUMP_MSG (("\t0x%08x Heap start in process.\n", heap_data)); |
491 DUMP_MSG (("\t0x%08x Heap offset in executable.\n", index)); | |
492 DUMP_MSG (("\t0x%08x Heap size in bytes.\n", size)); | |
428 | 493 |
814 | 494 memcpy ((PUCHAR) p_outfile->file_base + index, heap_data, size); |
428 | 495 |
496 #ifndef DUMP_SEPARATE_SECTION | |
814 | 497 DUMP_MSG (("Dumping bss onto end of executable...\n")); |
428 | 498 |
814 | 499 index += size; |
500 size = bss_size; | |
428 | 501 |
814 | 502 DUMP_MSG (("\t0x%08x BSS start in process.\n", bss_start)); |
503 DUMP_MSG (("\t0x%08x BSS offset in executable.\n", index)); | |
504 DUMP_MSG (("\t0x%08x BSS size in bytes.\n", size)); | |
2367 | 505 memcpy ((Rawbyte *) p_outfile->file_base + index, bss_start, size); |
428 | 506 #endif |
507 } | |
508 | |
509 #undef DUMP_MSG | |
510 | |
511 /* Reload and remap routines. */ | |
512 | |
513 | |
514 /* Load the dumped .bss section into the .bss area of our address space. */ | |
515 /* Already done if the .bss was part of a separate emacs data section */ | |
516 void | |
814 | 517 read_in_bss (Extbyte *filename) |
428 | 518 { |
519 #ifndef DUMP_SEPARATE_SECTION | |
520 HANDLE file; | |
521 unsigned long index, n_read; | |
522 | |
814 | 523 file = qxeCreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL, |
524 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
525 assert (file != INVALID_HANDLE_VALUE); |
428 | 526 |
527 /* Seek to where the .bss section is tucked away after the heap... */ | |
528 index = heap_index_in_executable + get_committed_heap_size (); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
529 if (SetFilePointer (file, index, NULL, FILE_BEGIN) == 0xFFFFFFFF) |
2500 | 530 ABORT (); |
428 | 531 |
532 /* Ok, read in the saved .bss section and initialize all | |
533 uninitialized variables. */ | |
534 if (!ReadFile (file, bss_start, bss_size, &n_read, NULL)) | |
2500 | 535 ABORT (); |
428 | 536 |
537 CloseHandle (file); | |
538 #endif | |
539 } | |
540 | |
541 /* Map the heap dumped into the executable file into our address space. */ | |
542 void | |
814 | 543 map_in_heap (Extbyte *filename) |
428 | 544 { |
545 HANDLE file; | |
546 HANDLE file_mapping; | |
547 void *file_base; | |
548 unsigned long size, upper_size, n_read; | |
549 | |
814 | 550 file = qxeCreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL, |
551 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
552 assert (file != INVALID_HANDLE_VALUE); |
428 | 553 |
554 size = GetFileSize (file, &upper_size); | |
814 | 555 file_mapping = qxeCreateFileMapping (file, NULL, PAGE_WRITECOPY, |
556 0, size, NULL); | |
5050
6f2158fa75ed
Fix quick-build, use asserts() in place of ABORT()
Ben Wing <ben@xemacs.org>
parents:
4854
diff
changeset
|
557 assert (file_mapping); |
428 | 558 |
559 size = get_committed_heap_size (); | |
560 file_base = MapViewOfFileEx (file_mapping, FILE_MAP_COPY, 0, | |
561 heap_index_in_executable, size, | |
562 get_heap_start ()); | |
563 if (file_base != 0) | |
564 { | |
565 return; | |
566 } | |
567 | |
568 /* If we don't succeed with the mapping, then copy from the | |
569 data into the heap. */ | |
570 | |
571 CloseHandle (file_mapping); | |
572 | |
573 if (VirtualAlloc (get_heap_start (), get_committed_heap_size (), | |
574 MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) == NULL) | |
2500 | 575 ABORT (); |
428 | 576 |
577 /* Seek to the location of the heap data in the executable. */ | |
578 if (SetFilePointer (file, heap_index_in_executable, | |
579 NULL, FILE_BEGIN) == 0xFFFFFFFF) | |
2500 | 580 ABORT (); |
428 | 581 |
582 /* Read in the data. */ | |
583 if (!ReadFile (file, get_heap_start (), | |
584 get_committed_heap_size (), &n_read, NULL)) | |
2500 | 585 ABORT (); |
428 | 586 |
587 CloseHandle (file); | |
588 } |