]> code.delx.au - gnu-emacs/blobdiff - src/unexcw.c
* src/callint.c (Fcall_interactively): Use the right lexical environment
[gnu-emacs] / src / unexcw.c
index 02add901bbd1a96bfcd8d617f4049673818c48e3..af93e158e144d918ad09d7e08a9b529ec42ed831 100644 (file)
@@ -1,7 +1,7 @@
 /* unexec() support for Cygwin;
    complete rewrite of xemacs Cygwin unexec() code
 
-   Copyright (C) 2004-2011 Free Software Foundation, Inc.
+   Copyright (C) 2004-2013 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -19,7 +19,9 @@ You should have received a copy of the GNU General Public License
 along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
-#include <setjmp.h>
+#include "unexec.h"
+#include "w32common.h"
+
 #include <lisp.h>
 #include <stdio.h>
 #include <fcntl.h>
@@ -31,6 +33,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 extern int bss_sbrk_did_unexec;
 
+extern int __malloc_initialized;
+
 /* emacs symbols that indicate where bss and data end for emacs internals */
 extern char my_endbss[];
 extern char my_edata[];
@@ -179,6 +183,19 @@ fixup_executable (int fd)
                exe_header->file_optional_header.FileAlignment *
                exe_header->file_optional_header.FileAlignment;
 
+              /* Make sure the generated bootstrap binary isn't
+               * sparse.  NT doesn't use a file cache for sparse
+               * executables, so if we bootstrap Emacs using a sparse
+               * bootstrap-emacs.exe, bootstrap takes about twenty
+               * times longer than it would otherwise.  */
+
+              ret = posix_fallocate (fd,
+                                     ( exe_header->section_header[i].s_scnptr +
+                                       exe_header->section_header[i].s_size ),
+                                     1);
+
+              assert (ret != -1);
+
              ret =
                lseek (fd,
                       (long) (exe_header->section_header[i].s_scnptr +
@@ -208,9 +225,12 @@ fixup_executable (int fd)
            lseek (fd, (long) (exe_header->section_header[i].s_scnptr),
                   SEEK_SET);
          assert (ret != -1);
+         /* force the dumped emacs to reinitialize malloc */
+         __malloc_initialized = 0;
          ret =
            write (fd, (char *) start_address,
                   my_endbss - (char *) start_address);
+         __malloc_initialized = 1;
          assert (ret == (my_endbss - (char *) start_address));
          if (debug_unexcw)
            printf ("         .bss, mem start 0x%08x mem length %d\n",
@@ -247,7 +267,7 @@ add_exe_suffix_if_necessary (const char *name, char *modified)
   return (modified);
 }
 
-int
+void
 unexec (const char *outfile, const char *infile)
 {
   char infile_buffer[FILENAME_MAX];
@@ -261,7 +281,7 @@ unexec (const char *outfile, const char *infile)
     {
       /* can only dump once */
       printf ("You can only dump Emacs once on this platform.\n");
-      return (1);
+      return;
     }
 
   report_sheap_usage (1);
@@ -296,7 +316,4 @@ unexec (const char *outfile, const char *infile)
 
   ret = close (fd_out);
   assert (ret == 0);
-
-  return (0);
 }
-