annotate src/unexmips.c @ 96613:379d83ec4588

* simple.el (previous-line, next-line): Update docstring.
author Chong Yidong <cyd@stupidchicken.com>
date Fri, 11 Jul 2008 18:10:59 +0000
parents 162cf3adba6b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Unexec for MIPS (including IRIS4D).
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
2 Note that the GNU project considers support for MIPS operation
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3 a peripheral activity which should not be allowed to divert effort
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 from development of the GNU system. Changes in this code will be
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5 installed when users send them in, but aside from that
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 we don't plan to think about it, or about whether other Emacs
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 maintenance might break it.
80cdb2387043 Initial revision
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,
79759
fc2bcd2a8aad Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 78260
diff changeset
10 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 This file is part of GNU Emacs.
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13
94963
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92159
diff changeset
14 GNU Emacs is free software: you can redistribute it and/or modify
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 it under the terms of the GNU General Public License as published by
94963
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92159
diff changeset
16 the Free Software Foundation, either version 3 of the License, or
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92159
diff changeset
17 (at your option) any later version.
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 GNU Emacs is distributed in the hope that it will be useful,
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 GNU General Public License for more details.
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 You should have received a copy of the GNU General Public License
94963
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 92159
diff changeset
25 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 3591
diff changeset
28 #include <config.h>
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 #include <sys/types.h>
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 #include <sys/file.h>
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 #include <sys/stat.h>
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 #include <stdio.h>
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 #include <varargs.h>
12420
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
34
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
35 #ifdef MACH
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
36
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
37 #include <a.out.h>
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
38
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
39 /* I don't know why this isn't defined. */
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
40 #ifndef STYP_INIT
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
41 #define STYP_INIT 0x80000000
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
42 #endif
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
43
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
44 /* I don't know why this isn't defined. */
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
45 #ifndef _RDATA
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
46 #define _RDATA ".rdata"
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
47 #define STYP_RDATA 0x00000100
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
48 #endif
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
49
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
50 /* Small ("near") data section. */
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
51 #ifndef _SDATA
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
52 #define _SDATA ".sdata"
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
53 #define STYP_SDATA 0x00000200
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
54 #endif
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
55
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
56 /* Small ("near") bss section. */
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
57 #ifndef _SBSS
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
58 #define _SBSS ".sbss"
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
59 #define STYP_SBSS 0x00000400
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
60 #endif
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
61
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
62 /* We don't seem to have a sym.h or syms.h anywhere, so we'll do it the
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
63 hard way. This stinks. */
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
64 typedef struct {
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
65 short magic;
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
66 short vstamp;
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
67 long ilineMax;
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
68 struct { long foo, offset; } offsets[11];
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
69 } HDRR, *pHDRR;
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
70
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
71 #else /* not MACH */
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
72
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 #include <filehdr.h>
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 #include <aouthdr.h>
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 #include <scnhdr.h>
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 #include <sym.h>
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77
12420
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
78 #endif /* not MACH */
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
79
96580
162cf3adba6b * unexmips.c:
Dan Nicolaescu <dann@ics.uci.edu>
parents: 94963
diff changeset
80 #if defined (IRIS_4D)
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 #include "getpagesize.h"
1486
1a12c5f1c04d [sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 1122
diff changeset
82 #include <fcntl.h>
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 #endif
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 static void fatal_unexec ();
1122
42922d56e5a6 * unexmips.c (mark_x): Declare this as static void at the top of
Jim Blandy <jimb@redhat.com>
parents: 1094
diff changeset
86 static void mark_x ();
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 #define READ(_fd, _buffer, _size, _error_message, _error_arg) \
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 errno = EEOF; \
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 if (read (_fd, _buffer, _size) != _size) \
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 fatal_unexec (_error_message, _error_arg);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 #define WRITE(_fd, _buffer, _size, _error_message, _error_arg) \
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 if (write (_fd, _buffer, _size) != _size) \
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 fatal_unexec (_error_message, _error_arg);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 #define SEEK(_fd, _position, _error_message, _error_arg) \
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 errno = EEOF; \
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 if (lseek (_fd, _position, L_SET) != _position) \
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 fatal_unexec (_error_message, _error_arg);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 extern int errno;
5521
d1d144ed5b76 Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents: 4696
diff changeset
103 extern char *strerror ();
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 #define EEOF -1
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 static struct scnhdr *text_section;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 static struct scnhdr *init_section;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 static struct scnhdr *finit_section;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 static struct scnhdr *rdata_section;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 static struct scnhdr *data_section;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 static struct scnhdr *lit8_section;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 static struct scnhdr *lit4_section;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 static struct scnhdr *sdata_section;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 static struct scnhdr *sbss_section;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 static struct scnhdr *bss_section;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 struct headers {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 struct filehdr fhdr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 struct aouthdr aout;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 struct scnhdr section[10];
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 };
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 /* Define name of label for entry point for the dumped executable. */
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 #ifndef DEFAULT_ENTRY_ADDRESS
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 #define DEFAULT_ENTRY_ADDRESS __start
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 #endif
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 unexec (new_name, a_name, data_start, bss_start, entry_address)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 char *new_name, *a_name;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 unsigned data_start, bss_start, entry_address;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 int new, old;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 int pagesize, brk;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 int newsyms, symrel;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 int nread;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 struct headers hdr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 int i;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 int vaddr, scnptr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 #define BUFSIZE 8192
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 char buffer[BUFSIZE];
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 old = open (a_name, O_RDONLY, 0);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 if (old < 0) fatal_unexec ("opening %s", a_name);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 new = creat (new_name, 0666);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 if (new < 0) fatal_unexec ("creating %s", new_name);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 hdr = *((struct headers *)TEXT_START);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 if (hdr.fhdr.f_magic != MIPSELMAGIC
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 && hdr.fhdr.f_magic != MIPSEBMAGIC)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 fprintf (stderr, "unexec: input file magic number is %x, not %x or %x.\n",
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 hdr.fhdr.f_magic, MIPSELMAGIC, MIPSEBMAGIC);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 exit (1);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 }
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 if (hdr.fhdr.f_opthdr != sizeof (hdr.aout))
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 fprintf (stderr, "unexec: input a.out header is %d bytes, not %d.\n",
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 hdr.fhdr.f_opthdr, sizeof (hdr.aout));
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 exit (1);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 }
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 if (hdr.aout.magic != ZMAGIC)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 fprintf (stderr, "unexec: input file a.out magic number is %o, not %o.\n",
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 hdr.aout.magic, ZMAGIC);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 exit (1);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 }
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 #define CHECK_SCNHDR(ptr, name, flags) \
1094
861c2997afee (unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents: 568
diff changeset
171 ptr = NULL; \
861c2997afee (unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents: 568
diff changeset
172 for (i = 0; i < hdr.fhdr.f_nscns && !ptr; i++) \
861c2997afee (unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents: 568
diff changeset
173 if (strcmp (hdr.section[i].s_name, name) == 0) \
861c2997afee (unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents: 568
diff changeset
174 { \
861c2997afee (unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents: 568
diff changeset
175 if (hdr.section[i].s_flags != flags) \
861c2997afee (unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents: 568
diff changeset
176 fprintf (stderr, "unexec: %x flags (%x expected) in %s section.\n", \
861c2997afee (unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents: 568
diff changeset
177 hdr.section[i].s_flags, flags, name); \
861c2997afee (unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents: 568
diff changeset
178 ptr = hdr.section + i; \
861c2997afee (unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents: 568
diff changeset
179 } \
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 CHECK_SCNHDR (text_section, _TEXT, STYP_TEXT);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 CHECK_SCNHDR (init_section, _INIT, STYP_INIT);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 CHECK_SCNHDR (rdata_section, _RDATA, STYP_RDATA);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 CHECK_SCNHDR (data_section, _DATA, STYP_DATA);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 #ifdef _LIT8
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 CHECK_SCNHDR (lit8_section, _LIT8, STYP_LIT8);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 CHECK_SCNHDR (lit4_section, _LIT4, STYP_LIT4);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 #endif /* _LIT8 */
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 CHECK_SCNHDR (sdata_section, _SDATA, STYP_SDATA);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 CHECK_SCNHDR (sbss_section, _SBSS, STYP_SBSS);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 CHECK_SCNHDR (bss_section, _BSS, STYP_BSS);
1486
1a12c5f1c04d [sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 1122
diff changeset
192 #if 0 /* Apparently this error check goes off on irix 3.3,
1a12c5f1c04d [sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 1122
diff changeset
193 but it doesn't indicate a real problem. */
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 if (i != hdr.fhdr.f_nscns)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 fprintf (stderr, "unexec: %d sections found instead of %d.\n",
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 i, hdr.fhdr.f_nscns);
1486
1a12c5f1c04d [sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 1122
diff changeset
197 #endif
1a12c5f1c04d [sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 1122
diff changeset
198
1a12c5f1c04d [sony, IRIS_4D]: Include getpagesize.h and fcntl.h.
Richard M. Stallman <rms@gnu.org>
parents: 1122
diff changeset
199 text_section->s_scnptr = 0;
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 pagesize = getpagesize ();
5969
999daf5b65b6 (unexec): Add cast to result of `sbrk'.
Richard M. Stallman <rms@gnu.org>
parents: 5521
diff changeset
202 /* Casting to int avoids compiler error on NEWS-OS 5.0.2. */
999daf5b65b6 (unexec): Add cast to result of `sbrk'.
Richard M. Stallman <rms@gnu.org>
parents: 5521
diff changeset
203 brk = (((int) (sbrk (0))) + pagesize - 1) & (-pagesize);
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 hdr.aout.dsize = brk - DATA_START;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 hdr.aout.bsize = 0;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 if (entry_address == 0)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 extern DEFAULT_ENTRY_ADDRESS ();
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 hdr.aout.entry = (unsigned)DEFAULT_ENTRY_ADDRESS;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 }
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 else
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 hdr.aout.entry = entry_address;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 hdr.aout.bss_start = hdr.aout.data_start + hdr.aout.dsize;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 rdata_section->s_size = data_start - DATA_START;
1094
861c2997afee (unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents: 568
diff changeset
216
861c2997afee (unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents: 568
diff changeset
217 /* Adjust start and virtual addresses of rdata_section, too. */
861c2997afee (unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents: 568
diff changeset
218 rdata_section->s_vaddr = DATA_START;
861c2997afee (unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents: 568
diff changeset
219 rdata_section->s_paddr = DATA_START;
861c2997afee (unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents: 568
diff changeset
220 rdata_section->s_scnptr = text_section->s_scnptr + hdr.aout.tsize;
861c2997afee (unexec): Allow sections in any order.
Richard M. Stallman <rms@gnu.org>
parents: 568
diff changeset
221
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 data_section->s_vaddr = data_start;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 data_section->s_paddr = data_start;
568
f4edd5fc98f6 entered into RCS
Jim Blandy <jimb@redhat.com>
parents: 486
diff changeset
224 data_section->s_size = brk - data_start;
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 data_section->s_scnptr = rdata_section->s_scnptr + rdata_section->s_size;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 vaddr = data_section->s_vaddr + data_section->s_size;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 scnptr = data_section->s_scnptr + data_section->s_size;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 if (lit8_section != NULL)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 lit8_section->s_vaddr = vaddr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 lit8_section->s_paddr = vaddr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 lit8_section->s_size = 0;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 lit8_section->s_scnptr = scnptr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 }
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 if (lit4_section != NULL)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 lit4_section->s_vaddr = vaddr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 lit4_section->s_paddr = vaddr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 lit4_section->s_size = 0;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 lit4_section->s_scnptr = scnptr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 }
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 if (sdata_section != NULL)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 sdata_section->s_vaddr = vaddr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 sdata_section->s_paddr = vaddr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 sdata_section->s_size = 0;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 sdata_section->s_scnptr = scnptr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 }
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 if (sbss_section != NULL)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 sbss_section->s_vaddr = vaddr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 sbss_section->s_paddr = vaddr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 sbss_section->s_size = 0;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 sbss_section->s_scnptr = scnptr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 }
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 if (bss_section != NULL)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 bss_section->s_vaddr = vaddr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 bss_section->s_paddr = vaddr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 bss_section->s_size = 0;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 bss_section->s_scnptr = scnptr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 }
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263
7151
1edd14fa94ae (unexec): Cast pointers. Fix error message.
Karl Heuer <kwzh@gnu.org>
parents: 5969
diff changeset
264 WRITE (new, (char *)TEXT_START, hdr.aout.tsize,
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 "writing text section to %s", new_name);
7151
1edd14fa94ae (unexec): Cast pointers. Fix error message.
Karl Heuer <kwzh@gnu.org>
parents: 5969
diff changeset
266 WRITE (new, (char *)DATA_START, hdr.aout.dsize,
1edd14fa94ae (unexec): Cast pointers. Fix error message.
Karl Heuer <kwzh@gnu.org>
parents: 5969
diff changeset
267 "writing data section to %s", new_name);
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 SEEK (old, hdr.fhdr.f_symptr, "seeking to start of symbols in %s", a_name);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 errno = EEOF;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 nread = read (old, buffer, BUFSIZE);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 if (nread < sizeof (HDRR)) fatal_unexec ("reading symbols from %s", a_name);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 newsyms = hdr.aout.tsize + hdr.aout.dsize;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 symrel = newsyms - hdr.fhdr.f_symptr;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 hdr.fhdr.f_symptr = newsyms;
12420
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
276 #define symhdr ((pHDRR)buffer)
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
277 #ifdef MACH
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
278 for (i = 0; i < 11; i++)
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
279 symhdr->offsets[i].offset += symrel;
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
280 #else
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 symhdr->cbLineOffset += symrel;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 symhdr->cbDnOffset += symrel;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 symhdr->cbPdOffset += symrel;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 symhdr->cbSymOffset += symrel;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 symhdr->cbOptOffset += symrel;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 symhdr->cbAuxOffset += symrel;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 symhdr->cbSsOffset += symrel;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 symhdr->cbSsExtOffset += symrel;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 symhdr->cbFdOffset += symrel;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 symhdr->cbRfdOffset += symrel;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 symhdr->cbExtOffset += symrel;
12420
0c728a1b2bed [MACH]: Include a.out.h.
Richard M. Stallman <rms@gnu.org>
parents: 7151
diff changeset
292 #endif
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 #undef symhdr
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 do
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 if (write (new, buffer, nread) != nread)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 fatal_unexec ("writing symbols to %s", new_name);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 nread = read (old, buffer, BUFSIZE);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 if (nread < 0) fatal_unexec ("reading symbols from %s", a_name);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 #undef BUFSIZE
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 } while (nread != 0);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 SEEK (new, 0, "seeking to start of header in %s", new_name);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 WRITE (new, &hdr, sizeof (hdr),
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 "writing header of %s", new_name);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 close (old);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 close (new);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 mark_x (new_name);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 }
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 /*
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 * mark_x
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 *
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 1486
diff changeset
315 * After successfully building the new a.out, mark it executable
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 */
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317
1122
42922d56e5a6 * unexmips.c (mark_x): Declare this as static void at the top of
Jim Blandy <jimb@redhat.com>
parents: 1094
diff changeset
318 static void
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 mark_x (name)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 char *name;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 struct stat sbuf;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 int um = umask (777);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 umask (um);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 if (stat (name, &sbuf) < 0)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 fatal_unexec ("getting protection on %s", name);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 sbuf.st_mode |= 0111 & ~um;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 if (chmod (name, sbuf.st_mode) < 0)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 fatal_unexec ("setting protection on %s", name);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 }
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 static void
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 fatal_unexec (s, va_alist)
5521
d1d144ed5b76 Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents: 4696
diff changeset
334 va_dcl
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 {
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 va_list ap;
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 if (errno == EEOF)
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 fputs ("unexec: unexpected end of file, ", stderr);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 else
5521
d1d144ed5b76 Don't declare sys_errlist; declare strerror instead.
Roland McGrath <roland@gnu.org>
parents: 4696
diff changeset
340 fprintf (stderr, "unexec: %s, ", strerror (errno));
486
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 va_start (ap);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 _doprnt (s, ap, stderr);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 fputs (".\n", stderr);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 exit (1);
80cdb2387043 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 }
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 14186
diff changeset
346
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 14186
diff changeset
347 /* arch-tag: ebdd2058-3bbc-4de4-b5c7-5760379ab153
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 14186
diff changeset
348 (do not change this comment) */