emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r117187: Fix bug #17622 with crashes in mmap routine


From: Eli Zaretskii
Subject: [Emacs-diffs] trunk r117187: Fix bug #17622 with crashes in mmap routines.
Date: Thu, 29 May 2014 14:53:28 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117187
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/17622
committer: Eli Zaretskii <address@hidden>
branch nick: trunk
timestamp: Thu 2014-05-29 17:52:47 +0300
message:
  Fix bug #17622 with crashes in mmap routines.
  
   src/buffer.c (init_buffer): Accept an argument 'initialized'.
   [USE_MMAP_FOR_BUFFERS]: If 'initialized' is non-zero, reset
   mmap_regions and mmap_fd, to avoid referencing stale data from the
   dump phase.  Add an assertion for buffer text of buffers created
   in temacs before this function is called.
   (mmap_regions_1, mmap_fd_1): Remove unused variables.
   src/lisp.h (init_buffer): Update prototype.
   src/emacs.c (main): Pass 'initialized' as the argument to init_buffer.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/buffer.c                   buffer.c-20091113204419-o5vbwnq5f7feedwu-264
  src/emacs.c                    emacs.c-20091113204419-o5vbwnq5f7feedwu-241
  src/lisp.h                     lisp.h-20091113204419-o5vbwnq5f7feedwu-253
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-05-29 08:02:58 +0000
+++ b/src/ChangeLog     2014-05-29 14:52:47 +0000
@@ -1,3 +1,16 @@
+2014-05-29  Eli Zaretskii  <address@hidden>
+
+       * buffer.c (init_buffer): Accept an argument 'initialized'.
+       [USE_MMAP_FOR_BUFFERS]: If 'initialized' is non-zero, reset
+       mmap_regions and mmap_fd, to avoid referencing stale data from the
+       dump phase.  Add an assertion for buffer text of buffers created
+       in temacs before this function is called.  (Bug#17622)
+       (mmap_regions_1, mmap_fd_1): Remove unused variables.
+
+       * lisp.h (init_buffer): Update prototype.
+
+       * emacs.c (main): Pass 'initialized' as the argument to init_buffer.
+
 2014-05-29  Dmitry Antipov  <address@hidden>
 
        * alloc.c (Fgarbage_collect): Fix compilation with

=== modified file 'src/buffer.c'
--- a/src/buffer.c      2014-05-27 17:31:17 +0000
+++ b/src/buffer.c      2014-05-29 14:52:47 +0000
@@ -4703,11 +4703,6 @@
 
 static int mmap_fd;
 
-/* Temporary storage for mmap_set_vars, see there.  */
-
-static struct mmap_region *mmap_regions_1;
-static int mmap_fd_1;
-
 /* Page size on this system.  */
 
 static int mmap_page_size;
@@ -5272,24 +5267,57 @@
 }
 
 void
-init_buffer (void)
+init_buffer (int initialized)
 {
   char *pwd;
   Lisp_Object temp;
   ptrdiff_t len;
 
 #ifdef USE_MMAP_FOR_BUFFERS
-  {
-    struct buffer *b;
-
-    /* We cannot dump buffers with meaningful addresses that can be
-       used by the dumped Emacs.  We map new memory for them here.  */
-    FOR_EACH_BUFFER (b)
-      {
-       b->text->beg = NULL;
-       enlarge_buffer_text (b, 0);
-      }
-  }
+  if (initialized)
+    {
+      struct buffer *b;
+
+#ifndef WINDOWSNT
+      /* These must be reset in the dumped Emacs, to avoid stale
+        references to mmap'ed memory from before the dump.
+
+        WINDOWSNT doesn't need this because it doesn't track mmap'ed
+        regions by hand (see w32heap.c, which uses system APIs for
+        that purpose), and thus doesn't use mmap_regions.  */
+      mmap_regions = NULL;
+      mmap_fd = -1;
+#endif
+
+      /* The dumped buffers reference addresses of buffer text
+        recorded by temacs, that cannot be used by the dumped Emacs.
+        We map new memory for their text here.
+
+        Implementation note: the buffers we carry from temacs are:
+        " prin1", "*scratch*", " *Minibuf-0*", "*Messages*", and
+        " *code-conversion-work*".  They are created by
+        init_buffer_once and init_window_once (which are not called
+        in the dumped Emacs), and by the first call to coding.c routines.  */
+      FOR_EACH_BUFFER (b)
+        {
+         b->text->beg = NULL;
+         enlarge_buffer_text (b, 0);
+       }
+    }
+  else
+    {
+      struct buffer *b;
+
+      /* Only buffers with allocated buffer text should be present at
+        this point in temacs.  */
+      FOR_EACH_BUFFER (b)
+        {
+         eassert (b->text->beg != NULL);
+       }
+    }
+#else  /* not USE_MMAP_FOR_BUFFERS */
+  /* Avoid compiler warnings.  */
+  initialized = initialized;
 #endif /* USE_MMAP_FOR_BUFFERS */
 
   Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));

=== modified file 'src/emacs.c'
--- a/src/emacs.c       2014-05-27 17:31:17 +0000
+++ b/src/emacs.c       2014-05-29 14:52:47 +0000
@@ -1376,7 +1376,8 @@
   xputenv ("LANG=C");
 #endif
 
-  init_buffer ();      /* Init default directory of main buffer.  */
+  /* Init buffer storage and default directory of main buffer.  */
+  init_buffer (initialized);
 
   init_callproc_1 ();  /* Must precede init_cmdargs and init_sys_modes.  */
 

=== modified file 'src/lisp.h'
--- a/src/lisp.h        2014-05-27 17:31:17 +0000
+++ b/src/lisp.h        2014-05-29 14:52:47 +0000
@@ -3951,7 +3951,7 @@
 extern Lisp_Object other_buffer_safely (Lisp_Object);
 extern Lisp_Object get_truename_buffer (Lisp_Object);
 extern void init_buffer_once (void);
-extern void init_buffer (void);
+extern void init_buffer (int);
 extern void syms_of_buffer (void);
 extern void keys_of_buffer (void);
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]