diff options
| author | Eli Zaretskii | 2014-05-29 17:52:47 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2014-05-29 17:52:47 +0300 |
| commit | 0bbb27fc3f52f87605cfadba62d52b72523b73a5 (patch) | |
| tree | facc4efc43f9ab259ab7f26c0bdb44afe52f9c0c /src | |
| parent | 609b06a0a1649b9bbcc6ffe0ac96a4192f855603 (diff) | |
| download | emacs-0bbb27fc3f52f87605cfadba62d52b72523b73a5.tar.gz emacs-0bbb27fc3f52f87605cfadba62d52b72523b73a5.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 13 | ||||
| -rw-r--r-- | src/buffer.c | 60 | ||||
| -rw-r--r-- | src/emacs.c | 3 | ||||
| -rw-r--r-- | src/lisp.h | 2 |
4 files changed, 60 insertions, 18 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 7665ccb7083..33b8257cc1c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,16 @@ | |||
| 1 | 2014-05-29 Eli Zaretskii <eliz@gnu.org> | ||
| 2 | |||
| 3 | * buffer.c (init_buffer): Accept an argument 'initialized'. | ||
| 4 | [USE_MMAP_FOR_BUFFERS]: If 'initialized' is non-zero, reset | ||
| 5 | mmap_regions and mmap_fd, to avoid referencing stale data from the | ||
| 6 | dump phase. Add an assertion for buffer text of buffers created | ||
| 7 | in temacs before this function is called. (Bug#17622) | ||
| 8 | (mmap_regions_1, mmap_fd_1): Remove unused variables. | ||
| 9 | |||
| 10 | * lisp.h (init_buffer): Update prototype. | ||
| 11 | |||
| 12 | * emacs.c (main): Pass 'initialized' as the argument to init_buffer. | ||
| 13 | |||
| 1 | 2014-05-29 Dmitry Antipov <dmantipov@yandex.ru> | 14 | 2014-05-29 Dmitry Antipov <dmantipov@yandex.ru> |
| 2 | 15 | ||
| 3 | * alloc.c (Fgarbage_collect): Fix compilation with | 16 | * alloc.c (Fgarbage_collect): Fix compilation with |
diff --git a/src/buffer.c b/src/buffer.c index 3cbb8153bc9..909b3779b06 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -4703,11 +4703,6 @@ static struct mmap_region *mmap_regions; | |||
| 4703 | 4703 | ||
| 4704 | static int mmap_fd; | 4704 | static int mmap_fd; |
| 4705 | 4705 | ||
| 4706 | /* Temporary storage for mmap_set_vars, see there. */ | ||
| 4707 | |||
| 4708 | static struct mmap_region *mmap_regions_1; | ||
| 4709 | static int mmap_fd_1; | ||
| 4710 | |||
| 4711 | /* Page size on this system. */ | 4706 | /* Page size on this system. */ |
| 4712 | 4707 | ||
| 4713 | static int mmap_page_size; | 4708 | static int mmap_page_size; |
| @@ -5272,24 +5267,57 @@ init_buffer_once (void) | |||
| 5272 | } | 5267 | } |
| 5273 | 5268 | ||
| 5274 | void | 5269 | void |
| 5275 | init_buffer (void) | 5270 | init_buffer (int initialized) |
| 5276 | { | 5271 | { |
| 5277 | char *pwd; | 5272 | char *pwd; |
| 5278 | Lisp_Object temp; | 5273 | Lisp_Object temp; |
| 5279 | ptrdiff_t len; | 5274 | ptrdiff_t len; |
| 5280 | 5275 | ||
| 5281 | #ifdef USE_MMAP_FOR_BUFFERS | 5276 | #ifdef USE_MMAP_FOR_BUFFERS |
| 5282 | { | 5277 | if (initialized) |
| 5283 | struct buffer *b; | 5278 | { |
| 5279 | struct buffer *b; | ||
| 5284 | 5280 | ||
| 5285 | /* We cannot dump buffers with meaningful addresses that can be | 5281 | #ifndef WINDOWSNT |
| 5286 | used by the dumped Emacs. We map new memory for them here. */ | 5282 | /* These must be reset in the dumped Emacs, to avoid stale |
| 5287 | FOR_EACH_BUFFER (b) | 5283 | references to mmap'ed memory from before the dump. |
| 5288 | { | 5284 | |
| 5289 | b->text->beg = NULL; | 5285 | WINDOWSNT doesn't need this because it doesn't track mmap'ed |
| 5290 | enlarge_buffer_text (b, 0); | 5286 | regions by hand (see w32heap.c, which uses system APIs for |
| 5291 | } | 5287 | that purpose), and thus doesn't use mmap_regions. */ |
| 5292 | } | 5288 | mmap_regions = NULL; |
| 5289 | mmap_fd = -1; | ||
| 5290 | #endif | ||
| 5291 | |||
| 5292 | /* The dumped buffers reference addresses of buffer text | ||
| 5293 | recorded by temacs, that cannot be used by the dumped Emacs. | ||
| 5294 | We map new memory for their text here. | ||
| 5295 | |||
| 5296 | Implementation note: the buffers we carry from temacs are: | ||
| 5297 | " prin1", "*scratch*", " *Minibuf-0*", "*Messages*", and | ||
| 5298 | " *code-conversion-work*". They are created by | ||
| 5299 | init_buffer_once and init_window_once (which are not called | ||
| 5300 | in the dumped Emacs), and by the first call to coding.c routines. */ | ||
| 5301 | FOR_EACH_BUFFER (b) | ||
| 5302 | { | ||
| 5303 | b->text->beg = NULL; | ||
| 5304 | enlarge_buffer_text (b, 0); | ||
| 5305 | } | ||
| 5306 | } | ||
| 5307 | else | ||
| 5308 | { | ||
| 5309 | struct buffer *b; | ||
| 5310 | |||
| 5311 | /* Only buffers with allocated buffer text should be present at | ||
| 5312 | this point in temacs. */ | ||
| 5313 | FOR_EACH_BUFFER (b) | ||
| 5314 | { | ||
| 5315 | eassert (b->text->beg != NULL); | ||
| 5316 | } | ||
| 5317 | } | ||
| 5318 | #else /* not USE_MMAP_FOR_BUFFERS */ | ||
| 5319 | /* Avoid compiler warnings. */ | ||
| 5320 | initialized = initialized; | ||
| 5293 | #endif /* USE_MMAP_FOR_BUFFERS */ | 5321 | #endif /* USE_MMAP_FOR_BUFFERS */ |
| 5294 | 5322 | ||
| 5295 | Fset_buffer (Fget_buffer_create (build_string ("*scratch*"))); | 5323 | Fset_buffer (Fget_buffer_create (build_string ("*scratch*"))); |
diff --git a/src/emacs.c b/src/emacs.c index fabea11a3bf..57f713125ee 100644 --- a/src/emacs.c +++ b/src/emacs.c | |||
| @@ -1376,7 +1376,8 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem | |||
| 1376 | xputenv ("LANG=C"); | 1376 | xputenv ("LANG=C"); |
| 1377 | #endif | 1377 | #endif |
| 1378 | 1378 | ||
| 1379 | init_buffer (); /* Init default directory of main buffer. */ | 1379 | /* Init buffer storage and default directory of main buffer. */ |
| 1380 | init_buffer (initialized); | ||
| 1380 | 1381 | ||
| 1381 | init_callproc_1 (); /* Must precede init_cmdargs and init_sys_modes. */ | 1382 | init_callproc_1 (); /* Must precede init_cmdargs and init_sys_modes. */ |
| 1382 | 1383 | ||
diff --git a/src/lisp.h b/src/lisp.h index 62fca16ec38..bbe2e4e9ce2 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -3951,7 +3951,7 @@ extern bool overlay_touches_p (ptrdiff_t); | |||
| 3951 | extern Lisp_Object other_buffer_safely (Lisp_Object); | 3951 | extern Lisp_Object other_buffer_safely (Lisp_Object); |
| 3952 | extern Lisp_Object get_truename_buffer (Lisp_Object); | 3952 | extern Lisp_Object get_truename_buffer (Lisp_Object); |
| 3953 | extern void init_buffer_once (void); | 3953 | extern void init_buffer_once (void); |
| 3954 | extern void init_buffer (void); | 3954 | extern void init_buffer (int); |
| 3955 | extern void syms_of_buffer (void); | 3955 | extern void syms_of_buffer (void); |
| 3956 | extern void keys_of_buffer (void); | 3956 | extern void keys_of_buffer (void); |
| 3957 | 3957 | ||