annotate src/unexconvex.c @ 13274:712386e1abe0

Whitespace changes.
author Richard M. Stallman <rms@gnu.org>
date Sun, 22 Oct 1995 18:28:17 +0000
parents ac7375e60931
children ee40177f6c68
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Modified version of unexec for convex machines.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2 Note that the GNU project considers support for the peculiarities
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3 of the Convex operating system a peripheral activity which should
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 not be allowed to divert effort from development of the GNU system.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5 Changes in this code will be installed when Convex system
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 maintainers send them in, but aside from that we don't plan to
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 think about it, or about whether other Emacs maintenance might
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 break it.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 Copyright (C) 1985, 1986, 1988 Free Software Foundation, Inc.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 This file is part of GNU Emacs.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 GNU Emacs is free software; you can redistribute it and/or modify
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 it under the terms of the GNU General Public License as published by
12244
ac7375e60931 Update GPL to version 2.
Karl Heuer <kwzh@gnu.org>
parents: 4696
diff changeset
16 the Free Software Foundation; either version 2, or (at your option)
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 any later version.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 GNU Emacs is distributed in the hope that it will be useful,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 GNU General Public License for more details.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 You should have received a copy of the GNU General Public License
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 along with GNU Emacs; see the file COPYING. If not, write to
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 /* modified for C-1 arch by jthomp@convex 871103 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 /* Corrected to support convex SOFF object file formats and thread specific
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 * regions. streepy@convex 890302
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 /*
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 * unexec.c - Convert a running program into an a.out file.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 * Author: Spencer W. Thomas
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 * Computer Science Dept.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 * University of Utah
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 * Date: Tue Mar 2 1982
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 * Modified heavily since then.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 * Synopsis:
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 * unexec (new_name, a_name, data_start, bss_start, entry_address)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 * char *new_name, *a_name;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 * unsigned data_start, bss_start, entry_address;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 * Takes a snapshot of the program and makes an a.out format file in the
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 * file named by the string argument new_name.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 * If a_name is non-NULL, the symbol table will be taken from the given file.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 * On some machines, an existing a_name file is required.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 * The boundaries within the a.out file may be adjusted with the data_start
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 * and bss_start arguments. Either or both may be given as 0 for defaults.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 * Data_start gives the boundary between the text segment and the data
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 * segment of the program. The text segment can contain shared, read-only
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 * program code and literal data, while the data segment is always unshared
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 * and unprotected. Data_start gives the lowest unprotected address.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 * The value you specify may be rounded down to a suitable boundary
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 * as required by the machine you are using.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 * Specifying zero for data_start means the boundary between text and data
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 * should not be the same as when the program was loaded.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 * If NO_REMAP is defined, the argument data_start is ignored and the
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 * segment boundaries are never changed.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 * Bss_start indicates how much of the data segment is to be saved in the
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 * a.out file and restored when the program is executed. It gives the lowest
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 * unsaved address, and is rounded up to a page boundary. The default when 0
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 * is given assumes that the entire data segment is to be stored, including
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 * the previous data and bss as well as any additional storage allocated with
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 * break (2).
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 * The new file is set up to start at entry_address.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 * If you make improvements I'd like to get them too.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 * harpo!utah-cs!thomas, thomas@Utah-20
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 /* There are several compilation parameters affecting unexec:
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 * COFF
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 Define this if your system uses COFF for executables.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 Otherwise we assume you use Berkeley format.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 * NO_REMAP
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 Define this if you do not want to try to save Emacs's pure data areas
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 as part of the text segment.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 Saving them as text is good because it allows users to share more.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 However, on machines that locate the text area far from the data area,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 the boundary cannot feasibly be moved. Such machines require
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 NO_REMAP.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 Also, remapping can cause trouble with the built-in startup routine
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 /lib/crt0.o, which defines `environ' as an initialized variable.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 Dumping `environ' as pure does not work! So, to use remapping,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 you must write a startup routine for your machine in Emacs's crt0.c.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 If NO_REMAP is defined, Emacs uses the system's crt0.o.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 * SECTION_ALIGNMENT
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 Some machines that use COFF executables require that each section
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 start on a certain boundary *in the COFF file*. Such machines should
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 define SECTION_ALIGNMENT to a mask of the low-order bits that must be
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 zero on such a boundary. This mask is used to control padding between
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 segments in the COFF file.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 If SECTION_ALIGNMENT is not defined, the segments are written
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 consecutively with no attempt at alignment. This is right for
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 unmodified system V.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 * SEGMENT_MASK
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 Some machines require that the beginnings and ends of segments
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 *in core* be on certain boundaries. For most machines, a page
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 boundary is sufficient. That is the default. When a larger
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 boundary is needed, define SEGMENT_MASK to a mask of
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 the bits that must be zero on such a boundary.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 * A_TEXT_OFFSET(HDR)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 Some machines count the a.out header as part of the size of the text
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 segment (a_text); they may actually load the header into core as the
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 first data in the text segment. Some have additional padding between
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 the header and the real text of the program that is counted in a_text.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 For these machines, define A_TEXT_OFFSET(HDR) to examine the header
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 structure HDR and return the number of bytes to add to `a_text'
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 before writing it (above and beyond the number of bytes of actual
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 program text). HDR's standard fields are already correct, except that
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 this adjustment to the `a_text' field has not yet been made;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 thus, the amount of offset can depend on the data in the file.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 * A_TEXT_SEEK(HDR)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 If defined, this macro specifies the number of bytes to seek into the
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 a.out file before starting to write the text segment.a
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 * EXEC_MAGIC
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 For machines using COFF, this macro, if defined, is a value stored
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 into the magic number field of the output file.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 * ADJUST_EXEC_HEADER
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 This macro can be used to generate statements to adjust or
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 initialize nonstandard fields in the file header
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 * ADDR_CORRECT(ADDR)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 Macro to correct an int which is the bit pattern of a pointer to a byte
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 into an int which is the number of a byte.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 This macro has a default definition which is usually right.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 This default definition is a no-op on most machines (where a
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 pointer looks like an int) but not on all machines.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 3591
diff changeset
166 #include <config.h>
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 #define PERROR(file) report_error (file, new)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 #include <a.out.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 /* Define getpagesize () if the system does not.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 Note that this may depend on symbols defined in a.out.h
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 #include "getpagesize.h"
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 #include <sys/types.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 #include <stdio.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 #include <sys/stat.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 #include <errno.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 extern char *start_of_text (); /* Start of text */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 extern char *start_of_data (); /* Start of initialized data */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 #include <machine/filehdr.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 #include <machine/opthdr.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 #include <machine/scnhdr.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 #include <machine/pte.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 static long block_copy_start; /* Old executable start point */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 static struct filehdr f_hdr; /* File header */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 static struct opthdr f_ohdr; /* Optional file header (a.out) */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 long bias; /* Bias to add for growth */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 #define SYMS_START block_copy_start
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 static long text_scnptr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 static long data_scnptr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 static int pagemask;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 static int pagesz;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 static
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 report_error (file, fd)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 char *file;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 int fd;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 if (fd)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 close (fd);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 error ("Failure operating on %s", file);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 #define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 #define ERROR1(msg,x) report_error_1 (new, msg, x, 0); return -1
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 #define ERROR2(msg,x,y) report_error_1 (new, msg, x, y); return -1
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 static
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 report_error_1 (fd, msg, a1, a2)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 int fd;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 char *msg;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 int a1, a2;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 close (fd);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 error (msg, a1, a2);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 /* ****************************************************************
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 * unexec
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 * driving logic.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 unexec (new_name, a_name, data_start, bss_start, entry_address)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 char *new_name, *a_name;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 unsigned data_start, bss_start, entry_address;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 int new, a_out = -1;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 if (a_name && (a_out = open (a_name, 0)) < 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 PERROR (a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 if ((new = creat (new_name, 0666)) < 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 PERROR (new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 if (make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) < 0
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 || copy_text_and_data (new) < 0
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 || copy_sym (new, a_out, a_name, new_name) < 0 ) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 close (new);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 return -1;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 close (new);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 if (a_out >= 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 close (a_out);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 mark_x (new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 return 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 /* ****************************************************************
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 * make_hdr
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 * Make the header in the new a.out from the header in core.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 * Modify the text and data sizes.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 struct scnhdr *stbl; /* Table of all scnhdr's */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 struct scnhdr *f_thdr; /* Text section header */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 struct scnhdr *f_dhdr; /* Data section header */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 struct scnhdr *f_tdhdr; /* Thread Data section header */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 struct scnhdr *f_bhdr; /* Bss section header */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 struct scnhdr *f_tbhdr; /* Thread Bss section header */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 static int
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 int new, a_out;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 unsigned data_start, bss_start, entry_address;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 char *a_name;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 char *new_name;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 register int scns;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 unsigned int bss_end;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 unsigned int eo_data; /* End of initialized data in new exec file */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 int scntype; /* Section type */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 int i; /* Var for sorting by vaddr */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 struct scnhdr scntemp; /* For swapping entries in sort */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 extern char *start_of_data();
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 pagemask = (pagesz = getpagesize()) - 1;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 /* Adjust text/data boundary. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 if (!data_start)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 data_start = (unsigned) start_of_data ();
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 data_start = data_start & ~pagemask; /* (Down) to page boundary. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 bss_end = (sbrk(0) + pagemask) & ~pagemask;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 /* Adjust data/bss boundary. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 if (bss_start != 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 bss_start = (bss_start + pagemask) & ~pagemask;/* (Up) to page bdry. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 if (bss_start > bss_end) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 ERROR1 ("unexec: Specified bss_start (%x) is past end of program",
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 bss_start);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 } else
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 bss_start = bss_end;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 if (data_start > bss_start) { /* Can't have negative data size. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 ERROR2 ("unexec: data_start (%x) can't be greater than bss_start (%x)",
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 data_start, bss_start);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 /* Salvage as much info from the existing file as possible */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 if (a_out < 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 ERROR0 ("can't build a COFF file from scratch yet");
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 /*NOTREACHED*/
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 if (read (a_out, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr)) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 PERROR (a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 block_copy_start += sizeof (f_hdr);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 if (f_hdr.h_opthdr > 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 if (read (a_out, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr)) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 PERROR (a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 block_copy_start += sizeof (f_ohdr);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 /* Allocate room for scn headers */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 stbl = (struct scnhdr *)malloc( sizeof(struct scnhdr) * f_hdr.h_nscns );
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 if( stbl == NULL ) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 ERROR0( "unexec: malloc of stbl failed" );
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 f_tdhdr = f_tbhdr = NULL;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 /* Loop through section headers, copying them in */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 for (scns = 0; scns < f_hdr.h_nscns; scns++) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 if( read( a_out, &stbl[scns], sizeof(*stbl)) != sizeof(*stbl)) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 PERROR (a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 scntype = stbl[scns].s_flags & S_TYPMASK; /* What type of section */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 if( stbl[scns].s_scnptr > 0L) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 if( block_copy_start < stbl[scns].s_scnptr + stbl[scns].s_size )
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 block_copy_start = stbl[scns].s_scnptr + stbl[scns].s_size;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 if( scntype == S_TEXT) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 f_thdr = &stbl[scns];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 } else if( scntype == S_DATA) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 f_dhdr = &stbl[scns];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 #ifdef S_TDATA
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 } else if( scntype == S_TDATA ) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 f_tdhdr = &stbl[scns];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 } else if( scntype == S_TBSS ) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 f_tbhdr = &stbl[scns];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 #endif /* S_TDATA (thread stuff) */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 } else if( scntype == S_BSS) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 f_bhdr = &stbl[scns];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 /* We will now convert TEXT and DATA into TEXT, BSS into DATA, and leave
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 * all thread stuff alone.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 /* Now we alter the contents of all the f_*hdr variables
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 to correspond to what we want to dump. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 f_thdr->s_vaddr = (long) start_of_text ();
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 f_thdr->s_size = data_start - f_thdr->s_vaddr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 f_thdr->s_scnptr = pagesz;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 f_thdr->s_relptr = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 f_thdr->s_nrel = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 eo_data = f_thdr->s_scnptr + f_thdr->s_size;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 if( f_tdhdr ) { /* Process thread data */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 f_tdhdr->s_vaddr = data_start;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 f_tdhdr->s_size += f_dhdr->s_size - (data_start - f_dhdr->s_vaddr);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 f_tdhdr->s_scnptr = eo_data;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 f_tdhdr->s_relptr = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 f_tdhdr->s_nrel = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 eo_data += f_tdhdr->s_size;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 /* And now for DATA */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 f_dhdr->s_vaddr = f_bhdr->s_vaddr; /* Take BSS start address */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 f_dhdr->s_size = bss_end - f_bhdr->s_vaddr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 f_dhdr->s_scnptr = eo_data;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 f_dhdr->s_relptr = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 f_dhdr->s_nrel = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 eo_data += f_dhdr->s_size;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 } else {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 f_dhdr->s_vaddr = data_start;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 f_dhdr->s_size = bss_start - data_start;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 f_dhdr->s_scnptr = eo_data;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 f_dhdr->s_relptr = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 f_dhdr->s_nrel = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 eo_data += f_dhdr->s_size;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 f_bhdr->s_vaddr = bss_start;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 f_bhdr->s_size = bss_end - bss_start + pagesz /* fudge */;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 f_bhdr->s_scnptr = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 f_bhdr->s_relptr = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 f_bhdr->s_nrel = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 text_scnptr = f_thdr->s_scnptr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 data_scnptr = f_dhdr->s_scnptr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 bias = eo_data - block_copy_start;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 if (f_ohdr.o_symptr > 0L) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 f_ohdr.o_symptr += bias;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 if (f_hdr.h_strptr > 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 f_hdr.h_strptr += bias;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 if (write (new, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr)) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 PERROR (new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 if (write (new, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr)) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 PERROR (new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 for( scns = 0; scns < f_hdr.h_nscns; scns++ ) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 484
diff changeset
441 /* This is a cheesy little loop to write out the section headers
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 * in order of increasing virtual address. Dull but effective.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 for( i = scns+1; i < f_hdr.h_nscns; i++ ) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 if( stbl[i].s_vaddr < stbl[scns].s_vaddr ) { /* Swap */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 scntemp = stbl[i];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 stbl[i] = stbl[scns];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 stbl[scns] = scntemp;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 for( scns = 0; scns < f_hdr.h_nscns; scns++ ) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457 if( write( new, &stbl[scns], sizeof(*stbl)) != sizeof(*stbl)) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458 PERROR (new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 return (0);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 /* ****************************************************************
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468 * copy_text_and_data
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 * Copy the text and data segments from memory to the new a.out
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 static int
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 copy_text_and_data (new)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474 int new;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 register int scns;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
478 for( scns = 0; scns < f_hdr.h_nscns; scns++ )
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
479 write_segment( new, &stbl[scns] );
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
480
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
481 return 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
482 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
483
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
484 write_segment( new, sptr )
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485 int new;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486 struct scnhdr *sptr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488 register char *ptr, *end;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
489 register int nwrite, ret;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 char buf[80];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 extern int errno;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492 char zeros[128];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
493
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
494 if( sptr->s_scnptr == 0 )
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
495 return; /* Nothing to do */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497 if( lseek( new, (long) sptr->s_scnptr, 0 ) == -1 )
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
498 PERROR( "unexecing" );
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
499
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
500 bzero (zeros, sizeof zeros);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
501
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
502 ptr = (char *) sptr->s_vaddr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
503 end = ptr + sptr->s_size;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
504
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
505 while( ptr < end ) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
506
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507 /* distance to next multiple of 128. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508 nwrite = (((int) ptr + 128) & -128) - (int) ptr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
509 /* But not beyond specified end. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 if (nwrite > end - ptr) nwrite = end - ptr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511 ret = write (new, ptr, nwrite);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 /* If write gets a page fault, it means we reached
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513 a gap between the old text segment and the old data segment.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 This gap has probably been remapped into part of the text segment.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
515 So write zeros for it. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
516 if (ret == -1 && errno == EFAULT)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
517 write (new, zeros, nwrite);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
518 else if (nwrite != ret) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
519 sprintf (buf,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
520 "unexec write failure: addr 0x%x, fileno %d, size 0x%x, wrote 0x%x, errno %d",
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
521 ptr, new, nwrite, ret, errno);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
522 PERROR (buf);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
523 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
524 ptr += nwrite;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
525 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
528 /* ****************************************************************
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
529 * copy_sym
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
531 * Copy the relocation information and symbol table from the a.out to the new
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
533 static int
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
534 copy_sym (new, a_out, a_name, new_name)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535 int new, a_out;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 char *a_name, *new_name;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
538 char page[1024];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
539 int n;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
540
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
541 if (a_out < 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542 return 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
543
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
544 if (SYMS_START == 0L)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
545 return 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
547 lseek (a_out, SYMS_START, 0); /* Position a.out to symtab. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
548 lseek( new, (long)f_ohdr.o_symptr, 0 );
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
549
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
550 while ((n = read (a_out, page, sizeof page)) > 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551 if (write (new, page, n) != n) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
552 PERROR (new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
553 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
554 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555 if (n < 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
556 PERROR (a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
557 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
558 return 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
559 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
560
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
561 /* ****************************************************************
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
562 * mark_x
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563 *
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 484
diff changeset
564 * After successfully building the new a.out, mark it executable
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
565 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
566 static
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
567 mark_x (name)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
568 char *name;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
569 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
570 struct stat sbuf;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571 int um;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 int new = 0; /* for PERROR */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
573
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
574 um = umask (777);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
575 umask (um);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
576 if (stat (name, &sbuf) == -1) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
577 PERROR (name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
578 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
579 sbuf.st_mode |= 0111 & ~um;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
580 if (chmod (name, sbuf.st_mode) == -1)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
581 PERROR (name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
582 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
583
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
584 /* Find the first pty letter. This is usually 'p', as in ptyp0, but
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
585 is sometimes configured down to 'm', 'n', or 'o' for some reason. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
586
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
587 first_pty_letter ()
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
588 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
589 struct stat buf;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
590 char pty_name[16];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
591 char c;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
592
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
593 for (c = 'o'; c >= 'a'; c--)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
594 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
595 sprintf (pty_name, "/dev/pty%c0", c);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
596 if (stat (pty_name, &buf) < 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
597 return c + 1;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
598 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
599 return 'a';
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
600 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
601