annotate src/unexw32.c @ 24084:c0b0893dd5a6

(main): Eliminate arbitrary limit on length of system_name. (xmalloc): Define unconditionally.
author Richard M. Stallman <rms@gnu.org>
date Sat, 16 Jan 1999 21:45:10 +0000
parents 5d7a43e8b133
children 1086aa5db591
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
1 /* unexec for GNU Emacs on Windows NT.
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2 Copyright (C) 1994 Free Software Foundation, Inc.
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
4 This file is part of GNU Emacs.
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
7 it under the terms of the GNU General Public License as published by
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
8 the Free Software Foundation; either version 2, or (at your option)
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
9 any later version.
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
10
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
14 GNU General Public License for more details.
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
15
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
16 You should have received a copy of the GNU General Public License
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 14036
diff changeset
19 Boston, MA 02111-1307, USA.
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
20
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
21 Geoff Voelker (voelker@cs.washington.edu) 8-12-94
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
22 */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
23
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
24 #include <config.h>
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
25
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
26 #include <stdlib.h> /* _fmode */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
27 #include <stdio.h>
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
28 #include <fcntl.h>
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
29 #include <time.h>
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
30 #include <windows.h>
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
31
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
32 /* Include relevant definitions from IMAGEHLP.H, which can be found
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
33 in \\win32sdk\mstools\samples\image\include\imagehlp.h. */
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
34
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
35 PIMAGE_NT_HEADERS
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
36 (__stdcall * pfnCheckSumMappedFile) (LPVOID BaseAddress,
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
37 DWORD FileLength,
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
38 LPDWORD HeaderSum,
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
39 LPDWORD CheckSum);
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
40
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
41 extern BOOL ctrl_c_handler (unsigned long type);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
42
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
43 extern char my_begdata[];
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
44 extern char my_edata[];
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
45 extern char my_begbss[];
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
46 extern char my_endbss[];
21604
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
47 extern char *my_begbss_static;
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
48 extern char *my_endbss_static;
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
49
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
50 #include "w32heap.h"
18506
bcc706aedcea Add pragma to force zero initialized
Geoff Voelker <voelker@cs.washington.edu>
parents: 16593
diff changeset
51
21456
c0496e62b737 (min, max): Define as macros.
Karl Heuer <kwzh@gnu.org>
parents: 19703
diff changeset
52 #undef min
c0496e62b737 (min, max): Define as macros.
Karl Heuer <kwzh@gnu.org>
parents: 19703
diff changeset
53 #undef max
c0496e62b737 (min, max): Define as macros.
Karl Heuer <kwzh@gnu.org>
parents: 19703
diff changeset
54 #define min(x, y) (((x) < (y)) ? (x) : (y))
c0496e62b737 (min, max): Define as macros.
Karl Heuer <kwzh@gnu.org>
parents: 19703
diff changeset
55 #define max(x, y) (((x) > (y)) ? (x) : (y))
c0496e62b737 (min, max): Define as macros.
Karl Heuer <kwzh@gnu.org>
parents: 19703
diff changeset
56
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
57 /* Basically, our "initialized" flag. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
58 BOOL need_to_recreate_heap = FALSE;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
59
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
60 /* So we can find our heap in the file to recreate it. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
61 unsigned long heap_index_in_executable = 0;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
62
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
63 int open_input_file (file_data *p_file, char *name);
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
64 int open_output_file (file_data *p_file, char *name, unsigned long size);
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
65 void close_file_data (file_data *p_file);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
66
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
67 void get_section_info (file_data *p_file);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
68 void copy_executable_and_dump_data_section (file_data *, file_data *);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
69 void dump_bss_and_heap (file_data *p_infile, file_data *p_outfile);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
70
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
71 /* Cached info about the .data section in the executable. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
72 PUCHAR data_start_va = 0;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
73 DWORD data_start_file = 0;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
74 DWORD data_size = 0;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
75
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
76 /* Cached info about the .bss section in the executable. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
77 PUCHAR bss_start = 0;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
78 DWORD bss_size = 0;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
79
13423
eefa4f720371 [HAVE_NTGUI] (WinMain): New procedure.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12454
diff changeset
80 #ifdef HAVE_NTGUI
eefa4f720371 [HAVE_NTGUI] (WinMain): New procedure.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12454
diff changeset
81 HINSTANCE hinst = NULL;
eefa4f720371 [HAVE_NTGUI] (WinMain): New procedure.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12454
diff changeset
82 HINSTANCE hprevinst = NULL;
eefa4f720371 [HAVE_NTGUI] (WinMain): New procedure.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12454
diff changeset
83 LPSTR lpCmdLine = "";
eefa4f720371 [HAVE_NTGUI] (WinMain): New procedure.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12454
diff changeset
84 int nCmdShow = 0;
eefa4f720371 [HAVE_NTGUI] (WinMain): New procedure.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12454
diff changeset
85 #endif /* HAVE_NTGUI */
eefa4f720371 [HAVE_NTGUI] (WinMain): New procedure.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12454
diff changeset
86
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
87 /* Startup code for running on NT. When we are running as the dumped
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
88 version, we need to bootstrap our heap and .bss section into our
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
89 address space before we can actually hand off control to the startup
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
90 code supplied by NT (primarily because that code relies upon malloc ()). */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
91 void
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
92 _start (void)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
93 {
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
94 extern void mainCRTStartup (void);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
95
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
96 #if 0
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
97 /* Give us a way to debug problems with crashes on startup when
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
98 running under the MSVC profiler. */
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
99 if (GetEnvironmentVariable ("EMACS_DEBUG", NULL, 0) > 0)
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
100 DebugBreak ();
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
101 #endif
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
102
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
103 /* Cache system info, e.g., the NT page size. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
104 cache_system_info ();
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
105
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
106 /* If we're a dumped version of emacs then we need to recreate
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
107 our heap and play tricks with our .bss section. Do this before
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
108 start up. (WARNING: Do not put any code before this section
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
109 that relies upon malloc () and runs in the dumped version. It
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
110 won't work.) */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
111 if (need_to_recreate_heap)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
112 {
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
113 char executable_path[MAX_PATH];
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
114
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
115 if (GetModuleFileName (NULL, executable_path, MAX_PATH) == 0)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
116 {
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
117 printf ("Failed to find path for executable.\n");
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
118 exit (1);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
119 }
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
120
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
121 #if 1
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
122 /* To allow profiling, make sure executable_path names the .exe
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
123 file, not the ._xe file created by the profiler which contains
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
124 extra code that makes the stored exe offsets incorrect. (This
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
125 will not be necessary when unexec properly extends the .bss (or
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
126 .data as appropriate) section to include the dumped bss data,
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
127 and dumps the heap into a proper section of its own.) */
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
128 {
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
129 char * p = strrchr (executable_path, '.');
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
130 if (p && p[1] == '_')
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
131 p[1] = 'e';
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
132 }
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
133
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
134 /* Using HiProf profiler, exe name is different still. */
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
135 {
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
136 char * p = strrchr (executable_path, '\\');
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
137 strcpy (p, "\\emacs.exe");
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
138 }
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
139 #endif
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
140
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
141 recreate_heap (executable_path);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
142 need_to_recreate_heap = FALSE;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
143 }
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
144 else
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
145 {
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
146 /* Grab our malloc arena space now, before CRT starts up. */
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
147 sbrk (0);
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
148 }
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
149
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
150 /* The default behavior is to treat files as binary and patch up
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
151 text files appropriately, in accordance with the MSDOS code. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
152 _fmode = O_BINARY;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
153
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
154 /* This prevents ctrl-c's in shells running while we're suspended from
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
155 having us exit. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
156 SetConsoleCtrlHandler ((PHANDLER_ROUTINE) ctrl_c_handler, TRUE);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
157
23948
5d7a43e8b133 (_start): Force system calls accessing unmounted devices to fail
Andrew Innes <andrewi@gnu.org>
parents: 22300
diff changeset
158 /* Prevent Emacs from being locked up (eg. in batch mode) when
5d7a43e8b133 (_start): Force system calls accessing unmounted devices to fail
Andrew Innes <andrewi@gnu.org>
parents: 22300
diff changeset
159 accessing devices that aren't mounted (eg. removable media drives). */
5d7a43e8b133 (_start): Force system calls accessing unmounted devices to fail
Andrew Innes <andrewi@gnu.org>
parents: 22300
diff changeset
160 SetErrorMode (SEM_FAILCRITICALERRORS);
5d7a43e8b133 (_start): Force system calls accessing unmounted devices to fail
Andrew Innes <andrewi@gnu.org>
parents: 22300
diff changeset
161
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
162 /* Invoke the NT CRT startup routine now that our housecleaning
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
163 is finished. */
13423
eefa4f720371 [HAVE_NTGUI] (WinMain): New procedure.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12454
diff changeset
164 #ifdef HAVE_NTGUI
15146
be6560506cce (WinMain): Function removed.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14812
diff changeset
165 /* determine WinMain args like crt0.c does */
be6560506cce (WinMain): Function removed.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14812
diff changeset
166 hinst = GetModuleHandle(NULL);
be6560506cce (WinMain): Function removed.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14812
diff changeset
167 lpCmdLine = GetCommandLine();
be6560506cce (WinMain): Function removed.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14812
diff changeset
168 nCmdShow = SW_SHOWDEFAULT;
be6560506cce (WinMain): Function removed.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14812
diff changeset
169 #endif
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
170 mainCRTStartup ();
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
171 }
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
172
14036
621a575db6f7 Comment fixes.
Karl Heuer <kwzh@gnu.org>
parents: 13830
diff changeset
173 /* Dump out .data and .bss sections into a new executable. */
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
174 void
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
175 unexec (char *new_name, char *old_name, void *start_data, void *start_bss,
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
176 void *entry_address)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
177 {
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
178 file_data in_file, out_file;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
179 char out_filename[MAX_PATH], in_filename[MAX_PATH];
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
180 unsigned long size;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
181 char *ptr;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
182
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
183 /* Make sure that the input and output filenames have the
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
184 ".exe" extension...patch them up if they don't. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
185 strcpy (in_filename, old_name);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
186 ptr = in_filename + strlen (in_filename) - 4;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
187 if (strcmp (ptr, ".exe"))
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
188 strcat (in_filename, ".exe");
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
189
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
190 strcpy (out_filename, new_name);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
191 ptr = out_filename + strlen (out_filename) - 4;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
192 if (strcmp (ptr, ".exe"))
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
193 strcat (out_filename, ".exe");
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
194
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
195 printf ("Dumping from %s\n", in_filename);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
196 printf (" to %s\n", out_filename);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
197
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
198 /* We need to round off our heap to NT's allocation unit (64KB). */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
199 round_heap (get_allocation_unit ());
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
200
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
201 /* Open the undumped executable file. */
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
202 if (!open_input_file (&in_file, in_filename))
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
203 {
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
204 printf ("Failed to open %s (%d)...bailing.\n",
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
205 in_filename, GetLastError ());
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
206 exit (1);
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
207 }
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
208
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
209 /* Get the interesting section info, like start and size of .bss... */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
210 get_section_info (&in_file);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
211
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
212 /* The size of the dumped executable is the size of the original
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
213 executable plus the size of the heap and the size of the .bss section. */
12454
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
214 heap_index_in_executable = (unsigned long)
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
215 round_to_next ((unsigned char *) in_file.size, get_allocation_unit ());
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
216 size = heap_index_in_executable + get_committed_heap_size () + bss_size;
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
217 if (!open_output_file (&out_file, out_filename, size))
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
218 {
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
219 printf ("Failed to open %s (%d)...bailing.\n",
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
220 out_filename, GetLastError ());
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
221 exit (1);
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
222 }
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
223
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
224 /* Set the flag (before dumping). */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
225 need_to_recreate_heap = TRUE;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
226
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
227 copy_executable_and_dump_data_section (&in_file, &out_file);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
228 dump_bss_and_heap (&in_file, &out_file);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
229
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
230 /* Patch up header fields; profiler is picky about this. */
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
231 {
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
232 PIMAGE_DOS_HEADER dos_header;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
233 PIMAGE_NT_HEADERS nt_header;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
234 HANDLE hImagehelp = LoadLibrary ("imagehlp.dll");
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
235 DWORD headersum;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
236 DWORD checksum;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
237
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
238 dos_header = (PIMAGE_DOS_HEADER) out_file.file_base;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
239 nt_header = (PIMAGE_NT_HEADERS) ((char *) dos_header + dos_header->e_lfanew);
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
240
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
241 nt_header->OptionalHeader.CheckSum = 0;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
242 // nt_header->FileHeader.TimeDateStamp = time (NULL);
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
243 // dos_header->e_cp = size / 512;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
244 // nt_header->OptionalHeader.SizeOfImage = size;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
245
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
246 pfnCheckSumMappedFile = (void *) GetProcAddress (hImagehelp, "CheckSumMappedFile");
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
247 if (pfnCheckSumMappedFile)
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
248 {
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
249 // nt_header->FileHeader.TimeDateStamp = time (NULL);
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
250 pfnCheckSumMappedFile (out_file.file_base,
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
251 out_file.size,
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
252 &headersum,
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
253 &checksum);
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
254 nt_header->OptionalHeader.CheckSum = checksum;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
255 }
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
256 FreeLibrary (hImagehelp);
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
257 }
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
258
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
259 close_file_data (&in_file);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
260 close_file_data (&out_file);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
261 }
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
262
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
263
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
264 /* File handling. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
265
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
266
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
267 int
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
268 open_input_file (file_data *p_file, char *filename)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
269 {
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
270 HANDLE file;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
271 HANDLE file_mapping;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
272 void *file_base;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
273 unsigned long size, upper_size;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
274
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
275 file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL,
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
276 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
277 if (file == INVALID_HANDLE_VALUE)
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
278 return FALSE;
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
279
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
280 size = GetFileSize (file, &upper_size);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
281 file_mapping = CreateFileMapping (file, NULL, PAGE_READONLY,
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
282 0, size, NULL);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
283 if (!file_mapping)
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
284 return FALSE;
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
285
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
286 file_base = MapViewOfFile (file_mapping, FILE_MAP_READ, 0, 0, size);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
287 if (file_base == 0)
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
288 return FALSE;
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
289
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
290 p_file->name = filename;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
291 p_file->size = size;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
292 p_file->file = file;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
293 p_file->file_mapping = file_mapping;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
294 p_file->file_base = file_base;
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
295
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
296 return TRUE;
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
297 }
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
298
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
299 int
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
300 open_output_file (file_data *p_file, char *filename, unsigned long size)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
301 {
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
302 HANDLE file;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
303 HANDLE file_mapping;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
304 void *file_base;
13423
eefa4f720371 [HAVE_NTGUI] (WinMain): New procedure.
Geoff Voelker <voelker@cs.washington.edu>
parents: 12454
diff changeset
305
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
306 file = CreateFile (filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
307 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
308 if (file == INVALID_HANDLE_VALUE)
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
309 return FALSE;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
310
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
311 file_mapping = CreateFileMapping (file, NULL, PAGE_READWRITE,
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
312 0, size, NULL);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
313 if (!file_mapping)
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
314 return FALSE;
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
315
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
316 file_base = MapViewOfFile (file_mapping, FILE_MAP_WRITE, 0, 0, size);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
317 if (file_base == 0)
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
318 return FALSE;
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
319
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
320 p_file->name = filename;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
321 p_file->size = size;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
322 p_file->file = file;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
323 p_file->file_mapping = file_mapping;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
324 p_file->file_base = file_base;
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
325
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
326 return TRUE;
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
327 }
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
328
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
329 /* Close the system structures associated with the given file. */
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
330 void
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
331 close_file_data (file_data *p_file)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
332 {
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
333 UnmapViewOfFile (p_file->file_base);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
334 CloseHandle (p_file->file_mapping);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
335 CloseHandle (p_file->file);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
336 }
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
337
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
338
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
339 /* Routines to manipulate NT executable file sections. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
340
21604
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
341 #ifdef SEPARATE_BSS_SECTION
13830
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
342 static void
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
343 get_bss_info_from_map_file (file_data *p_infile, PUCHAR *p_bss_start,
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
344 DWORD *p_bss_size)
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
345 {
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
346 int n, start, len;
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
347 char map_filename[MAX_PATH];
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
348 char buffer[256];
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
349 FILE *map;
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
350
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
351 /* Overwrite the .exe extension on the executable file name with
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
352 the .map extension. */
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
353 strcpy (map_filename, p_infile->name);
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
354 n = strlen (map_filename) - 3;
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
355 strcpy (&map_filename[n], "map");
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
356
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
357 map = fopen (map_filename, "r");
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
358 if (!map)
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
359 {
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
360 printf ("Failed to open map file %s, error %d...bailing out.\n",
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
361 map_filename, GetLastError ());
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
362 exit (-1);
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
363 }
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
364
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
365 while (fgets (buffer, sizeof (buffer), map))
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
366 {
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
367 if (!(strstr (buffer, ".bss") && strstr (buffer, "DATA")))
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
368 continue;
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
369 n = sscanf (buffer, " %*d:%x %x", &start, &len);
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
370 if (n != 2)
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
371 {
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
372 printf ("Failed to scan the .bss section line:\n%s", buffer);
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
373 exit (-1);
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
374 }
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
375 break;
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
376 }
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
377 *p_bss_start = (PUCHAR) start;
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
378 *p_bss_size = (DWORD) len;
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
379 }
21604
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
380 #endif
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
381
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
382 unsigned long
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
383 get_section_size (PIMAGE_SECTION_HEADER p_section)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
384 {
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
385 /* The true section size, before rounding. Some linkers swap the
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
386 meaning of these two values. */
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
387 return min (p_section->SizeOfRawData,
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
388 p_section->Misc.VirtualSize);
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
389 }
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
390
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
391 /* Return pointer to section header for named section. */
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
392 IMAGE_SECTION_HEADER *
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
393 find_section (char * name, IMAGE_NT_HEADERS * nt_header)
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
394 {
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
395 PIMAGE_SECTION_HEADER section;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
396 int i;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
397
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
398 section = IMAGE_FIRST_SECTION (nt_header);
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
399
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
400 for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++)
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
401 {
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
402 if (strcmp (section->Name, name) == 0)
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
403 return section;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
404 section++;
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
405 }
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
406 return NULL;
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
407 }
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
408
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
409 /* Return pointer to section header for section containing the given
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
410 relative virtual address. */
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
411 IMAGE_SECTION_HEADER *
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
412 rva_to_section (DWORD rva, IMAGE_NT_HEADERS * nt_header)
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
413 {
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
414 PIMAGE_SECTION_HEADER section;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
415 int i;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
416
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
417 section = IMAGE_FIRST_SECTION (nt_header);
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
418
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
419 for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++)
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
420 {
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
421 if (rva >= section->VirtualAddress
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
422 && rva < section->VirtualAddress + section->SizeOfRawData)
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
423 return section;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
424 section++;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
425 }
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
426 return NULL;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
427 }
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
428
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
429
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
430 /* Flip through the executable and cache the info necessary for dumping. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
431 static void
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
432 get_section_info (file_data *p_infile)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
433 {
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
434 PIMAGE_DOS_HEADER dos_header;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
435 PIMAGE_NT_HEADERS nt_header;
13830
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
436 PIMAGE_SECTION_HEADER section, data_section;
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
437 unsigned char *ptr;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
438 int i;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
439
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
440 dos_header = (PIMAGE_DOS_HEADER) p_infile->file_base;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
441 if (dos_header->e_magic != IMAGE_DOS_SIGNATURE)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
442 {
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
443 printf ("Unknown EXE header in %s...bailing.\n", p_infile->name);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
444 exit (1);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
445 }
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
446 nt_header = (PIMAGE_NT_HEADERS) (((unsigned long) dos_header) +
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
447 dos_header->e_lfanew);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
448 if (nt_header == NULL)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
449 {
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
450 printf ("Failed to find IMAGE_NT_HEADER in %s...bailing.\n",
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
451 p_infile->name);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
452 exit (1);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
453 }
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
454
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
455 /* Check the NT header signature ... */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
456 if (nt_header->Signature != IMAGE_NT_SIGNATURE)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
457 {
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
458 printf ("Invalid IMAGE_NT_SIGNATURE 0x%x in %s...bailing.\n",
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
459 nt_header->Signature, p_infile->name);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
460 }
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
461
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
462 /* Flip through the sections for .data and .bss ... */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
463 section = (PIMAGE_SECTION_HEADER) IMAGE_FIRST_SECTION (nt_header);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
464 for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
465 {
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
466 #ifdef SEPARATE_BSS_SECTION
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
467 if (!strcmp (section->Name, ".bss"))
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
468 {
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
469 /* The .bss section. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
470 ptr = (char *) nt_header->OptionalHeader.ImageBase +
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
471 section->VirtualAddress;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
472 bss_start = ptr;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
473 bss_size = get_section_size (section);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
474 }
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
475 #endif
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
476 #if 0
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
477 if (!strcmp (section->Name, ".data"))
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
478 {
12454
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
479 /* From lastfile.c */
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
480 extern char my_edata[];
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
481
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
482 /* The .data section. */
13830
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
483 data_section = section;
15146
be6560506cce (WinMain): Function removed.
Geoff Voelker <voelker@cs.washington.edu>
parents: 14812
diff changeset
484 ptr = (char *) nt_header->OptionalHeader.ImageBase +
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
485 section->VirtualAddress;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
486 data_start_va = ptr;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
487 data_start_file = section->PointerToRawData;
12454
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
488
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
489 /* We want to only write Emacs data back to the executable,
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
490 not any of the library data (if library data is included,
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
491 then a dumped Emacs won't run on system versions other
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
492 than the one Emacs was dumped on). */
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
493 data_size = my_edata - data_start_va;
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
494 }
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
495 #else
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
496 if (!strcmp (section->Name, "EMDATA"))
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
497 {
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
498 /* The Emacs initialized data section. */
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
499 data_section = section;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
500 ptr = (char *) nt_header->OptionalHeader.ImageBase +
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
501 section->VirtualAddress;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
502 data_start_va = ptr;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
503 data_start_file = section->PointerToRawData;
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
504
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
505 /* Write back the full section. */
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
506 data_size = get_section_size (section);
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
507 }
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
508 #endif
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
509 section++;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
510 }
13830
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
511
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
512 #ifdef SEPARATE_BSS_SECTION
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
513 if (bss_start == UNINIT_PTR && bss_size == UNINIT_LONG)
13830
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
514 {
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
515 /* Starting with MSVC 4.0, the .bss section has been eliminated
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
516 and appended virtually to the end of the .data section. Our
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
517 only hint about where the .bss section starts in the address
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
518 comes from the SizeOfRawData field in the .data section
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
519 header. Unfortunately, this field is only approximate, as it
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
520 is a rounded number and is typically rounded just beyond the
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
521 start of the .bss section. To find the start and size of the
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
522 .bss section exactly, we have to peek into the map file. */
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
523 get_bss_info_from_map_file (p_infile, &ptr, &bss_size);
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
524 bss_start = ptr + nt_header->OptionalHeader.ImageBase
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
525 + data_section->VirtualAddress;
8d30151f4acb (get_bss_info_from_map_file): New function.
Geoff Voelker <voelker@cs.washington.edu>
parents: 13423
diff changeset
526 }
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
527 #else
21604
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
528 /* As noted in lastfile.c, the Alpha (but not the Intel) MSVC linker
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
529 globally segregates all static and public bss data (ie. across all
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
530 linked modules, not just per module), so we must take both static and
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
531 public bss areas into account to determine the true extent of the bss
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
532 area used by Emacs.
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
533
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
534 To be strictly correct, we should dump the static and public bss
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
535 areas used by Emacs separately if non-overlapping (since otherwise we
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
536 are dumping bss data belonging to system libraries, eg. the static
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
537 bss system data on the Alpha). However, in practice this doesn't
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
538 seem to matter, since presumably the system libraries always
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
539 reinitialize their bss variables. */
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
540 bss_start = min (my_begbss, my_begbss_static);
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
541 bss_size = max (my_endbss, my_endbss_static) - bss_start;
19703
9fa57c73882d Include config.h and time.h.
Geoff Voelker <voelker@cs.washington.edu>
parents: 18506
diff changeset
542 #endif
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
543 }
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
544
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
545
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
546 /* The dump routines. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
547
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
548 static void
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
549 copy_executable_and_dump_data_section (file_data *p_infile,
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
550 file_data *p_outfile)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
551 {
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
552 unsigned char *data_file, *data_va;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
553 unsigned long size, index;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
554
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
555 /* Get a pointer to where the raw data should go in the executable file. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
556 data_file = (char *) p_outfile->file_base + data_start_file;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
557
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
558 /* Get a pointer to the raw data in our address space. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
559 data_va = data_start_va;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
560
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
561 size = (DWORD) data_file - (DWORD) p_outfile->file_base;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
562 printf ("Copying executable up to data section...\n");
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
563 printf ("\t0x%08x Offset in input file.\n", 0);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
564 printf ("\t0x%08x Offset in output file.\n", 0);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
565 printf ("\t0x%08x Size in bytes.\n", size);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
566 memcpy (p_outfile->file_base, p_infile->file_base, size);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
567
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
568 size = data_size;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
569 printf ("Dumping .data section...\n");
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
570 printf ("\t0x%08x Address in process.\n", data_va);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
571 printf ("\t0x%08x Offset in output file.\n",
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
572 data_file - p_outfile->file_base);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
573 printf ("\t0x%08x Size in bytes.\n", size);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
574 memcpy (data_file, data_va, size);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
575
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
576 index = (DWORD) data_file + size - (DWORD) p_outfile->file_base;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
577 size = p_infile->size - index;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
578 printf ("Copying rest of executable...\n");
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
579 printf ("\t0x%08x Offset in input file.\n", index);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
580 printf ("\t0x%08x Offset in output file.\n", index);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
581 printf ("\t0x%08x Size in bytes.\n", size);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
582 memcpy ((char *) p_outfile->file_base + index,
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
583 (char *) p_infile->file_base + index, size);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
584 }
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
585
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
586 static void
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
587 dump_bss_and_heap (file_data *p_infile, file_data *p_outfile)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
588 {
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
589 unsigned char *heap_data, *bss_data;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
590 unsigned long size, index;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
591
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
592 printf ("Dumping heap into executable...\n");
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
593
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
594 index = heap_index_in_executable;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
595 size = get_committed_heap_size ();
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
596 heap_data = get_heap_start ();
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
597
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
598 printf ("\t0x%08x Heap start in process.\n", heap_data);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
599 printf ("\t0x%08x Heap offset in executable.\n", index);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
600 printf ("\t0x%08x Heap size in bytes.\n", size);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
601
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
602 memcpy ((PUCHAR) p_outfile->file_base + index, heap_data, size);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
603
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
604 printf ("Dumping .bss into executable...\n");
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
605
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
606 index += size;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
607 size = bss_size;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
608 bss_data = bss_start;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
609
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
610 printf ("\t0x%08x BSS start in process.\n", bss_data);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
611 printf ("\t0x%08x BSS offset in executable.\n", index);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
612 printf ("\t0x%08x BSS size in bytes.\n", size);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
613 memcpy ((char *) p_outfile->file_base + index, bss_data, size);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
614 }
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
615
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
616
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
617 /* Reload and remap routines. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
618
21604
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
619 void
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
620 w32_fatal_reload_error (char *step)
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
621 {
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
622 int error = GetLastError ();
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
623 char *buffer = alloca (4096);
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
624
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
625 sprintf (buffer,
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
626 "Emacs failed to load its dumped heap back into its address space.\n"
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
627 "The error occurred during the following step:\n\n"
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
628 "%s\n\n"
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
629 "GetLastError = %d\n\n"
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
630 "Heap start: 0x%08x\n"
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
631 "Heap commit: 0x%08x\n"
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
632 "Heap end: 0x%08x\n\n"
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
633 "This error typically happens when the system loads a DLL into\n"
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
634 "the middle of Emacs' address space, preventing Emacs from\n"
22300
ce79e5edf080 (w32_fatal_reload_error): Update error message.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21604
diff changeset
635 "loading its heap there. If this happens only occasionally, then\n"
ce79e5edf080 (w32_fatal_reload_error): Update error message.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21604
diff changeset
636 "you can probably ignore it. But if it happens so often that\n"
ce79e5edf080 (w32_fatal_reload_error): Update error message.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21604
diff changeset
637 "you cannot get Emacs to start reliably, and you think that Emacs\n"
ce79e5edf080 (w32_fatal_reload_error): Update error message.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21604
diff changeset
638 "is installed correctly, then you have a couple of options:\n\n"
21604
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
639 "Emacs correctly, then you have two options:\n\n"
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
640 "1) You can dump Emacs yourself. By doing this, you ensure that\n"
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
641 "Emacs' heap fits around the DLLs in your system. To dump Emacs,\n"
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
642 "download the emacs-(version)-undump-(arch) distribution file\n"
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
643 "from the site where you downloaded the executable distribution.\n\n"
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
644 "2) You can build Emacs from source. This is just another way\n"
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
645 "to dump Emacs on your system.",
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
646 step,
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
647 error,
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
648 get_heap_start (),
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
649 get_heap_start () + get_committed_heap_size (),
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
650 get_heap_end ());
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
651
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
652 MessageBox (NULL,
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
653 buffer,
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
654 "Emacs Abort Dialog",
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
655 MB_OK | MB_ICONEXCLAMATION | MB_TASKMODAL);
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
656
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
657 exit (-1);
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
658 }
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
659
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
660 /* Load the dumped .bss section into the .bss area of our address space. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
661 void
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
662 read_in_bss (char *filename)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
663 {
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
664 HANDLE file;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
665 unsigned long size, index, n_read, total_read;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
666 char buffer[512], *bss;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
667 int i;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
668
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
669 file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL,
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
670 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
671 if (file == INVALID_HANDLE_VALUE)
21604
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
672 w32_fatal_reload_error ("Opening Emacs executable file for .bss.");
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
673
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
674 /* Seek to where the .bss section is tucked away after the heap... */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
675 index = heap_index_in_executable + get_committed_heap_size ();
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
676 if (SetFilePointer (file, index, NULL, FILE_BEGIN) == 0xFFFFFFFF)
21604
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
677 w32_fatal_reload_error ("Seeking to the saved .bss section.");
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
678
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
679 /* Ok, read in the saved .bss section and initialize all
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
680 uninitialized variables. */
12454
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
681 if (!ReadFile (file, bss_start, bss_size, &n_read, NULL))
21604
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
682 w32_fatal_reload_error ("Reading the saved .bss section.");
12454
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
683
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
684 CloseHandle (file);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
685 }
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
686
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
687 /* Map the heap dumped into the executable file into our address space. */
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
688 void
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
689 map_in_heap (char *filename)
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
690 {
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
691 HANDLE file;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
692 HANDLE file_mapping;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
693 void *file_base;
12454
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
694 unsigned long size, upper_size, n_read;
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
695 int i;
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
696
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
697 file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL,
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
698 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
699 if (file == INVALID_HANDLE_VALUE)
21604
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
700 w32_fatal_reload_error ("Opening Emacs executable file for heap.");
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
701
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
702 size = GetFileSize (file, &upper_size);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
703 file_mapping = CreateFileMapping (file, NULL, PAGE_WRITECOPY,
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
704 0, size, NULL);
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
705 if (!file_mapping)
21604
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
706 w32_fatal_reload_error ("Creating file mapping to heap in executable.");
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
707
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
708 size = get_committed_heap_size ();
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
709 file_base = MapViewOfFileEx (file_mapping, FILE_MAP_COPY, 0,
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
710 heap_index_in_executable, size,
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
711 get_heap_start ());
12454
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
712 if (file_base != 0)
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
713 {
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
714 return;
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
715 }
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
716
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
717 /* If we don't succeed with the mapping, then copy from the
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
718 data into the heap. */
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
719
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
720 CloseHandle (file_mapping);
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
721
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
722 if (VirtualAlloc (get_heap_start (), get_committed_heap_size (),
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
723 MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE) == NULL)
21604
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
724 w32_fatal_reload_error ("Allocating heap address space.");
12454
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
725
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
726 /* Seek to the location of the heap data in the executable. */
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
727 i = heap_index_in_executable;
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
728 if (SetFilePointer (file, i, NULL, FILE_BEGIN) == 0xFFFFFFFF)
21604
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
729 w32_fatal_reload_error ("Seeking to saved heap in executable file.");
12454
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
730
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
731 /* Read in the data. */
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
732 if (!ReadFile (file, get_heap_start (),
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
733 get_committed_heap_size (), &n_read, NULL))
21604
104277bc1444 (my_begbss_static, my_endbss_static): Declare.
Geoff Voelker <voelker@cs.washington.edu>
parents: 21456
diff changeset
734 w32_fatal_reload_error ("Reading saved heap from executable file.");
12454
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
735
3f4da17a7cd8 (get_section_info): Set the end of the data region
Geoff Voelker <voelker@cs.washington.edu>
parents: 12245
diff changeset
736 CloseHandle (file);
12245
e8a6dfd8d5d2 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
737 }