annotate src/unexenix.c @ 83833:98eeda530a30

*** empty log message ***
author Jay Belanger <jay.p.belanger@gmail.com>
date Sat, 01 Sep 2007 04:13:52 +0000
parents 922696f363b0
children fc2bcd2a8aad f55f9811f5d7
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 /* Unexec for Xenix.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2 Note that the GNU project considers support for Xenix operation
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3 a peripheral activity which should not be allowed to divert effort
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 from development of the GNU system. Changes in this code will be
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5 installed when Xenix users send them in, but aside from that
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 we don't plan to think about it, or about whether other Emacs
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 maintenance might break it.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8
75227
e90d04cd455a Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents: 68651
diff changeset
9 Copyright (C) 1988, 1994, 2001, 2002, 2003, 2004,
e90d04cd455a Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents: 68651
diff changeset
10 2005, 2006, 2007 Free Software Foundation, Inc.
484
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
78260
922696f363b0 Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 75227
diff changeset
16 the Free Software Foundation; either version 3, 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
64084
a8fa7c632ee4 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
26 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
a8fa7c632ee4 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
27 Boston, MA 02110-1301, 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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 /*
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 On 80386 Xenix, segmentation screws prevent us from modifying the text
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 segment at all. We basically just plug a new value for "data segment
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 size" into the countless headers and copy the other records straight
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 through. The data segment is ORG'ed at the xs_rbase value of the data
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 segment's xseg record (always @ 0x1880000, thanks to the "sophisticated
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 memory management hardware" of the chip) and extends to sbrk(0), exactly.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 This code is afraid to malloc (should it be?), and alloca has to be the
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 wimpy, malloc-based version; consequently, data is usually copied in
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 smallish chunks.
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 gb@entity.com
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
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 3591
diff changeset
45 #include <config.h>
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 #include <sys/types.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 #include <fcntl.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 #include <sys/file.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 #include <sys/stat.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 #include <stdio.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 #include <varargs.h>
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 #include <a.out.h>
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 static void fatal_unexec ();
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 #define READ(_fd, _buffer, _size, _error_message, _error_arg) \
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 errno = EEOF; \
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 if (read(_fd, _buffer, _size) != _size) \
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 fatal_unexec(_error_message, _error_arg);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 #define WRITE(_fd, _buffer, _size, _error_message, _error_arg) \
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 if (write(_fd, _buffer, _size) != _size) \
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 fatal_unexec(_error_message, _error_arg);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 #define SEEK(_fd, _position, _error_message, _error_arg) \
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 errno = EEOF; \
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 if (lseek(_fd, _position, L_SET) != _position) \
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 fatal_unexec(_error_message, _error_arg);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 extern int errno;
5521
d1d144ed5b76 Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents: 4696
diff changeset
71 extern char *strerror ();
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 #define EEOF -1
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 #ifndef L_SET
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 #define L_SET 0
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 #endif
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 /* Should check the magic number of the old executable;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 not yet written. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 check_exec (x)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 struct xexec *x;
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 }
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
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 unexec (new_name, a_name, data_start, bss_start, entry_address)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 char *new_name, *a_name;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 unsigned data_start, bss_start, entry_address;
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 char *sbrk (), *datalim = sbrk (0), *data_org;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 long segpos, textseen, textpos, textlen, datapos, datadiff, datalen;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 struct xexec u_xexec, /* a.out header */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 *u_xexecp = &u_xexec;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 struct xext u_xext, /* extended header */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 *u_xextp = &u_xext;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 struct xseg u_xseg, /* segment table entry */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 *u_xsegp = &u_xseg;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 int i, nsegs, isdata = 0, infd, outfd;
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 infd = open (a_name, O_RDONLY, 0);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 if (infd < 0) fatal_unexec ("opening %s", a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 outfd = creat (new_name, 0666);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 if (outfd < 0) fatal_unexec ("creating %s", new_name);
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 READ (infd, u_xexecp, sizeof (struct xexec),
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 "error reading %s", a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 check_exec (u_xexecp);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 READ (infd, u_xextp, sizeof (struct xext),
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 "error reading %s", a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 segpos = u_xextp->xe_segpos;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 nsegs = u_xextp->xe_segsize / sizeof (struct xseg);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 SEEK (infd, segpos, "seek error on %s", a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 for (i = 0; i < nsegs; i ++)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 READ (infd, u_xsegp, sizeof (struct xseg),
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 "error reading %s", a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 switch (u_xsegp->xs_type)
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 case XS_TTEXT:
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 if (i == 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 textpos = u_xsegp->xs_filpos;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 textlen = u_xsegp->xs_psize;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 break;
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 fatal_unexec ("invalid text segment in %s", a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 case XS_TDATA:
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 if (i == 1)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 datapos = u_xsegp->xs_filpos;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 datalen = datalim - (data_org = (char *)(u_xsegp->xs_rbase));
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 datadiff = datalen - u_xsegp->xs_psize;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 break;
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 fatal_unexec ("invalid data segment in %s", a_name);
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 default:
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 if (i > 1) break;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 fatal_unexec ("invalid segment record in %s", a_name);
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 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 }
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 u_xexecp->x_data = datalen;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 u_xexecp->x_bss = 0;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 WRITE (outfd, u_xexecp, sizeof (struct xexec),
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 "error writing %s", new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 WRITE (outfd, u_xextp, sizeof (struct xext),
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 "error writing %s", new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 SEEK (infd, segpos, "seek error on %s", a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 SEEK (outfd, segpos, "seek error on %s", new_name);
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 /* Copy the text segment record verbatim. */
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 copyrec (infd, outfd, sizeof (struct xseg), a_name, new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 /* Read, modify, write the data segment record. */
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 READ (infd, u_xsegp, sizeof (struct xseg),
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 "error reading %s", a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 u_xsegp->xs_psize = u_xsegp->xs_vsize = datalen;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 u_xsegp->xs_attr &= (~XS_AITER & ~XS_ABSS);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 WRITE (outfd, u_xsegp, sizeof (struct xseg),
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 "error writing %s", new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 /* Now copy any additional segment records, adjusting their
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 file position field */
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 for (i = 2; i < nsegs; i++)
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 READ (infd, u_xsegp, sizeof (struct xseg),
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 "error reading %s", a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 u_xsegp->xs_filpos += datadiff;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 WRITE (outfd, u_xsegp, sizeof (struct xseg),
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 "error writing %s", new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 }
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 SEEK (infd, textpos, "seek error on %s", a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 SEEK (outfd, textpos, "seek error on %s", new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 copyrec (infd, outfd, textlen, a_name, new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 SEEK (outfd, datapos, "seek error on %s", new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 WRITE (outfd, data_org, datalen,
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 "write error on %s", new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 14186
diff changeset
191 for (i = 2, segpos += (2 * sizeof (struct xseg));
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 i < nsegs;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 i++, segpos += sizeof (struct xseg))
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 SEEK (infd, segpos, "seek error on %s", a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 READ (infd, u_xsegp, sizeof (struct xseg),
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 "read error on %s", a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 SEEK (infd, u_xsegp->xs_filpos, "seek error on %s", a_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 /* We should be at eof in the output file here, but we must seek
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 because the xs_filpos and xs_psize fields in symbol table
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 segments are inconsistent. */
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 SEEK (outfd, u_xsegp->xs_filpos + datadiff, "seek error on %s", new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 copyrec (infd, outfd, u_xsegp->xs_psize, a_name, new_name);
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 close (infd);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 close (outfd);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 mark_x (new_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 return 0;
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 copyrec (infd, outfd, len, in_name, out_name)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 int infd, outfd, len;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 char *in_name, *out_name;
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 char buf[BUFSIZ];
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 int chunk;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 while (len)
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 chunk = BUFSIZ;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 if (chunk > len)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 chunk = len;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 READ (infd, buf, chunk, "error reading %s", in_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 WRITE (outfd, buf, chunk, "error writing %s", out_name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 len -= chunk;
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 }
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 /*
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 * mark_x
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 *
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 484
diff changeset
232 * After successfully building the new a.out, mark it executable
484
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 static
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 mark_x (name)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 char *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 struct stat sbuf;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 int um = umask (777);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 umask (um);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 if (stat (name, &sbuf) < 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 fatal_unexec ("getting protection on %s", name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 sbuf.st_mode |= 0111 & ~um;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 if (chmod (name, sbuf.st_mode) < 0)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 fatal_unexec ("setting protection on %s", name);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 }
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 static void
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 fatal_unexec (s, va_alist)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 va_dcl
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 {
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 va_list ap;
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 if (errno == EEOF)
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 fputs ("unexec: unexpected end of file, ", stderr);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 else
5521
d1d144ed5b76 Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents: 4696
diff changeset
256 fprintf (stderr, "unexec: %s, ", strerror (errno));
484
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 va_start (ap);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 _doprnt (s, ap, stderr);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 fputs (".\n", stderr);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 exit (1);
3165b2697c78 entered into RCS
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 }
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
262
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
263 /* arch-tag: ce26be27-370a-438d-83b4-766059749a02
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
264 (do not change this comment) */