Comment fixes.
[bpt/emacs.git] / src / unexec.c
index d0ac5b4..6b6136b 100644 (file)
@@ -170,8 +170,6 @@ pointer looks like an int) but not on all machines.
 
 #ifndef CANNOT_DUMP  /* all rest of file!  */
 
-#ifndef CANNOT_UNEXEC /* most of rest of file */
-
 #ifdef COFF_ENCAPSULATE
 int need_coff_header = 1;
 #include <coff-encap/a.out.encap.h> /* The location might be a poor assumption */
@@ -202,9 +200,8 @@ struct aouthdr
 #endif /* not MSDOS */
 #endif
 
-/* Define getpagesize () if the system does not.
-   Note that this may depend on symbols defined in a.out.h
- */
+/* Define getpagesize if the system does not.
+   Note that this may depend on symbols defined in a.out.h.  */
 #include "getpagesize.h"
 
 #ifndef makedev                        /* Try to detect types.h already loaded */
@@ -793,12 +790,13 @@ make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name)
       PERROR (new_name);
     }
 
+#if 0 /* This #ifndef caused a bug on Linux when using QMAGIC.  */
   /* This adjustment was done above only #ifndef NO_REMAP,
      so only undo it now #ifndef NO_REMAP.  */
-#ifndef NO_REMAP
+  /* #ifndef NO_REMAP  */
+#endif
 #ifdef A_TEXT_OFFSET
   hdr.a_text -= A_TEXT_OFFSET (ohdr);
-#endif
 #endif
 
   return 0;
@@ -897,7 +895,7 @@ copy_text_and_data (new, a_out)
 
 /* Some machines count the header as part of the text segment.
    That is to say, the header appears in core
-   just before the address that start_of_text () returns.
+   just before the address that start_of_text returns.
    For them, N_TXTOFF is the place where the header goes.
    We must adjust the seek to the place after the header.
    Note that at this point hdr.a_text does *not* count
@@ -913,12 +911,12 @@ copy_text_and_data (new, a_out)
 
   /* Acorn's RISC-iX has a wacky way of initialising the position of the heap.
    * There is a little table in crt0.o that is filled at link time with
-   * the min and current brk positions, among other things.  When start()
+   * the min and current brk positions, among other things.  When start
    * 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
@@ -1016,14 +1014,18 @@ write_segment (new, ptr, end)
   register int i, nwrite, ret;
   char buf[80];
   extern int errno;
-  char zeros[128];
+  /* 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[1 << 13];
 
-  bzero (zeros, sizeof zeros);
+  bzero (zeros, sizeof (zeros));
 
   for (i = 0; ptr < end;)
     {
-      /* distance to next multiple of 128.  */
-      nwrite = (((int) ptr + 128) & -128) - (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);
@@ -1036,7 +1038,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,
@@ -1044,6 +1055,7 @@ write_segment (new, ptr, end)
                   ptr, new, nwrite, ret, errno);
          PERROR (buf);
        }
+#endif
       i += nwrite;
       ptr += nwrite;
     }
@@ -1194,6 +1206,4 @@ adjust_lnnoptrs (writedesc, readdesc, new_name)
 
 #endif /* COFF */
 
-#endif /* not CANNOT_UNEXEC */
-
 #endif /* not CANNOT_DUMP */