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/window.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/window.c')
| -rw-r--r-- | src/window.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/window.c b/src/window.c index 6798be8231c..86f86deedb2 100644 --- a/src/window.c +++ b/src/window.c | |||
| @@ -2819,7 +2819,7 @@ window-start value is reasonable when this function is called. */) | |||
| 2819 | } | 2819 | } |
| 2820 | } | 2820 | } |
| 2821 | 2821 | ||
| 2822 | BLOCK_INPUT; | 2822 | block_input (); |
| 2823 | if (!FRAME_INITIAL_P (f)) | 2823 | if (!FRAME_INITIAL_P (f)) |
| 2824 | { | 2824 | { |
| 2825 | Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); | 2825 | Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); |
| @@ -2961,7 +2961,7 @@ window-start value is reasonable when this function is called. */) | |||
| 2961 | } | 2961 | } |
| 2962 | 2962 | ||
| 2963 | adjust_glyphs (f); | 2963 | adjust_glyphs (f); |
| 2964 | UNBLOCK_INPUT; | 2964 | unblock_input (); |
| 2965 | 2965 | ||
| 2966 | run_window_configuration_change_hook (f); | 2966 | run_window_configuration_change_hook (f); |
| 2967 | 2967 | ||
| @@ -3696,14 +3696,14 @@ be applied on the Elisp level. */) | |||
| 3696 | (horflag ? r->total_cols : r->total_lines))) | 3696 | (horflag ? r->total_cols : r->total_lines))) |
| 3697 | return Qnil; | 3697 | return Qnil; |
| 3698 | 3698 | ||
| 3699 | BLOCK_INPUT; | 3699 | block_input (); |
| 3700 | window_resize_apply (r, horflag); | 3700 | window_resize_apply (r, horflag); |
| 3701 | 3701 | ||
| 3702 | windows_or_buffers_changed++; | 3702 | windows_or_buffers_changed++; |
| 3703 | FRAME_WINDOW_SIZES_CHANGED (f) = 1; | 3703 | FRAME_WINDOW_SIZES_CHANGED (f) = 1; |
| 3704 | 3704 | ||
| 3705 | adjust_glyphs (f); | 3705 | adjust_glyphs (f); |
| 3706 | UNBLOCK_INPUT; | 3706 | unblock_input (); |
| 3707 | 3707 | ||
| 3708 | run_window_configuration_change_hook (f); | 3708 | run_window_configuration_change_hook (f); |
| 3709 | 3709 | ||
| @@ -3973,13 +3973,13 @@ set correctly. See the code of `split-window' for how this is done. */) | |||
| 3973 | wset_new_total (n, total_size); | 3973 | wset_new_total (n, total_size); |
| 3974 | wset_new_normal (n, normal_size); | 3974 | wset_new_normal (n, normal_size); |
| 3975 | 3975 | ||
| 3976 | BLOCK_INPUT; | 3976 | block_input (); |
| 3977 | window_resize_apply (p, horflag); | 3977 | window_resize_apply (p, horflag); |
| 3978 | adjust_glyphs (f); | 3978 | adjust_glyphs (f); |
| 3979 | /* Set buffer of NEW to buffer of reference window. Don't run | 3979 | /* Set buffer of NEW to buffer of reference window. Don't run |
| 3980 | any hooks. */ | 3980 | any hooks. */ |
| 3981 | set_window_buffer (new, r->buffer, 0, 1); | 3981 | set_window_buffer (new, r->buffer, 0, 1); |
| 3982 | UNBLOCK_INPUT; | 3982 | unblock_input (); |
| 3983 | 3983 | ||
| 3984 | /* Maybe we should run the scroll functions in Elisp (which already | 3984 | /* Maybe we should run the scroll functions in Elisp (which already |
| 3985 | runs the configuration change hook). */ | 3985 | runs the configuration change hook). */ |
| @@ -4060,7 +4060,7 @@ Signal an error when WINDOW is the only window on its frame. */) | |||
| 4060 | { | 4060 | { |
| 4061 | 4061 | ||
| 4062 | /* Block input. */ | 4062 | /* Block input. */ |
| 4063 | BLOCK_INPUT; | 4063 | block_input (); |
| 4064 | window_resize_apply (p, horflag); | 4064 | window_resize_apply (p, horflag); |
| 4065 | 4065 | ||
| 4066 | /* If this window is referred to by the dpyinfo's mouse | 4066 | /* If this window is referred to by the dpyinfo's mouse |
| @@ -4132,7 +4132,7 @@ Signal an error when WINDOW is the only window on its frame. */) | |||
| 4132 | else | 4132 | else |
| 4133 | fset_selected_window (f, new_selected_window); | 4133 | fset_selected_window (f, new_selected_window); |
| 4134 | 4134 | ||
| 4135 | UNBLOCK_INPUT; | 4135 | unblock_input (); |
| 4136 | 4136 | ||
| 4137 | /* Now look whether `get-mru-window' gets us something. */ | 4137 | /* Now look whether `get-mru-window' gets us something. */ |
| 4138 | mru_window = call1 (Qget_mru_window, frame); | 4138 | mru_window = call1 (Qget_mru_window, frame); |
| @@ -4147,7 +4147,7 @@ Signal an error when WINDOW is the only window on its frame. */) | |||
| 4147 | fset_selected_window (f, new_selected_window); | 4147 | fset_selected_window (f, new_selected_window); |
| 4148 | } | 4148 | } |
| 4149 | else | 4149 | else |
| 4150 | UNBLOCK_INPUT; | 4150 | unblock_input (); |
| 4151 | 4151 | ||
| 4152 | /* Must be run by the caller: | 4152 | /* Must be run by the caller: |
| 4153 | run_window_configuration_change_hook (f); */ | 4153 | run_window_configuration_change_hook (f); */ |
| @@ -4197,7 +4197,7 @@ grow_mini_window (struct window *w, int delta) | |||
| 4197 | root, make_number (- delta)); | 4197 | root, make_number (- delta)); |
| 4198 | if (INTEGERP (value) && window_resize_check (r, 0)) | 4198 | if (INTEGERP (value) && window_resize_check (r, 0)) |
| 4199 | { | 4199 | { |
| 4200 | BLOCK_INPUT; | 4200 | block_input (); |
| 4201 | window_resize_apply (r, 0); | 4201 | window_resize_apply (r, 0); |
| 4202 | 4202 | ||
| 4203 | /* Grow the mini-window. */ | 4203 | /* Grow the mini-window. */ |
| @@ -4209,7 +4209,7 @@ grow_mini_window (struct window *w, int delta) | |||
| 4209 | w->last_overlay_modified = 0; | 4209 | w->last_overlay_modified = 0; |
| 4210 | 4210 | ||
| 4211 | adjust_glyphs (f); | 4211 | adjust_glyphs (f); |
| 4212 | UNBLOCK_INPUT; | 4212 | unblock_input (); |
| 4213 | } | 4213 | } |
| 4214 | } | 4214 | } |
| 4215 | 4215 | ||
| @@ -4234,7 +4234,7 @@ shrink_mini_window (struct window *w) | |||
| 4234 | root, make_number (size - 1)); | 4234 | root, make_number (size - 1)); |
| 4235 | if (INTEGERP (value) && window_resize_check (r, 0)) | 4235 | if (INTEGERP (value) && window_resize_check (r, 0)) |
| 4236 | { | 4236 | { |
| 4237 | BLOCK_INPUT; | 4237 | block_input (); |
| 4238 | window_resize_apply (r, 0); | 4238 | window_resize_apply (r, 0); |
| 4239 | 4239 | ||
| 4240 | /* Shrink the mini-window. */ | 4240 | /* Shrink the mini-window. */ |
| @@ -4246,7 +4246,7 @@ shrink_mini_window (struct window *w) | |||
| 4246 | w->last_overlay_modified = 0; | 4246 | w->last_overlay_modified = 0; |
| 4247 | 4247 | ||
| 4248 | adjust_glyphs (f); | 4248 | adjust_glyphs (f); |
| 4249 | UNBLOCK_INPUT; | 4249 | unblock_input (); |
| 4250 | } | 4250 | } |
| 4251 | /* If the above failed for whatever strange reason we must make a | 4251 | /* If the above failed for whatever strange reason we must make a |
| 4252 | one window frame here. The same routine will be needed when | 4252 | one window frame here. The same routine will be needed when |
| @@ -4278,7 +4278,7 @@ DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal, Sresize_mini | |||
| 4278 | && XINT (w->new_total) > 0 | 4278 | && XINT (w->new_total) > 0 |
| 4279 | && height == XINT (r->new_total) + XINT (w->new_total)) | 4279 | && height == XINT (r->new_total) + XINT (w->new_total)) |
| 4280 | { | 4280 | { |
| 4281 | BLOCK_INPUT; | 4281 | block_input (); |
| 4282 | window_resize_apply (r, 0); | 4282 | window_resize_apply (r, 0); |
| 4283 | 4283 | ||
| 4284 | wset_total_lines (w, w->new_total); | 4284 | wset_total_lines (w, w->new_total); |
| @@ -4288,7 +4288,7 @@ DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal, Sresize_mini | |||
| 4288 | windows_or_buffers_changed++; | 4288 | windows_or_buffers_changed++; |
| 4289 | FRAME_WINDOW_SIZES_CHANGED (f) = 1; | 4289 | FRAME_WINDOW_SIZES_CHANGED (f) = 1; |
| 4290 | adjust_glyphs (f); | 4290 | adjust_glyphs (f); |
| 4291 | UNBLOCK_INPUT; | 4291 | unblock_input (); |
| 4292 | 4292 | ||
| 4293 | run_window_configuration_change_hook (f); | 4293 | run_window_configuration_change_hook (f); |
| 4294 | return Qt; | 4294 | return Qt; |
| @@ -5624,7 +5624,7 @@ the return value is nil. Otherwise the value is t. */) | |||
| 5624 | 5624 | ||
| 5625 | /* The mouse highlighting code could get screwed up | 5625 | /* The mouse highlighting code could get screwed up |
| 5626 | if it runs during this. */ | 5626 | if it runs during this. */ |
| 5627 | BLOCK_INPUT; | 5627 | block_input (); |
| 5628 | 5628 | ||
| 5629 | if (data->frame_lines != previous_frame_lines | 5629 | if (data->frame_lines != previous_frame_lines |
| 5630 | || data->frame_cols != previous_frame_cols) | 5630 | || data->frame_cols != previous_frame_cols) |
| @@ -5875,7 +5875,7 @@ the return value is nil. Otherwise the value is t. */) | |||
| 5875 | } | 5875 | } |
| 5876 | 5876 | ||
| 5877 | adjust_glyphs (f); | 5877 | adjust_glyphs (f); |
| 5878 | UNBLOCK_INPUT; | 5878 | unblock_input (); |
| 5879 | 5879 | ||
| 5880 | /* Scan dead buffer windows. */ | 5880 | /* Scan dead buffer windows. */ |
| 5881 | for (; CONSP (dead_windows); dead_windows = XCDR (dead_windows)) | 5881 | for (; CONSP (dead_windows); dead_windows = XCDR (dead_windows)) |