annotate src/unexconvex.c @ 26702:8be2b52389a5

* viper-cmd.el (viper-change-state): Use viper-ESC-moves-cursor-back to decide whether to move the cursor back.
author Michael Kifer <kifer@cs.stonybrook.edu>
date Sat, 04 Dec 1999 06:19:05 +0000
parents ee40177f6c68
children 23a1cea22d13
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
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 12244
diff changeset
26 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 12244
diff changeset
27 Boston, MA 02111-1307, USA. */
484
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 /* modified for C-1 arch by jthomp@convex 871103 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 /* Corrected to support convex SOFF object file formats and thread specific
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 * regions. streepy@convex 890302
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 /*
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 * unexec.c - Convert a running program into an a.out file.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 * Author: Spencer W. Thomas
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 * Computer Science Dept.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 * University of Utah
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 * Date: Tue Mar 2 1982
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 * Modified heavily since then.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 * Synopsis:
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 * unexec (new_name, a_name, data_start, bss_start, entry_address)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 * char *new_name, *a_name;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 * unsigned data_start, bss_start, entry_address;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 * 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
50 * file named by the string argument new_name.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 * 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
52 * On some machines, an existing a_name file is required.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 * 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
55 * 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
56 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 * Data_start gives the boundary between the text segment and the data
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 * segment of the program. The text segment can contain shared, read-only
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 * program code and literal data, while the data segment is always unshared
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 * and unprotected. Data_start gives the lowest unprotected address.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 * The value you specify may be rounded down to a suitable boundary
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 * as required by the machine you are using.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 * Specifying zero for data_start means the boundary between text and data
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 * should not be the same as when the program was loaded.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 * 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
67 * segment boundaries are never changed.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 * 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
70 * 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
71 * 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
72 * 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
73 * 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
74 * break (2).
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 * The new file is set up to start at entry_address.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 * If you make improvements I'd like to get them too.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 * harpo!utah-cs!thomas, thomas@Utah-20
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 /* There are several compilation parameters affecting unexec:
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 * COFF
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 Define this if your system uses COFF for executables.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 Otherwise we assume you use Berkeley format.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 * NO_REMAP
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 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
93 as part of the text segment.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 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
96
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 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
98 the boundary cannot feasibly be moved. Such machines require
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 NO_REMAP.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 Also, remapping can cause trouble with the built-in startup routine
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 /lib/crt0.o, which defines `environ' as an initialized variable.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 Dumping `environ' as pure does not work! So, to use remapping,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 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
105 If NO_REMAP is defined, Emacs uses the system's crt0.o.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 * SECTION_ALIGNMENT
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 Some machines that use COFF executables require that each section
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 start on a certain boundary *in the COFF file*. Such machines should
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 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
112 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
113 segments in the COFF file.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 If SECTION_ALIGNMENT is not defined, the segments are written
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 consecutively with no attempt at alignment. This is right for
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 unmodified system V.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 * SEGMENT_MASK
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 Some machines require that the beginnings and ends of segments
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 *in core* be on certain boundaries. For most machines, a page
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 boundary is sufficient. That is the default. When a larger
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 boundary is needed, define SEGMENT_MASK to a mask of
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 the bits that must be zero on such a boundary.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 * A_TEXT_OFFSET(HDR)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 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
130 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
131 first data in the text segment. Some have additional padding between
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 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
133
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 For these machines, define A_TEXT_OFFSET(HDR) to examine the header
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 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
136 before writing it (above and beyond the number of bytes of actual
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 program text). HDR's standard fields are already correct, except that
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 this adjustment to the `a_text' field has not yet been made;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 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
140
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 * A_TEXT_SEEK(HDR)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 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
144 a.out file before starting to write the text segment.a
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 * EXEC_MAGIC
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 For machines using COFF, this macro, if defined, is a value stored
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 into the magic number field of the output file.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 * ADJUST_EXEC_HEADER
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 This macro can be used to generate statements to adjust or
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 initialize nonstandard fields in the file header
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 * ADDR_CORRECT(ADDR)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 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
159 into an int which is the number of a byte.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 This macro has a default definition which is usually right.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 This default definition is a no-op on most machines (where a
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 pointer looks like an int) but not on all machines.
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 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 3591
diff changeset
167 #include <config.h>
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 #define PERROR(file) report_error (file, new)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 #include <a.out.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 /* Define getpagesize () if the system does not.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 Note that this may depend on symbols defined in a.out.h
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 #include "getpagesize.h"
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 #include <sys/types.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 #include <stdio.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 #include <sys/stat.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 #include <errno.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 extern char *start_of_text (); /* Start of text */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 extern char *start_of_data (); /* Start of initialized data */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 #include <machine/filehdr.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 #include <machine/opthdr.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 #include <machine/scnhdr.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 #include <machine/pte.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 static long block_copy_start; /* Old executable start point */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 static struct filehdr f_hdr; /* File header */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 static struct opthdr f_ohdr; /* Optional file header (a.out) */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 long bias; /* Bias to add for growth */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 #define SYMS_START block_copy_start
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 static long text_scnptr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 static long data_scnptr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 static int pagemask;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 static int pagesz;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 static
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 report_error (file, fd)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 char *file;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 int fd;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 if (fd)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 close (fd);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 error ("Failure operating on %s", file);
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 #define ERROR0(msg) report_error_1 (new, msg, 0, 0); return -1
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 #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
213 #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
214
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 static
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 report_error_1 (fd, msg, a1, a2)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 int fd;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 char *msg;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 int a1, a2;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 close (fd);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 error (msg, a1, a2);
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 /* ****************************************************************
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 * unexec
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 * driving logic.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 unexec (new_name, a_name, data_start, bss_start, entry_address)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 char *new_name, *a_name;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 unsigned data_start, bss_start, entry_address;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 int new, a_out = -1;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 if (a_name && (a_out = open (a_name, 0)) < 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 PERROR (a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 if ((new = creat (new_name, 0666)) < 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 PERROR (new_name);
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 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
244 || copy_text_and_data (new) < 0
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 || copy_sym (new, a_out, a_name, new_name) < 0 ) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 close (new);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 return -1;
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 close (new);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 if (a_out >= 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 close (a_out);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 mark_x (new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 return 0;
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 /* ****************************************************************
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 * make_hdr
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 * 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
261 * Modify the text and data sizes.
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 struct scnhdr *stbl; /* Table of all scnhdr's */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 struct scnhdr *f_thdr; /* Text section header */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 struct scnhdr *f_dhdr; /* Data section header */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 struct scnhdr *f_tdhdr; /* Thread Data section header */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 struct scnhdr *f_bhdr; /* Bss section header */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 struct scnhdr *f_tbhdr; /* Thread Bss section header */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 static int
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 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
273 int new, a_out;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 unsigned data_start, bss_start, entry_address;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 char *a_name;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 char *new_name;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 register int scns;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 unsigned int bss_end;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 unsigned int eo_data; /* End of initialized data in new exec file */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 int scntype; /* Section type */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 int i; /* Var for sorting by vaddr */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 struct scnhdr scntemp; /* For swapping entries in sort */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 extern char *start_of_data();
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 pagemask = (pagesz = getpagesize()) - 1;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 /* Adjust text/data boundary. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 if (!data_start)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 data_start = (unsigned) start_of_data ();
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 data_start = data_start & ~pagemask; /* (Down) to page boundary. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 bss_end = (sbrk(0) + pagemask) & ~pagemask;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 /* Adjust data/bss boundary. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 if (bss_start != 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 bss_start = (bss_start + pagemask) & ~pagemask;/* (Up) to page bdry. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 if (bss_start > bss_end) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 ERROR1 ("unexec: Specified bss_start (%x) is past end of program",
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 bss_start);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 } else
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 bss_start = bss_end;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 if (data_start > bss_start) { /* Can't have negative data size. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 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
308 data_start, bss_start);
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 /* Salvage as much info from the existing file as possible */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 if (a_out < 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 ERROR0 ("can't build a COFF file from scratch yet");
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 /*NOTREACHED*/
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 if (read (a_out, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr)) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 PERROR (a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 block_copy_start += sizeof (f_hdr);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 if (f_hdr.h_opthdr > 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 if (read (a_out, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr)) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 PERROR (a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 block_copy_start += sizeof (f_ohdr);
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 /* Allocate room for scn headers */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 stbl = (struct scnhdr *)malloc( sizeof(struct scnhdr) * f_hdr.h_nscns );
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 if( stbl == NULL ) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 ERROR0( "unexec: malloc of stbl failed" );
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 f_tdhdr = f_tbhdr = NULL;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 /* Loop through section headers, copying them in */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 for (scns = 0; scns < f_hdr.h_nscns; scns++) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 if( read( a_out, &stbl[scns], sizeof(*stbl)) != sizeof(*stbl)) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 PERROR (a_name);
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 scntype = stbl[scns].s_flags & S_TYPMASK; /* What type of section */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 if( stbl[scns].s_scnptr > 0L) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 if( block_copy_start < stbl[scns].s_scnptr + stbl[scns].s_size )
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 block_copy_start = stbl[scns].s_scnptr + stbl[scns].s_size;
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 if( scntype == S_TEXT) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 f_thdr = &stbl[scns];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 } else if( scntype == S_DATA) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 f_dhdr = &stbl[scns];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 #ifdef S_TDATA
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 } else if( scntype == S_TDATA ) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 f_tdhdr = &stbl[scns];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 } else if( scntype == S_TBSS ) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 f_tbhdr = &stbl[scns];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 #endif /* S_TDATA (thread stuff) */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 } else if( scntype == S_BSS) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 f_bhdr = &stbl[scns];
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 /* 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
368 * all thread stuff alone.
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 /* Now we alter the contents of all the f_*hdr variables
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 to correspond to what we want to dump. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 f_thdr->s_vaddr = (long) start_of_text ();
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 f_thdr->s_size = data_start - f_thdr->s_vaddr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 f_thdr->s_scnptr = pagesz;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 f_thdr->s_relptr = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 f_thdr->s_nrel = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 eo_data = f_thdr->s_scnptr + f_thdr->s_size;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 if( f_tdhdr ) { /* Process thread data */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 f_tdhdr->s_vaddr = data_start;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 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
386 f_tdhdr->s_scnptr = eo_data;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 f_tdhdr->s_relptr = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 f_tdhdr->s_nrel = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 eo_data += f_tdhdr->s_size;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 /* And now for DATA */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 f_dhdr->s_vaddr = f_bhdr->s_vaddr; /* Take BSS start address */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 f_dhdr->s_size = bss_end - f_bhdr->s_vaddr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 f_dhdr->s_scnptr = eo_data;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 f_dhdr->s_relptr = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 f_dhdr->s_nrel = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 eo_data += f_dhdr->s_size;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402 } else {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 f_dhdr->s_vaddr = data_start;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 f_dhdr->s_size = bss_start - data_start;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 f_dhdr->s_scnptr = eo_data;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 f_dhdr->s_relptr = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 f_dhdr->s_nrel = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 eo_data += f_dhdr->s_size;
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 f_bhdr->s_vaddr = bss_start;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 f_bhdr->s_size = bss_end - bss_start + pagesz /* fudge */;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 f_bhdr->s_scnptr = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 f_bhdr->s_relptr = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 f_bhdr->s_nrel = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 text_scnptr = f_thdr->s_scnptr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 data_scnptr = f_dhdr->s_scnptr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 bias = eo_data - block_copy_start;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 if (f_ohdr.o_symptr > 0L) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 f_ohdr.o_symptr += bias;
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 if (f_hdr.h_strptr > 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 f_hdr.h_strptr += bias;
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 if (write (new, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr)) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 PERROR (new_name);
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 if (write (new, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr)) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 PERROR (new_name);
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 for( scns = 0; scns < f_hdr.h_nscns; scns++ ) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 484
diff changeset
442 /* 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
443 * in order of increasing virtual address. Dull but effective.
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 for( i = scns+1; i < f_hdr.h_nscns; i++ ) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 if( stbl[i].s_vaddr < stbl[scns].s_vaddr ) { /* Swap */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 scntemp = stbl[i];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 stbl[i] = stbl[scns];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 stbl[scns] = scntemp;
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 for( scns = 0; scns < f_hdr.h_nscns; scns++ ) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458 if( write( new, &stbl[scns], sizeof(*stbl)) != sizeof(*stbl)) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 PERROR (new_name);
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464 return (0);
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 /* ****************************************************************
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 * copy_text_and_data
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 * 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
472 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 static int
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474 copy_text_and_data (new)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 int new;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477 register int scns;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
478
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
479 for( scns = 0; scns < f_hdr.h_nscns; scns++ )
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
480 write_segment( new, &stbl[scns] );
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
481
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
482 return 0;
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485 write_segment( new, sptr )
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486 int new;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 struct scnhdr *sptr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
489 register char *ptr, *end;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 register int nwrite, ret;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 char buf[80];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492 extern int errno;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
493 char zeros[128];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
494
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
495 if( sptr->s_scnptr == 0 )
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496 return; /* Nothing to do */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
498 if( lseek( new, (long) sptr->s_scnptr, 0 ) == -1 )
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
499 PERROR( "unexecing" );
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
500
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
501 bzero (zeros, sizeof zeros);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
502
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
503 ptr = (char *) sptr->s_vaddr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
504 end = ptr + sptr->s_size;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
505
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
506 while( ptr < end ) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508 /* distance to next multiple of 128. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
509 nwrite = (((int) ptr + 128) & -128) - (int) ptr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 /* But not beyond specified end. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511 if (nwrite > end - ptr) nwrite = end - ptr;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 ret = write (new, ptr, nwrite);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513 /* If write gets a page fault, it means we reached
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 a gap between the old text segment and the old data segment.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
515 This gap has probably been remapped into part of the text segment.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
516 So write zeros for it. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
517 if (ret == -1 && errno == EFAULT)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
518 write (new, zeros, nwrite);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
519 else if (nwrite != ret) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
520 sprintf (buf,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
521 "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
522 ptr, new, nwrite, ret, errno);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
523 PERROR (buf);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
524 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
525 ptr += nwrite;
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 /* ****************************************************************
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 * copy_sym
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
531 *
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532 * 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
533 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
534 static int
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535 copy_sym (new, a_out, a_name, new_name)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 int new, a_out;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537 char *a_name, *new_name;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
538 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
539 char page[1024];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
540 int n;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
541
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542 if (a_out < 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
543 return 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
544
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
545 if (SYMS_START == 0L)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546 return 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
547
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
548 lseek (a_out, SYMS_START, 0); /* Position a.out to symtab. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
549 lseek( new, (long)f_ohdr.o_symptr, 0 );
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
550
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551 while ((n = read (a_out, page, sizeof page)) > 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
552 if (write (new, page, n) != n) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
553 PERROR (new_name);
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 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
556 if (n < 0) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
557 PERROR (a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
558 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
559 return 0;
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 /* ****************************************************************
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563 * mark_x
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
564 *
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 484
diff changeset
565 * After successfully building the new a.out, mark it executable
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
566 */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
567 static
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
568 mark_x (name)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
569 char *name;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
570 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571 struct stat sbuf;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 int um;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
573 int new = 0; /* for PERROR */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
574
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
575 um = umask (777);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
576 umask (um);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
577 if (stat (name, &sbuf) == -1) {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
578 PERROR (name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
579 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
580 sbuf.st_mode |= 0111 & ~um;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
581 if (chmod (name, sbuf.st_mode) == -1)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
582 PERROR (name);
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
585 /* 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
586 is sometimes configured down to 'm', 'n', or 'o' for some reason. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
587
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
588 first_pty_letter ()
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
589 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
590 struct stat buf;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
591 char pty_name[16];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
592 char c;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
593
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
594 for (c = 'o'; c >= 'a'; c--)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
595 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
596 sprintf (pty_name, "/dev/pty%c0", c);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
597 if (stat (pty_name, &buf) < 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
598 return c + 1;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
599 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
600 return 'a';
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
601 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
602