[SQUASH] symbol
[bpt/emacs.git] / src / unexaix.c
index a3ffd50..c97d5ca 100644 (file)
@@ -1,5 +1,5 @@
 /* Dump an executable image.
-   Copyright (C) 1985-1988, 1999, 2001-2013 Free Software Foundation,
+   Copyright (C) 1985-1988, 1999, 2001-2014 Free Software Foundation,
    Inc.
 
 This file is part of GNU Emacs.
@@ -42,6 +42,7 @@ what you give them.   Help stamp out software-hoarding!  */
 
 #include <config.h>
 #include "unexec.h"
+#include "lisp.h"
 
 #define PERROR(file) report_error (file, new)
 #include <a.out.h>
@@ -59,12 +60,8 @@ what you give them.   Help stamp out software-hoarding!  */
 #include <unistd.h>
 #include <fcntl.h>
 
-#include "mem-limits.h"
-
-char *start_of_text (void);                    /* Start of text */
-
-extern int _data;
-extern int _text;
+extern char _data[];
+extern char _text[];
 
 #include <filehdr.h>
 #include <aouthdr.h>
@@ -73,15 +70,15 @@ extern int _text;
 
 static struct filehdr f_hdr;           /* File header */
 static struct aouthdr f_ohdr;          /* Optional file header (a.out) */
-static long bias;                      /* Bias to add for growth */
-static long lnnoptr;                   /* Pointer to line-number info within file */
+static off_t bias;                     /* Bias to add for growth */
+static off_t lnnoptr;                  /* Pointer to line-number info within file */
 
-static long text_scnptr;
-static long data_scnptr;
+static off_t text_scnptr;
+static off_t data_scnptr;
 #define ALIGN(val, pwr) (((val) + ((1L<<(pwr))-1)) & ~((1L<<(pwr))-1))
-static long load_scnptr;
-static long orig_load_scnptr;
-static long orig_data_scnptr;
+static off_t load_scnptr;
+static off_t orig_load_scnptr;
+static off_t orig_data_scnptr;
 static int unrelocate_symbols (int, int, const char *, const char *);
 
 #ifndef MAX_SECTIONS
@@ -97,13 +94,10 @@ static int pagemask;
 static _Noreturn void
 report_error (const char *file, int fd)
 {
+  int err = errno;
   if (fd)
-    {
-      int failed_errno = errno;
-      close (fd);
-      errno = failed_errno;
-    }
-  report_file_error ("Cannot unexec", Fcons (build_string (file), Qnil));
+    emacs_close (fd);
+  report_file_errno ("Cannot unexec", build_string (file), err);
 }
 
 #define ERROR0(msg) report_error_1 (new, msg)
@@ -114,7 +108,7 @@ static _Noreturn void ATTRIBUTE_FORMAT_PRINTF (2, 3)
 report_error_1 (int fd, const char *msg, ...)
 {
   va_list ap;
-  close (fd);
+  emacs_close (fd);
   va_start (ap, msg);
   verror (msg, ap);
   va_end (ap);
@@ -136,11 +130,11 @@ unexec (const char *new_name, const char *a_name)
 {
   int new = -1, a_out = -1;
 
-  if (a_name && (a_out = open (a_name, O_RDONLY)) < 0)
+  if (a_name && (a_out = emacs_open (a_name, O_RDONLY, 0)) < 0)
     {
       PERROR (a_name);
     }
-  if ((new = creat (new_name, 0666)) < 0)
+  if ((new = emacs_open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
     {
       PERROR (new_name);
     }
@@ -151,13 +145,13 @@ unexec (const char *new_name, const char *a_name)
       || adjust_lnnoptrs (new, a_out, new_name) < 0
       || unrelocate_symbols (new, a_out, a_name, new_name) < 0)
     {
-      close (new);
+      emacs_close (new);
       return;
     }
 
-  close (new);
+  emacs_close (new);
   if (a_out >= 0)
-    close (a_out);
+    emacs_close (a_out);
   mark_x (new_name);
 }
 
@@ -188,7 +182,7 @@ make_hdr (int new, int a_out,
   pagemask = getpagesize () - 1;
 
   /* Adjust text/data boundary. */
-  data_start = (uintptr_t) start_of_data ();
+  data_start = (uintptr_t) _data;
 
   data_start = data_start & ~pagemask; /* (Down) to page boundary. */
 
@@ -288,7 +282,7 @@ make_hdr (int new, int a_out,
 
   /* fix scnptr's */
   {
-    ulong ptr = section[0].s_scnptr;
+    off_t ptr = section[0].s_scnptr;
 
     bias = -1;
     for (scns = 0; scns < f_hdr.f_nscns; scns++)
@@ -384,12 +378,12 @@ copy_text_and_data (int new)
   char *end;
   char *ptr;
 
-  lseek (new, (long) text_scnptr, SEEK_SET);
-  ptr = start_of_text () + text_scnptr;
+  lseek (new, text_scnptr, SEEK_SET);
+  ptr = _text;
   end = ptr + f_ohdr.tsize;
   write_segment (new, ptr, end);
 
-  lseek (new, (long) data_scnptr, SEEK_SET);
+  lseek (new, data_scnptr, SEEK_SET);
   ptr = (char *) f_ohdr.data_start;
   end = ptr + f_ohdr.dsize;
   write_segment (new, ptr, end);
@@ -507,7 +501,7 @@ adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name)
   if (!lnnoptr || !f_hdr.f_symptr)
     return 0;
 
-  if ((new = open (new_name, O_RDWR)) < 0)
+  if ((new = emacs_open (new_name, O_RDWR, 0)) < 0)
     {
       PERROR (new_name);
       return -1;
@@ -537,7 +531,7 @@ adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name)
             }
        }
     }
-  close (new);
+  emacs_close (new);
 
   return 0;
 }
@@ -549,13 +543,13 @@ unrelocate_symbols (int new, int a_out,
   int i;
   LDHDR ldhdr;
   LDREL ldrel;
-  ulong t_reloc = (ulong) &_text - f_ohdr.text_start;
+  off_t t_reloc = (intptr_t) _text - f_ohdr.text_start;
 #ifndef ALIGN_DATA_RELOC
-  ulong d_reloc = (ulong) &_data - f_ohdr.data_start;
+  off_t d_reloc = (intptr_t) _data - f_ohdr.data_start;
 #else
   /* This worked (and was needed) before AIX 4.2.
      I have no idea why. -- Mike */
-  ulong d_reloc = (ulong) &_data - ALIGN (f_ohdr.data_start, 2);
+  off_t d_reloc = (intptr_t) _data - ALIGN (f_ohdr.data_start, 2);
 #endif
   int * p;
 
@@ -612,7 +606,7 @@ unrelocate_symbols (int new, int a_out,
              PERROR (a_name);
            }
 
-          p = (int *) (ldrel.l_vaddr + d_reloc);
+          p = (int *) (intptr_t) (ldrel.l_vaddr + d_reloc);
 
          switch (ldrel.l_symndx) {
          case SYMNDX_TEXT:
@@ -640,16 +634,3 @@ unrelocate_symbols (int new, int a_out,
     }
   return 0;
 }
-
-/*
- *     Return the address of the start of the text segment prior to
- *     doing an unexec.  After unexec the return value is undefined.
- *     See crt0.c for further explanation and _start.
- *
- */
-
-char *
-start_of_text (void)
-{
-  return ((char *) 0x10000000);
-}