diff options
| author | Paul Eggert | 2012-09-23 01:44:20 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-09-23 01:44:20 -0700 |
| commit | 4d7e6e51dd4acecff466a28d958c50f34fc130b8 (patch) | |
| tree | 5e340d48fb69f9a40a4304cc94db2006caefe51f /src/image.c | |
| parent | 8f4635e97e1587c4026ec83fc1bd9f8954775915 (diff) | |
| download | emacs-4d7e6e51dd4acecff466a28d958c50f34fc130b8.tar.gz emacs-4d7e6e51dd4acecff466a28d958c50f34fc130b8.zip | |
Simplify and avoid signal-handling races.
* nt/inc/ms-w32.h (emacs_raise): New macro.
* src/alloc.c (die):
* src/sysdep.c (emacs_abort) [HAVE_NTGUI]:
Avoid recursive loop if there's a fatal error in the function itself.
* src/atimer.c (pending_atimers):
* src/blockinput.h: Don't include "atimer.h"; no longer needed.
(interrupt_input_pending): Remove. All uses removed.
pending_signals now counts both atimers and ordinary interrupts.
This is less racy than having three separate pending-signal flags.
(block_input, unblock_input, totally_unblock_input, unblock_input_to)
(input_blocked_p):
Rename from their upper-case counterparts BLOCK_INPUT,
UNBLOCK_INPUT, TOTALLY_UNBLOCK_INPUT, UNBLOCK_INPUT_TO,
INPUT_BLOCKED_P, and turn into functions. All uses changed.
This makes it easier to access volatile variables more accurately.
(BLOCK_INPUT_RESIGNAL): Remove. All uses replaced by unblock_input ().
(input_blocked_p): Prefer this to 'interrupt_input_blocked', as
that's more reliable if the code is buggy and sets
interrupt_input_blocked to a negative value. All uses changed.
* src/atimer.c (deliver_alarm_signal):
Remove. No need to deliver this to the parent; any thread can
handle this signal now. All uses replaced by underlying handler.
* src/atimer.c (turn_on_atimers):
* src/dispnew.c (handle_window_change_signal):
* src/emacs.c (handle_danger_signal):
* src/keyboard.c (kbd_buffer_get_event):
Don't reestablish signal handler; not needed with sigaction.
* src/blockinput.h (UNBLOCK_INPUT_TO, TOTALLY_UNBLOCK_INPUT)
(UNBLOCK_INPUT_TO):
Rework to avoid unnecessary accesses to volatile variables.
(UNBLOCK_INPUT_TO): Now a function.
(totally_unblock_input, unblock_input): New decls.
* src/data.c (handle_arith_signal, deliver_arith_signal): Move to sysdep.c
(init_data): Remove. Necessary stuff now done in init_signal.
* src/emacs.c, src/xdisp.c: Include "atimer.h", since we invoke atimer functions.
* src/emacs.c (handle_fatal_signal, deliver_fatal_signal): Move to sysdep.c.
(fatal_error_code): Remove; no longer needed.
(terminate_due_to_signal): Rename from fatal_error_backtrace, since
it doesn't always backtrace. All uses changed. No need to reset
signal to default, since sigaction and/or die does that for us now.
Use emacs_raise (FOO), not kill (getpid (), FOO).
(main): Check more-accurately whether we're dumping.
Move fatal-error setup to sysdep.c
* src/floatfns.c: Do not include "syssignal.h"; no longer needed.
* src/gtkutil.c (xg_get_file_name, xg_get_font):
Remove no-longer-needed signal-mask manipulation.
* src/keyboard.c, src/process.c (POLL_FOR_INPUT):
Don't depend on USE_ASYNC_EVENTS, a symbol that is never defined.
* src/keyboard.c (read_avail_input): Remove.
All uses replaced by gobble_input.
(Ftop_level): Use TOTALLY_UNBLOCK_INPUT rather than open code.
(kbd_buffer_store_event_hold, gobble_input):
(record_asynch_buffer_change) [USABLE_SIGIO]:
(store_user_signal_events):
No need to mess with signal mask.
(gobble_input): If blocking input and there are terminals, simply
set pending_signals to 1 and return. All hooks changed to not
worry about whether input is blocked.
(process_pending_signals): Clear pending_signals before processing
them, in case a signal comes in while we're processing.
By convention callers now test pending_signals before calling us.
(UNBLOCK_INPUT_TO, unblock_input, totally_unblock_input):
New functions, to support changes to blockinput.h.
(handle_input_available_signal): Now extern.
(reinvoke_input_signal): Remove. All uses replaced by
handle_async_input.
(quit_count): Now volatile, since a signal handler uses it.
(handle_interrupt): Now takes bool IN_SIGNAL_HANDLER as arg. All
callers changed. Block SIGINT only if not already blocked.
Clear sigmask reliably, even if Fsignal returns, which it can.
Omit unnecessary accesses to volatile var.
(quit_throw_to_read_char): No need to restore sigmask.
* src/keyboard.c (gobble_input, handle_user_signal):
* src/process.c (wait_reading_process_output):
Call signal-handling code rather than killing ourselves.
* src/lisp.h: Include <float.h>, for...
(IEEE_FLOATING_POINT): New macro, moved here to avoid duplication.
(pending_signals): Now volatile.
(syms_of_data): Now const if IEEE floating point.
(handle_input_available_signal) [USABLE_SIGIO]:
(terminate_due_to_signal, record_child_status_change): New decls.
* src/process.c (create_process): Avoid disaster if memory is exhausted
while we're processing a vfork, by tightening the critical section
around the vfork.
(send_process_frame, process_sent_to, handle_pipe_signal)
(deliver_pipe_signal): Remove. No longer needed, as Emacs now
ignores SIGPIPE.
(send_process): No need for setjmp/longjmp any more, since the
SIGPIPE stuff is now gone. Instead, report an error if errno
is EPIPE.
(record_child_status_change): Now extern. PID and W are now args.
Return void, not bool. All callers changed.
* src/sysdep.c (wait_debugging) [(BSD_SYSTEM || HPUX) && !defined (__GNU__)]:
Remove. All uses removed. This bug should be fixed now in a
different way.
(wait_for_termination_1): Use waitpid rather than sigsuspend,
and record the child status change directly. This avoids the
need to futz with the signal mask.
(process_fatal_action): Move here from emacs.c.
(emacs_sigaction_flags): New function, containing
much of what used to be in emacs_sigaction_init.
(emacs_sigaction_init): Use it. Block nonfatal system signals that are
caught by emacs, to make races less likely.
(deliver_process_signal): Rename from handle_on_main_thread.
All uses changed.
(BACKTRACE_LIMIT_MAX): Now at top level.
(thread_backtrace_buffer, threadback_backtrace_pointers):
New static vars.
(deliver_thread_signal, deliver_fatal_thread_signal):
New functions, for more-accurate delivery of thread-specific signals.
(handle_fatal_signal, deliver_fatal_signal): Move here from emacs.c.
(deliver_arith_signal): Handle in this thread, not
in the main thread, since it's triggered by this thread.
(maybe_fatal_sig): New function.
(init_signals): New arg DUMPING so that we can be more accurate
about whether we're dumping. Caller changed.
Treat thread-specific signals differently from process-general signals.
Block all signals while handling fatal error; that's safer.
xsignal from SIGFPE only on non-IEEE hosts, treating it as fatal
on IEEE hosts.
When batch, ignore SIGHUP, SIGINT, SIGTERM if they were already ignored.
Ignore SIGPIPE unless batch.
(emacs_backtrace): Output backtrace for the appropriate thread,
which is not necessarily the main thread.
* src/syssignal.h: Include <stdbool.h>.
(emacs_raise): New macro.
* src/xterm.c (x_connection_signal): Remove; no longer needed
now that we use sigaction.
(x_connection_closed): No need to mess with sigmask now.
(x_initialize): No need to reset SIGPIPE handler here, since
init_signals does this for us now.
Fixes: debbugs:12471
Diffstat (limited to 'src/image.c')
| -rw-r--r-- | src/image.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/image.c b/src/image.c index 0060d0d4148..a3717bf365e 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -407,9 +407,9 @@ x_destroy_bitmap (FRAME_PTR f, ptrdiff_t id) | |||
| 407 | 407 | ||
| 408 | if (--bm->refcount == 0) | 408 | if (--bm->refcount == 0) |
| 409 | { | 409 | { |
| 410 | BLOCK_INPUT; | 410 | block_input (); |
| 411 | free_bitmap_record (dpyinfo, bm); | 411 | free_bitmap_record (dpyinfo, bm); |
| 412 | UNBLOCK_INPUT; | 412 | unblock_input (); |
| 413 | } | 413 | } |
| 414 | } | 414 | } |
| 415 | } | 415 | } |
| @@ -470,19 +470,19 @@ x_create_bitmap_mask (struct frame *f, ptrdiff_t id) | |||
| 470 | width = x_bitmap_width (f, id); | 470 | width = x_bitmap_width (f, id); |
| 471 | height = x_bitmap_height (f, id); | 471 | height = x_bitmap_height (f, id); |
| 472 | 472 | ||
| 473 | BLOCK_INPUT; | 473 | block_input (); |
| 474 | ximg = XGetImage (FRAME_X_DISPLAY (f), pixmap, 0, 0, width, height, | 474 | ximg = XGetImage (FRAME_X_DISPLAY (f), pixmap, 0, 0, width, height, |
| 475 | ~0, ZPixmap); | 475 | ~0, ZPixmap); |
| 476 | 476 | ||
| 477 | if (!ximg) | 477 | if (!ximg) |
| 478 | { | 478 | { |
| 479 | UNBLOCK_INPUT; | 479 | unblock_input (); |
| 480 | return -1; | 480 | return -1; |
| 481 | } | 481 | } |
| 482 | 482 | ||
| 483 | result = x_create_x_image_and_pixmap (f, width, height, 1, &mask_img, &mask); | 483 | result = x_create_x_image_and_pixmap (f, width, height, 1, &mask_img, &mask); |
| 484 | 484 | ||
| 485 | UNBLOCK_INPUT; | 485 | unblock_input (); |
| 486 | if (!result) | 486 | if (!result) |
| 487 | { | 487 | { |
| 488 | XDestroyImage (ximg); | 488 | XDestroyImage (ximg); |
| @@ -514,7 +514,7 @@ x_create_bitmap_mask (struct frame *f, ptrdiff_t id) | |||
| 514 | } | 514 | } |
| 515 | } | 515 | } |
| 516 | 516 | ||
| 517 | eassert (interrupt_input_blocked); | 517 | eassert (input_blocked_p ()); |
| 518 | gc = XCreateGC (FRAME_X_DISPLAY (f), mask, 0, NULL); | 518 | gc = XCreateGC (FRAME_X_DISPLAY (f), mask, 0, NULL); |
| 519 | XPutImage (FRAME_X_DISPLAY (f), mask, gc, mask_img, 0, 0, 0, 0, | 519 | XPutImage (FRAME_X_DISPLAY (f), mask, gc, mask_img, 0, 0, 0, 0, |
| 520 | width, height); | 520 | width, height); |
| @@ -593,7 +593,7 @@ define_image_type (struct image_type *type, Lisp_Object libraries) | |||
| 593 | Lisp_Object target_type = *type->type; | 593 | Lisp_Object target_type = *type->type; |
| 594 | int type_valid = 1; | 594 | int type_valid = 1; |
| 595 | 595 | ||
| 596 | BLOCK_INPUT; | 596 | block_input (); |
| 597 | 597 | ||
| 598 | for (p = image_types; p; p = p->next) | 598 | for (p = image_types; p; p = p->next) |
| 599 | if (EQ (*p->type, target_type)) | 599 | if (EQ (*p->type, target_type)) |
| @@ -625,7 +625,7 @@ define_image_type (struct image_type *type, Lisp_Object libraries) | |||
| 625 | } | 625 | } |
| 626 | 626 | ||
| 627 | done: | 627 | done: |
| 628 | UNBLOCK_INPUT; | 628 | unblock_input (); |
| 629 | return p; | 629 | return p; |
| 630 | } | 630 | } |
| 631 | 631 | ||
| @@ -1328,9 +1328,9 @@ x_clear_image_1 (struct frame *f, struct image *img, int pixmap_p, int mask_p, | |||
| 1328 | static void | 1328 | static void |
| 1329 | x_clear_image (struct frame *f, struct image *img) | 1329 | x_clear_image (struct frame *f, struct image *img) |
| 1330 | { | 1330 | { |
| 1331 | BLOCK_INPUT; | 1331 | block_input (); |
| 1332 | x_clear_image_1 (f, img, 1, 1, 1); | 1332 | x_clear_image_1 (f, img, 1, 1, 1); |
| 1333 | UNBLOCK_INPUT; | 1333 | unblock_input (); |
| 1334 | } | 1334 | } |
| 1335 | 1335 | ||
| 1336 | 1336 | ||
| @@ -1485,7 +1485,7 @@ clear_image_cache (struct frame *f, Lisp_Object filter) | |||
| 1485 | 1485 | ||
| 1486 | /* Block input so that we won't be interrupted by a SIGIO | 1486 | /* Block input so that we won't be interrupted by a SIGIO |
| 1487 | while being in an inconsistent state. */ | 1487 | while being in an inconsistent state. */ |
| 1488 | BLOCK_INPUT; | 1488 | block_input (); |
| 1489 | 1489 | ||
| 1490 | if (!NILP (filter)) | 1490 | if (!NILP (filter)) |
| 1491 | { | 1491 | { |
| @@ -1551,7 +1551,7 @@ clear_image_cache (struct frame *f, Lisp_Object filter) | |||
| 1551 | ++windows_or_buffers_changed; | 1551 | ++windows_or_buffers_changed; |
| 1552 | } | 1552 | } |
| 1553 | 1553 | ||
| 1554 | UNBLOCK_INPUT; | 1554 | unblock_input (); |
| 1555 | } | 1555 | } |
| 1556 | } | 1556 | } |
| 1557 | 1557 | ||
| @@ -1716,7 +1716,7 @@ lookup_image (struct frame *f, Lisp_Object spec) | |||
| 1716 | /* If not found, create a new image and cache it. */ | 1716 | /* If not found, create a new image and cache it. */ |
| 1717 | if (img == NULL) | 1717 | if (img == NULL) |
| 1718 | { | 1718 | { |
| 1719 | BLOCK_INPUT; | 1719 | block_input (); |
| 1720 | img = make_image (spec, hash); | 1720 | img = make_image (spec, hash); |
| 1721 | cache_image (f, img); | 1721 | cache_image (f, img); |
| 1722 | img->load_failed_p = img->type->load (f, img) == 0; | 1722 | img->load_failed_p = img->type->load (f, img) == 0; |
| @@ -1787,7 +1787,7 @@ lookup_image (struct frame *f, Lisp_Object spec) | |||
| 1787 | postprocess_image (f, img); | 1787 | postprocess_image (f, img); |
| 1788 | } | 1788 | } |
| 1789 | 1789 | ||
| 1790 | UNBLOCK_INPUT; | 1790 | unblock_input (); |
| 1791 | } | 1791 | } |
| 1792 | 1792 | ||
| 1793 | /* We're using IMG, so set its timestamp to `now'. */ | 1793 | /* We're using IMG, so set its timestamp to `now'. */ |
| @@ -1940,7 +1940,7 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth, | |||
| 1940 | Window window = FRAME_X_WINDOW (f); | 1940 | Window window = FRAME_X_WINDOW (f); |
| 1941 | Screen *screen = FRAME_X_SCREEN (f); | 1941 | Screen *screen = FRAME_X_SCREEN (f); |
| 1942 | 1942 | ||
| 1943 | eassert (interrupt_input_blocked); | 1943 | eassert (input_blocked_p ()); |
| 1944 | 1944 | ||
| 1945 | if (depth <= 0) | 1945 | if (depth <= 0) |
| 1946 | depth = DefaultDepthOfScreen (screen); | 1946 | depth = DefaultDepthOfScreen (screen); |
| @@ -2078,7 +2078,7 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth, | |||
| 2078 | static void | 2078 | static void |
| 2079 | x_destroy_x_image (XImagePtr ximg) | 2079 | x_destroy_x_image (XImagePtr ximg) |
| 2080 | { | 2080 | { |
| 2081 | eassert (interrupt_input_blocked); | 2081 | eassert (input_blocked_p ()); |
| 2082 | if (ximg) | 2082 | if (ximg) |
| 2083 | { | 2083 | { |
| 2084 | #ifdef HAVE_X_WINDOWS | 2084 | #ifdef HAVE_X_WINDOWS |
| @@ -2107,7 +2107,7 @@ x_put_x_image (struct frame *f, XImagePtr ximg, Pixmap pixmap, int width, int he | |||
| 2107 | #ifdef HAVE_X_WINDOWS | 2107 | #ifdef HAVE_X_WINDOWS |
| 2108 | GC gc; | 2108 | GC gc; |
| 2109 | 2109 | ||
| 2110 | eassert (interrupt_input_blocked); | 2110 | eassert (input_blocked_p ()); |
| 2111 | gc = XCreateGC (FRAME_X_DISPLAY (f), pixmap, 0, NULL); | 2111 | gc = XCreateGC (FRAME_X_DISPLAY (f), pixmap, 0, NULL); |
| 2112 | XPutImage (FRAME_X_DISPLAY (f), pixmap, gc, ximg, 0, 0, 0, 0, width, height); | 2112 | XPutImage (FRAME_X_DISPLAY (f), pixmap, gc, ximg, 0, 0, 0, 0, width, height); |
| 2113 | XFreeGC (FRAME_X_DISPLAY (f), gc); | 2113 | XFreeGC (FRAME_X_DISPLAY (f), gc); |
| @@ -4311,12 +4311,12 @@ lookup_pixel_color (struct frame *f, unsigned long pixel) | |||
| 4311 | x_query_color (f, &color); | 4311 | x_query_color (f, &color); |
| 4312 | rc = x_alloc_nearest_color (f, cmap, &color); | 4312 | rc = x_alloc_nearest_color (f, cmap, &color); |
| 4313 | #else | 4313 | #else |
| 4314 | BLOCK_INPUT; | 4314 | block_input (); |
| 4315 | cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f)); | 4315 | cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f)); |
| 4316 | color.pixel = pixel; | 4316 | color.pixel = pixel; |
| 4317 | XQueryColor (NULL, cmap, &color); | 4317 | XQueryColor (NULL, cmap, &color); |
| 4318 | rc = x_alloc_nearest_color (f, cmap, &color); | 4318 | rc = x_alloc_nearest_color (f, cmap, &color); |
| 4319 | UNBLOCK_INPUT; | 4319 | unblock_input (); |
| 4320 | #endif /* HAVE_X_WINDOWS */ | 4320 | #endif /* HAVE_X_WINDOWS */ |
| 4321 | 4321 | ||
| 4322 | if (rc) | 4322 | if (rc) |
| @@ -8656,11 +8656,11 @@ gs_load (struct frame *f, struct image *img) | |||
| 8656 | if (x_check_image_size (0, img->width, img->height)) | 8656 | if (x_check_image_size (0, img->width, img->height)) |
| 8657 | { | 8657 | { |
| 8658 | /* Only W32 version did BLOCK_INPUT here. ++kfs */ | 8658 | /* Only W32 version did BLOCK_INPUT here. ++kfs */ |
| 8659 | BLOCK_INPUT; | 8659 | block_input (); |
| 8660 | img->pixmap = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | 8660 | img->pixmap = XCreatePixmap (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
| 8661 | img->width, img->height, | 8661 | img->width, img->height, |
| 8662 | DefaultDepthOfScreen (FRAME_X_SCREEN (f))); | 8662 | DefaultDepthOfScreen (FRAME_X_SCREEN (f))); |
| 8663 | UNBLOCK_INPUT; | 8663 | unblock_input (); |
| 8664 | } | 8664 | } |
| 8665 | 8665 | ||
| 8666 | if (!img->pixmap) | 8666 | if (!img->pixmap) |
| @@ -8736,7 +8736,7 @@ x_kill_gs_process (Pixmap pixmap, struct frame *f) | |||
| 8736 | { | 8736 | { |
| 8737 | XImagePtr ximg; | 8737 | XImagePtr ximg; |
| 8738 | 8738 | ||
| 8739 | BLOCK_INPUT; | 8739 | block_input (); |
| 8740 | 8740 | ||
| 8741 | /* Try to get an XImage for img->pixmep. */ | 8741 | /* Try to get an XImage for img->pixmep. */ |
| 8742 | ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap, | 8742 | ximg = XGetImage (FRAME_X_DISPLAY (f), img->pixmap, |
| @@ -8779,15 +8779,15 @@ x_kill_gs_process (Pixmap pixmap, struct frame *f) | |||
| 8779 | image_error ("Cannot get X image of `%s'; colors will not be freed", | 8779 | image_error ("Cannot get X image of `%s'; colors will not be freed", |
| 8780 | img->spec, Qnil); | 8780 | img->spec, Qnil); |
| 8781 | 8781 | ||
| 8782 | UNBLOCK_INPUT; | 8782 | unblock_input (); |
| 8783 | } | 8783 | } |
| 8784 | #endif /* HAVE_X_WINDOWS */ | 8784 | #endif /* HAVE_X_WINDOWS */ |
| 8785 | 8785 | ||
| 8786 | /* Now that we have the pixmap, compute mask and transform the | 8786 | /* Now that we have the pixmap, compute mask and transform the |
| 8787 | image if requested. */ | 8787 | image if requested. */ |
| 8788 | BLOCK_INPUT; | 8788 | block_input (); |
| 8789 | postprocess_image (f, img); | 8789 | postprocess_image (f, img); |
| 8790 | UNBLOCK_INPUT; | 8790 | unblock_input (); |
| 8791 | } | 8791 | } |
| 8792 | 8792 | ||
| 8793 | #endif /* HAVE_GHOSTSCRIPT */ | 8793 | #endif /* HAVE_GHOSTSCRIPT */ |