/* Unexec for Sunos 4 using shared libraries.
- Copyright (C) 1990, 1994 Free Software Foundation, Inc.
+ Copyright (C) 1990, 1994, 1999, 2002, 2003, 2004,
+ 2005, 2006 Free Software Foundation, Inc.
This file is part of GNU Emacs.
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. */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
/* Contributed by Viktor Dukhovni. */
/*
* is somewhat abused here) is loaded first!
*
*/
+
+#ifdef emacs
+#include <config.h>
+#endif
+
#include <sys/param.h>
#include <sys/mman.h>
#include <sys/file.h>
#include <stdio.h>
#include <a.out.h>
-/* Do this after the above #include's in case a configuration file wants
- to define things for this file based on what <a.out.h> defines. */
-#ifdef emacs
-#include <config.h>
-#endif
-
-#if defined (SUNOS4) || defined (__FreeBSD__)
+#if defined (SUNOS4) || defined (__FreeBSD__) || defined (__NetBSD__)
#define UNDO_RELOCATION
#endif
#endif
extern char *getenv ();
-static unsigned Brk;
+static unsigned brk_value;
static struct exec nhdr;
static int rd_only_len;
static long cookie;
-unexec (new_name, a_name, bndry, bss_start, entry)
+unexec (new_name, a_name, bndry, bss_start, entry)
char *new_name, *a_name;
unsigned bndry, bss_start, entry;
{
struct exec ohdr; /* Allocate on the stack, not needed in the next life */
struct stat stat;
-#ifdef emacs
- fprintf (stderr, "Used %d bytes of Pure Storage\n", pureptr);
-#endif
-
if ((fd = open (a_name, O_RDONLY)) < 0)
{
fprintf (stderr, "%s: open: ", a_name);
*/
cookie = time (0);
- Brk = sbrk (0); /* Save the break, it is reset to &_end (by ld.so?) */
+ /* Save the break, it is reset to &_end (by ld.so?). */
+ brk_value = (unsigned) sbrk (0);
/*
* Round up data start to a page boundary (Lose if not a 2 power!)
/* Have to do this some time before dumping the data */
initialized = 1;
#endif
-
- /*
- * Handle new data and bss sizes and optional new entry point.
- * No one actually uses bss_start and entry, but tradition compels
- * one to support them.
- * Could complain if bss_start > Brk, but the caller is *supposed* to know
- * what she is doing.
- */
- nhdr.a_data = (bss_start ? bss_start : Brk) - N_DATADDR (nhdr);
- nhdr.a_bss = bss_start ? Brk - bss_start : 0;
- if (entry)
+
+ /* Handle new data and bss sizes and optional new entry point.
+ No one actually uses bss_start and entry, but tradition compels
+ one to support them.
+ Could complain if bss_start > brk_value,
+ but the caller is *supposed* to know what she is doing. */
+ nhdr.a_data = (bss_start ? bss_start : brk_value) - N_DATADDR (nhdr);
+ nhdr.a_bss = bss_start ? brk_value - bss_start : 0;
+ if (entry)
nhdr.a_entry = entry;
/*
unsigned long daddr = N_DATADDR (ohdr);
unsigned long rel, erel;
#ifdef SUNOS4
+#ifdef SUNOS4_SHARED_LIBRARIES
extern struct link_dynamic _DYNAMIC;
/* SunOS4.x's ld_rel is relative to N_TXTADDR. */
- if (_DYNAMIC.ld_version < 2)
+ if (!ohdr.a_dynamic)
+ /* This was statically linked. */
+ rel = erel = 0;
+ else if (_DYNAMIC.ld_version < 2)
{
rel = _DYNAMIC.ld_un.ld_1->ld_rel + N_TXTADDR (ohdr);
erel = _DYNAMIC.ld_un.ld_1->ld_hash + N_TXTADDR (ohdr);
rel = _DYNAMIC.ld_un.ld_2->ld_rel + N_TXTADDR (ohdr);
erel = _DYNAMIC.ld_un.ld_2->ld_hash + N_TXTADDR (ohdr);
}
+#else /* not SUNOS4_SHARED_LIBRARIES */
+ rel = erel = 0;
+#endif /* not SUNOS4_SHARED_LIBRARIES */
#ifdef sparc
#define REL_INFO_TYPE struct reloc_info_sparc
#else
-#define REL_INFO_TYPE struct reloc_info_m68k
+#define REL_INFO_TYPE struct relocation_info
#endif /* sparc */
#define REL_TARGET_ADDRESS(r) (((REL_INFO_TYPE *)(r))->r_address)
#endif /* SUNOS4 */
-#ifdef __FreeBSD__
+#if defined (__FreeBSD__) || defined (__NetBSD__)
extern struct _dynamic _DYNAMIC;
/* FreeBSD's LD_REL is a virtual address itself. */
return;
/* Restore the break */
- brk (Brk);
+ brk ((char *) brk_value);
/* If nothing to remap: we are done! */
if (rd_only_len == 0)
* First try argv[0], will almost always succeed as shells tend to give
* the full path from the hash list rather than using execvp ()
*/
- if (is_it (progname))
+ if (is_it (progname))
return;
/*
* If argv[0] is a full path and does not exist, not much sense in
* searching further
*/
- if (strchr (progname, '/'))
+ if (strchr (progname, '/'))
return;
/*
* should the shared library decide to indirect through
* addresses in the data segment not part of __DYNAMIC
*/
- mmap (data_start, rd_only_len, PROT_READ | PROT_EXEC,
+ mmap ((char *) data_start, rd_only_len, PROT_READ | PROT_EXEC,
MAP_FILE | MAP_SHARED | MAP_FIXED, fd,
N_DATOFF (hdr) + data_start - N_DATADDR (hdr));
close (fd);
}
return 0;
}
+
+/* arch-tag: 30227420-2c6f-4700-a4f8-9e45e52f53b1
+ (do not change this comment) */