summaryrefslogtreecommitdiff
path: root/src/unexec.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/unexec.c')
-rw-r--r--src/unexec.c107
1 files changed, 52 insertions, 55 deletions
diff --git a/src/unexec.c b/src/unexec.c
index ccd67451203..eeae9c6a229 100644
--- a/src/unexec.c
+++ b/src/unexec.c
@@ -1,20 +1,22 @@
/* Copyright (C) 1985, 1986, 1987, 1988 Free Software Foundation, Inc.
-This file is part of GNU Emacs.
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 1, or (at your option)
+ any later version.
-GNU Emacs is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 1, or (at your option)
-any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
-GNU Emacs is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING. If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+In other words, you are welcome to use, share and improve this program.
+You are forbidden to forbid anyone else to use, share and improve
+what you give them. Help stamp out software-hoarding! */
/*
@@ -156,7 +158,6 @@ pointer looks like an int) but not on all machines.
#ifndef emacs
#define PERROR(arg) perror (arg); return -1
#else
-#define IN_UNEXEC
#include "config.h"
#define PERROR(file) report_error (file, new)
#endif
@@ -181,7 +182,24 @@ pointer looks like an int) but not on all machines.
extern char *start_of_text (); /* Start of text */
extern char *start_of_data (); /* Start of initialized data */
+static int make_hdr (), copy_text_and_data (), copy_sym ();
+static int mark_x ();
+
#ifdef COFF
+#ifndef USG
+#ifndef STRIDE
+#ifndef UMAX
+#ifndef sun386
+/* I have a suspicion that these are turned off on all systems
+ and can be deleted. Try it in version 19. */
+#include <filehdr.h>
+#include <aouthdr.h>
+#include <scnhdr.h>
+#include <syms.h>
+#endif /* not sun386 */
+#endif /* not UMAX */
+#endif /* Not STRIDE */
+#endif /* not USG */
static long block_copy_start; /* Old executable start point */
static struct filehdr f_hdr; /* File header */
static struct aouthdr f_ohdr; /* Optional file header (a.out) */
@@ -194,8 +212,6 @@ static long data_scnptr;
#else /* not COFF */
-extern char *sbrk ();
-
#define SYMS_START ((long) N_SYMOFF (ohdr))
/* Some machines override the structure name for an a.out header. */
@@ -218,7 +234,9 @@ static EXEC_HDR_TYPE hdr, ohdr;
#else /* not HPUX */
-#if defined (USG) && !defined (IBMAIX) && !defined (IRIS)
+extern char *sbrk ();
+
+#if defined (USG) && !defined (IBMRTAIX) && !defined (IRIS)
static struct bhdr hdr, ohdr;
#define a_magic fmagic
#define a_text tsize
@@ -232,10 +250,10 @@ static struct bhdr hdr, ohdr;
(((x).fmagic)!=OMAGIC && ((x).fmagic)!=NMAGIC &&\
((x).fmagic)!=FMAGIC && ((x).fmagic)!=IMAGIC)
#define NEWMAGIC FMAGIC
-#else /* IRIS or IBMAIX or not USG */
+#else /* IRIS or IBMRTAIX or not USG */
static EXEC_HDR_TYPE hdr, ohdr;
#define NEWMAGIC ZMAGIC
-#endif /* IRIS or IBMAIX not USG */
+#endif /* IRIS or IBMRTAIX not USG */
#endif /* not HPUX */
static int unexec_text_start;
@@ -262,7 +280,7 @@ report_error (file, fd)
{
if (fd)
close (fd);
- error ("Failure operating on %s\n", file);
+ error ("Failure operating on %s", file);
}
#endif /* emacs */
@@ -285,11 +303,6 @@ report_error_1 (fd, msg, a1, a2)
#endif
}
-static int make_hdr ();
-static int copy_text_and_data ();
-static int copy_sym ();
-static void mark_x ();
-
/* ****************************************************************
* unexec
*
@@ -314,10 +327,8 @@ unexec (new_name, a_name, data_start, bss_start, entry_address)
|| copy_text_and_data (new, a_out) < 0
|| copy_sym (new, a_out, a_name, new_name) < 0
#ifdef COFF
-#ifndef COFF_BSD_SYMBOLS
|| adjust_lnnoptrs (new, a_out, new_name) < 0
#endif
-#endif
)
{
close (new);
@@ -328,8 +339,7 @@ unexec (new_name, a_name, data_start, bss_start, entry_address)
close (new);
if (a_out >= 0)
close (a_out);
- mark_x (new_name);
- return 0;
+ return mark_x (new_name);
}
/* ****************************************************************
@@ -475,17 +485,9 @@ make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name)
#endif /* NO_REMAP */
f_ohdr.dsize = bss_start - f_ohdr.data_start;
f_ohdr.bsize = bss_end - bss_start;
-#ifndef KEEP_OLD_TEXT_SCNPTR
- /* On some machines, the old values are right.
- ??? Maybe on all machines with NO_REMAP. */
f_thdr.s_size = f_ohdr.tsize;
f_thdr.s_scnptr = sizeof (f_hdr) + sizeof (f_ohdr);
f_thdr.s_scnptr += (f_hdr.f_nscns) * (sizeof (f_thdr));
-#endif /* KEEP_OLD_TEXT_SCNPTR */
-#ifdef ADJUST_TEXT_SCNHDR_SIZE
- /* On some machines, `text size' includes all headers. */
- f_thdr.s_size -= f_thdr.s_scnptr;
-#endif /* ADJUST_TEST_SCNHDR_SIZE */
lnnoptr = f_thdr.s_lnnoptr;
#ifdef SECTION_ALIGNMENT
/* Some systems require special alignment
@@ -497,12 +499,7 @@ make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name)
f_thdr.s_scnptr = 0xd0;
#endif
text_scnptr = f_thdr.s_scnptr;
-#ifdef ADJUST_TEXTBASE
- text_scnptr = sizeof (f_hdr) + sizeof (f_ohdr) + (f_hdr.f_nscns) * (sizeof (f_thdr));
-#endif
-#ifndef KEEP_OLD_PADDR
f_dhdr.s_paddr = f_ohdr.data_start;
-#endif /* KEEP_OLD_PADDR */
f_dhdr.s_vaddr = f_ohdr.data_start;
f_dhdr.s_size = f_ohdr.dsize;
f_dhdr.s_scnptr = f_thdr.s_scnptr + f_thdr.s_size;
@@ -519,9 +516,7 @@ make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name)
= (f_dhdr.s_scnptr + DATA_SECTION_ALIGNMENT) & ~DATA_SECTION_ALIGNMENT;
#endif /* DATA_SECTION_ALIGNMENT */
data_scnptr = f_dhdr.s_scnptr;
-#ifndef KEEP_OLD_PADDR
f_bhdr.s_paddr = f_ohdr.data_start + f_ohdr.dsize;
-#endif /* KEEP_OLD_PADDR */
f_bhdr.s_vaddr = f_ohdr.data_start + f_ohdr.dsize;
f_bhdr.s_size = f_ohdr.bsize;
f_bhdr.s_scnptr = 0L;
@@ -540,7 +535,7 @@ make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name)
}
#ifdef ADJUST_EXEC_HEADER
- ADJUST_EXEC_HEADER;
+ ADJUST_EXEC_HEADER
#endif /* ADJUST_EXEC_HEADER */
if (write (new, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr))
@@ -753,10 +748,6 @@ copy_text_and_data (new, a_out)
lseek (new, (long) text_scnptr, 0);
ptr = (char *) f_ohdr.text_start;
-#ifdef HEADER_INCL_IN_TEXT
- /* For Gould UTX/32, text starts after headers */
- ptr = (char *) (ptr + text_scnptr);
-#endif /* HEADER_INCL_IN_TEXT */
end = ptr + f_ohdr.tsize;
write_segment (new, ptr, end);
@@ -780,7 +771,15 @@ copy_text_and_data (new, a_out)
#ifdef A_TEXT_SEEK
lseek (new, (long) A_TEXT_SEEK (hdr), 0);
#else
+#ifdef A_TEXT_OFFSET
+ /* Note that on the Sequent machine A_TEXT_OFFSET != sizeof (hdr)
+ and sizeof (hdr) is the correct amount to add here. */
+ /* In version 19, eliminate this case and use A_TEXT_SEEK whenever
+ N_TXTOFF is not right. */
+ lseek (new, (long) N_TXTOFF (hdr) + sizeof (hdr), 0);
+#else
lseek (new, (long) N_TXTOFF (hdr), 0);
+#endif /* no A_TEXT_OFFSET */
#endif /* no A_TEXT_SEEK */
ptr = (char *) unexec_text_start;
@@ -883,7 +882,7 @@ copy_sym (new, a_out, a_name, new_name)
*
* After succesfully building the new a.out, mark it executable
*/
-static void
+static int
mark_x (name)
char *name;
{
@@ -900,11 +899,9 @@ mark_x (name)
sbuf.st_mode |= 0111 & ~um;
if (chmod (name, sbuf.st_mode) == -1)
PERROR (name);
+ return 0;
}
-#ifdef COFF
-#ifndef COFF_BSD_SYMBOLS
-
/*
* If the COFF file contains a symbol table and a line number section,
* then any auxiliary entries that have values for x_lnnoptr must
@@ -920,6 +917,8 @@ mark_x (name)
* will complain. Fred Fish, UniSoft Systems Inc.
*/
+#ifdef COFF
+
/* This function is probably very slow. Instead of reopening the new
file for input and output it should copy from the old to the new
using the two descriptors already open (WRITEDESC and READDESC).
@@ -934,7 +933,7 @@ adjust_lnnoptrs (writedesc, readdesc, new_name)
{
register int nsyms;
register int new;
-#ifdef amdahl_uts
+#if defined (amdahl_uts) || defined (pfa)
SYMENT symentry;
AUXENT auxentry;
#else
@@ -969,8 +968,6 @@ adjust_lnnoptrs (writedesc, readdesc, new_name)
close (new);
}
-#endif /* COFF_BSD_SYMBOLS */
-
#endif /* COFF */
#endif /* not CANNOT_UNEXEC */