annotate src/unexmips.c @ 844:047d37eb70d7

[xemacs-hg @ 2002-05-16 13:30:23 by ben] ui fixes for things that were bothering me bytecode.c, editfns.c, lisp.h, lread.c: Fix save-restriction to use markers rather than pseudo-markers (integers representing the amount of text on either side of the region). That way, all inserts are handled correctly, not just those inside old restriction. Add buffer argument to save_restriction_save(). process.c: Clean up very dirty and kludgy code that outputs into a buffer -- use proper unwind protects, etc. font-lock.c: Do save-restriction/widen around the function -- otherwise, incorrect results will ensue when a buffer has been narrowed before a call to e.g. `buffer-syntactic-context' -- something that happens quite often. fileio.c: Look for a handler for make-temp-name. window.c, winslots.h: Try to solve this annoying problem: have two frames displaying the buffer, in different places; in one, temporarily switch away to another buffer and then back -- and you've lost your position; it's reset to the other one in the other frame. My current solution involves window-level caches of buffers and points (also a cache for window-start); when set-window-buffer is called, it looks to see if the buffer was previously visited in the window, and if so, uses the most recent point at that time. (It's a marker, so it handles changes.) #### Note: It could be argued that doing it on the frame level would be better -- e.g. if you visit a buffer temporarily through a grep, and then go back to that buffer, you presumably want the grep's position rather than some previous position provided everything was in the same frame, even though the grep was in another window in the frame. However, doing it on the frame level fails when you have two windows on the same frame. Perhaps we keep both a window and a frame cache, and use the frame cache if there are no other windows on the frame showing the buffer, else the window's cache? This is probably something to be configurable using a specifier. Suggestions please please please? window.c: Clean up a bit code that deals with the annoyance of window-point vs. point. dialog.el: Function to ask a multiple-choice question, automatically choosing a dialog box or minibuffer representation as necessary. Generalized version of yes-or-no-p, y-or-n-p. files.el: Use get-user-response to ask "yes/no/diff" question when recovering. "diff" means that a diff is displayed between the current file and the autosave. (Converts/deconverts escape-quoted as necessary. No more complaints from you, Mr. Turnbull!) One known problem: when a dialog is used, it's modal, so you can't scroll the diff. Will fix soon. lisp-mode.el: If we're filling a string, don't treat semicolon as a comment, which would give very unfriendly results. Uses `buffer-syntactic-context'. simple.el: all changes back to the beginning. (Useful if you've saved the file in the middle of the changes.) simple.el: Add option kill-word-into-kill-ring, which controls whether words deleted with kill-word, backward-kill-word, etc. are "cut" into the kill ring, or "cleared" into nothingness. (My preference is the latter, by far. I'd almost go so far as suggesting we make it the default, as you can always select a word and then cut it if you want it cut.) menubar-items.el: Add option corresponding to kill-word-into-kill-ring.
author ben
date Thu, 16 May 2002 13:30:58 +0000
parents 74fd4e045ea6
children 697ef44129c6 04bc9d2f42c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Unexec for MIPS (including IRIS4D).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1988, 1992, 1993, 1994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: FSF 19.31. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #include <sys/file.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include <sys/stat.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include <stdio.h>
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 0
diff changeset
29 #include <errno.h>
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #include <varargs.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #ifdef MACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #include <a.out.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 /* I don't know why this isn't defined. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 #ifndef STYP_INIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #define STYP_INIT 0x80000000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 /* I don't know why this isn't defined. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #ifndef _RDATA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #define _RDATA ".rdata"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #define STYP_RDATA 0x00000100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 /* Small ("near") data section. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 #ifndef _SDATA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #define _SDATA ".sdata"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #define STYP_SDATA 0x00000200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 /* Small ("near") bss section. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 #ifndef _SBSS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 #define _SBSS ".sbss"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 #define STYP_SBSS 0x00000400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 /* We don't seem to have a sym.h or syms.h anywhere, so we'll do it the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 hard way. This stinks. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 typedef struct {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 short magic;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 short vstamp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 long ilineMax;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 struct { long foo, offset; } offsets[11];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 } HDRR, *pHDRR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 #else /* not MACH */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 #include <filehdr.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 #include <aouthdr.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 #include <scnhdr.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 #include <sym.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 #endif /* not MACH */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 #if defined (IRIS_4D) || defined (sony)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 #include "getpagesize.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 #include <fcntl.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 static void fatal_unexec ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 static void mark_x ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 #define READ(_fd, _buffer, _size, _error_message, _error_arg) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 errno = EEOF; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 if (read (_fd, _buffer, _size) != _size) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 fatal_unexec (_error_message, _error_arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 #define WRITE(_fd, _buffer, _size, _error_message, _error_arg) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 if (write (_fd, _buffer, _size) != _size) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 fatal_unexec (_error_message, _error_arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 #define SEEK(_fd, _position, _error_message, _error_arg) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 errno = EEOF; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 if (lseek (_fd, _position, L_SET) != _position) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 fatal_unexec (_error_message, _error_arg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 extern char *strerror ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 #define EEOF -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 static struct scnhdr *text_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 static struct scnhdr *init_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 static struct scnhdr *finit_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 static struct scnhdr *rdata_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 static struct scnhdr *data_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 static struct scnhdr *lit8_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 static struct scnhdr *lit4_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 static struct scnhdr *sdata_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 static struct scnhdr *sbss_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 static struct scnhdr *bss_section;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 struct headers {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 struct filehdr fhdr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 struct aouthdr aout;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 struct scnhdr section[10];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 /* Define name of label for entry point for the dumped executable. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 #ifndef DEFAULT_ENTRY_ADDRESS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 #define DEFAULT_ENTRY_ADDRESS __start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 unexec (new_name, a_name, data_start, bss_start, entry_address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 char *new_name, *a_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 unsigned data_start, bss_start, entry_address;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 int new, old;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 int pagesize, brk;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 int newsyms, symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 int nread;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 struct headers hdr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 int vaddr, scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 #define BUFSIZE 8192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 char buffer[BUFSIZE];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 old = open (a_name, O_RDONLY, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 if (old < 0) fatal_unexec ("opening %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 new = creat (new_name, 0666);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 if (new < 0) fatal_unexec ("creating %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 hdr = *((struct headers *)TEXT_START);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 #ifdef MIPS2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 if (hdr.fhdr.f_magic != MIPSELMAGIC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 && hdr.fhdr.f_magic != MIPSEBMAGIC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 && hdr.fhdr.f_magic != (MIPSELMAGIC | 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 && hdr.fhdr.f_magic != (MIPSEBMAGIC | 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 fprintf (stderr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 "unexec: input file magic number is %x, not %x, %x, %x or %x.\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 hdr.fhdr.f_magic,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 MIPSELMAGIC, MIPSEBMAGIC,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 MIPSELMAGIC | 1, MIPSEBMAGIC | 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 #else /* not MIPS2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 if (hdr.fhdr.f_magic != MIPSELMAGIC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 && hdr.fhdr.f_magic != MIPSEBMAGIC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 fprintf (stderr, "unexec: input file magic number is %x, not %x or %x.\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 hdr.fhdr.f_magic, MIPSELMAGIC, MIPSEBMAGIC);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 #endif /* not MIPS2 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 if (hdr.fhdr.f_opthdr != sizeof (hdr.aout))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 fprintf (stderr, "unexec: input a.out header is %d bytes, not %d.\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 hdr.fhdr.f_opthdr, sizeof (hdr.aout));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 if (hdr.aout.magic != ZMAGIC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 fprintf (stderr, "unexec: input file a.out magic number is %o, not %o.\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 hdr.aout.magic, ZMAGIC);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 #define CHECK_SCNHDR(ptr, name, flags) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ptr = NULL; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 for (i = 0; i < hdr.fhdr.f_nscns && !ptr; i++) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 if (strcmp (hdr.section[i].s_name, name) == 0) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 if (hdr.section[i].s_flags != flags) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 fprintf (stderr, "unexec: %x flags (%x expected) in %s section.\n", \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 hdr.section[i].s_flags, flags, name); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ptr = hdr.section + i; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 CHECK_SCNHDR (text_section, _TEXT, STYP_TEXT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 CHECK_SCNHDR (init_section, _INIT, STYP_INIT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 CHECK_SCNHDR (rdata_section, _RDATA, STYP_RDATA);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 CHECK_SCNHDR (data_section, _DATA, STYP_DATA);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 #ifdef _LIT8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 CHECK_SCNHDR (lit8_section, _LIT8, STYP_LIT8);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 CHECK_SCNHDR (lit4_section, _LIT4, STYP_LIT4);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 #endif /* _LIT8 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 CHECK_SCNHDR (sdata_section, _SDATA, STYP_SDATA);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 CHECK_SCNHDR (sbss_section, _SBSS, STYP_SBSS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 CHECK_SCNHDR (bss_section, _BSS, STYP_BSS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 #if 0 /* Apparently this error check goes off on irix 3.3,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 but it doesn't indicate a real problem. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 if (i != hdr.fhdr.f_nscns)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 fprintf (stderr, "unexec: %d sections found instead of %d.\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 i, hdr.fhdr.f_nscns);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 text_section->s_scnptr = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 pagesize = getpagesize ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 /* Casting to int avoids compiler error on NEWS-OS 5.0.2. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 brk = (((int) (sbrk (0))) + pagesize - 1) & (-pagesize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 hdr.aout.dsize = brk - DATA_START;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 hdr.aout.bsize = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 if (entry_address == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 extern DEFAULT_ENTRY_ADDRESS ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 hdr.aout.entry = (unsigned)DEFAULT_ENTRY_ADDRESS;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 hdr.aout.entry = entry_address;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 hdr.aout.bss_start = hdr.aout.data_start + hdr.aout.dsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 rdata_section->s_size = data_start - DATA_START;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 /* Adjust start and virtual addresses of rdata_section, too. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 rdata_section->s_vaddr = DATA_START;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 rdata_section->s_paddr = DATA_START;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 rdata_section->s_scnptr = text_section->s_scnptr + hdr.aout.tsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 data_section->s_vaddr = data_start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 data_section->s_paddr = data_start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 data_section->s_size = brk - data_start;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 data_section->s_scnptr = rdata_section->s_scnptr + rdata_section->s_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 vaddr = data_section->s_vaddr + data_section->s_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 scnptr = data_section->s_scnptr + data_section->s_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 if (lit8_section != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 lit8_section->s_vaddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 lit8_section->s_paddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 lit8_section->s_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 lit8_section->s_scnptr = scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 if (lit4_section != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 lit4_section->s_vaddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 lit4_section->s_paddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 lit4_section->s_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 lit4_section->s_scnptr = scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 if (sdata_section != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 sdata_section->s_vaddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 sdata_section->s_paddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 sdata_section->s_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 sdata_section->s_scnptr = scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 if (sbss_section != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 sbss_section->s_vaddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 sbss_section->s_paddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 sbss_section->s_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 sbss_section->s_scnptr = scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 if (bss_section != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 bss_section->s_vaddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 bss_section->s_paddr = vaddr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 bss_section->s_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 bss_section->s_scnptr = scnptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 WRITE (new, (void *) TEXT_START, hdr.aout.tsize,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 "writing text section to %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 WRITE (new, (void *) DATA_START, hdr.aout.dsize,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 "writing data section to %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 SEEK (old, hdr.fhdr.f_symptr, "seeking to start of symbols in %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 errno = EEOF;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 nread = read (old, buffer, BUFSIZE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 if (nread < sizeof (HDRR)) fatal_unexec ("reading symbols from %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 newsyms = hdr.aout.tsize + hdr.aout.dsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 symrel = newsyms - hdr.fhdr.f_symptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 hdr.fhdr.f_symptr = newsyms;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 #define symhdr ((pHDRR)buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 #ifdef MACH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 for (i = 0; i < 11; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 symhdr->offsets[i].offset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 symhdr->cbLineOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 symhdr->cbDnOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 symhdr->cbPdOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 symhdr->cbSymOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 symhdr->cbOptOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 symhdr->cbAuxOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 symhdr->cbSsOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 symhdr->cbSsExtOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 symhdr->cbFdOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 symhdr->cbRfdOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 symhdr->cbExtOffset += symrel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 #undef symhdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 if (write (new, buffer, nread) != nread)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 fatal_unexec ("writing symbols to %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 nread = read (old, buffer, BUFSIZE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 if (nread < 0) fatal_unexec ("reading symbols from %s", a_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 #undef BUFSIZE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 } while (nread != 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 SEEK (new, 0, "seeking to start of header in %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 WRITE (new, &hdr, sizeof (hdr),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 "writing header of %s", new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 close (old);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 close (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 mark_x (new_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 * mark_x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 * After successfully building the new a.out, mark it executable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 mark_x (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 char *name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 struct stat sbuf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 int um = umask (777);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 umask (um);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 if (stat (name, &sbuf) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 fatal_unexec ("getting protection on %s", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 sbuf.st_mode |= 0111 & ~um;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 if (chmod (name, sbuf.st_mode) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 fatal_unexec ("setting protection on %s", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 fatal_unexec (s, va_alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 va_dcl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 va_list ap;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 if (errno == EEOF)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 fputs ("unexec: unexpected end of file, ", stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 fprintf (stderr, "unexec: %s, ", strerror (errno));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 va_start (ap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 _doprnt (s, ap, stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 fputs (".\n", stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 }