]> code.delx.au - gnu-emacs/blobdiff - src/unexec.c
(set-auto-mode): Run multiple mode: specs in left-to-right order.
[gnu-emacs] / src / unexec.c
index 3be336a9a779849918eb90e3dbcc9ca2159ed469..7e2760159432063bf40d14e6a2ccb1ee752edb23 100644 (file)
@@ -14,7 +14,8 @@ GNU General Public License for more details.
 
 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., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 
 /*
@@ -175,6 +176,9 @@ int need_coff_header = 1;
 #include <coff-encap/a.out.encap.h> /* The location might be a poor assumption */
 #else
 #ifdef MSDOS
+#if __DJGPP__ > 1
+#include <fcntl.h>  /* for O_RDONLY, O_RDWR */
+#endif
 #include <coff.h>
 #define filehdr external_filehdr
 #define scnhdr external_scnhdr
@@ -875,6 +879,14 @@ copy_text_and_data (new, a_out)
 
 #else /* COFF, but not USG_SHARED_LIBRARIES */
 
+#ifdef MSDOS
+#if __DJGPP__ >= 2
+  /* Dump the original table of exception handlers, not the one
+     where our exception hooks are registered.  */
+  __djgpp_exception_toggle ();
+#endif
+#endif
+
   lseek (new, (long) text_scnptr, 0);
   ptr = (char *) f_ohdr.text_start;
 #ifdef HEADER_INCL_IN_TEXT
@@ -889,6 +901,13 @@ copy_text_and_data (new, a_out)
   end = ptr + f_ohdr.dsize;
   write_segment (new, ptr, end);
 
+#ifdef MSDOS
+#if __DJGPP__ >= 2
+  /* Restore our exception hooks.  */
+  __djgpp_exception_toggle ();
+#endif
+#endif
+
 #endif /* USG_SHARED_LIBRARIES */
 
 #else /* if not COFF */
@@ -915,8 +934,8 @@ copy_text_and_data (new, a_out)
    * runs, it copies the table to where these parameters live during
    * execution.  This data is in text space, so it cannot be modified here
    * before saving the executable, so the data is written manually.  In
-   * addition, the table does not have a label, and the nearest accessable
-   * label (mcount) is not prefixed with a '_', thus making it inaccessable
+   * addition, the table does not have a label, and the nearest accessible
+   * label (mcount) is not prefixed with a '_', thus making it inaccessible
    * from within C programs.  To overcome this, emacs's executable is passed
    * through the command 'nm %s | fgrep mcount' into a pipe, and the
    * resultant output is then used to find the address of 'mcount'.  As far as
@@ -1014,15 +1033,18 @@ write_segment (new, ptr, end)
   register int i, nwrite, ret;
   char buf[80];
   extern int errno;
+  /* This is the normal amount to write at once.
+     It is the size of block that NFS uses.  */
+  int writesize = 1 << 13;
   int pagesize = getpagesize ();
-  char *zeros = (char *) alloca (pagesize);
+  char zeros[1 << 13];
 
-  bzero (zeros, pagesize);
+  bzero (zeros, sizeof (zeros));
 
   for (i = 0; ptr < end;)
     {
-      /* distance to next multiple of pagesize.  */
-      nwrite = (((int) ptr + pagesize) & -pagesize) - (int) ptr;
+      /* Distance to next multiple of writesize.  */
+      nwrite = (((int) ptr + writesize) & -writesize) - (int) ptr;
       /* But not beyond specified end.  */
       if (nwrite > end - ptr) nwrite = end - ptr;
       ret = write (new, ptr, nwrite);
@@ -1035,7 +1057,16 @@ write_segment (new, ptr, end)
          && errno == EFAULT
 #endif
          )
-       write (new, zeros, nwrite);
+       {
+         /* Write only a page of zeros at once,
+            so that we we don't overshoot the start
+            of the valid memory in the old data segment.  */
+         if (nwrite > pagesize)
+           nwrite = pagesize;
+         write (new, zeros, nwrite);
+       }
+#if 0 /* Now that we have can ask `write' to write more than a page,
+        it is legit for write do less than the whole amount specified.  */
       else if (nwrite != ret)
        {
          sprintf (buf,
@@ -1043,6 +1074,7 @@ write_segment (new, ptr, end)
                   ptr, new, nwrite, ret, errno);
          PERROR (buf);
        }
+#endif
       i += nwrite;
       ptr += nwrite;
     }