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/buffer.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/buffer.c')
| -rw-r--r-- | src/buffer.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/buffer.c b/src/buffer.c index 22624e33a4b..356a308fce6 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -550,11 +550,11 @@ even if it is dead. The return value is never nil. */) | |||
| 550 | b->indirections = 0; | 550 | b->indirections = 0; |
| 551 | 551 | ||
| 552 | BUF_GAP_SIZE (b) = 20; | 552 | BUF_GAP_SIZE (b) = 20; |
| 553 | BLOCK_INPUT; | 553 | block_input (); |
| 554 | /* We allocate extra 1-byte at the tail and keep it always '\0' for | 554 | /* We allocate extra 1-byte at the tail and keep it always '\0' for |
| 555 | anchoring a search. */ | 555 | anchoring a search. */ |
| 556 | alloc_buffer_text (b, BUF_GAP_SIZE (b) + 1); | 556 | alloc_buffer_text (b, BUF_GAP_SIZE (b) + 1); |
| 557 | UNBLOCK_INPUT; | 557 | unblock_input (); |
| 558 | if (! BUF_BEG_ADDR (b)) | 558 | if (! BUF_BEG_ADDR (b)) |
| 559 | buffer_memory_full (BUF_GAP_SIZE (b) + 1); | 559 | buffer_memory_full (BUF_GAP_SIZE (b) + 1); |
| 560 | 560 | ||
| @@ -1923,7 +1923,7 @@ cleaning up all windows currently displaying the buffer to be killed. */) | |||
| 1923 | 1923 | ||
| 1924 | bset_name (b, Qnil); | 1924 | bset_name (b, Qnil); |
| 1925 | 1925 | ||
| 1926 | BLOCK_INPUT; | 1926 | block_input (); |
| 1927 | if (b->base_buffer) | 1927 | if (b->base_buffer) |
| 1928 | { | 1928 | { |
| 1929 | /* Notify our base buffer that we don't share the text anymore. */ | 1929 | /* Notify our base buffer that we don't share the text anymore. */ |
| @@ -1946,7 +1946,7 @@ cleaning up all windows currently displaying the buffer to be killed. */) | |||
| 1946 | b->width_run_cache = 0; | 1946 | b->width_run_cache = 0; |
| 1947 | } | 1947 | } |
| 1948 | bset_width_table (b, Qnil); | 1948 | bset_width_table (b, Qnil); |
| 1949 | UNBLOCK_INPUT; | 1949 | unblock_input (); |
| 1950 | bset_undo_list (b, Qnil); | 1950 | bset_undo_list (b, Qnil); |
| 1951 | 1951 | ||
| 1952 | /* Run buffer-list-update-hook. */ | 1952 | /* Run buffer-list-update-hook. */ |
| @@ -5032,7 +5032,7 @@ alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes) | |||
| 5032 | { | 5032 | { |
| 5033 | void *p; | 5033 | void *p; |
| 5034 | 5034 | ||
| 5035 | BLOCK_INPUT; | 5035 | block_input (); |
| 5036 | #if defined USE_MMAP_FOR_BUFFERS | 5036 | #if defined USE_MMAP_FOR_BUFFERS |
| 5037 | p = mmap_alloc ((void **) &b->text->beg, nbytes); | 5037 | p = mmap_alloc ((void **) &b->text->beg, nbytes); |
| 5038 | #elif defined REL_ALLOC | 5038 | #elif defined REL_ALLOC |
| @@ -5043,12 +5043,12 @@ alloc_buffer_text (struct buffer *b, ptrdiff_t nbytes) | |||
| 5043 | 5043 | ||
| 5044 | if (p == NULL) | 5044 | if (p == NULL) |
| 5045 | { | 5045 | { |
| 5046 | UNBLOCK_INPUT; | 5046 | unblock_input (); |
| 5047 | memory_full (nbytes); | 5047 | memory_full (nbytes); |
| 5048 | } | 5048 | } |
| 5049 | 5049 | ||
| 5050 | b->text->beg = (unsigned char *) p; | 5050 | b->text->beg = (unsigned char *) p; |
| 5051 | UNBLOCK_INPUT; | 5051 | unblock_input (); |
| 5052 | } | 5052 | } |
| 5053 | 5053 | ||
| 5054 | /* Enlarge buffer B's text buffer by DELTA bytes. DELTA < 0 means | 5054 | /* Enlarge buffer B's text buffer by DELTA bytes. DELTA < 0 means |
| @@ -5060,7 +5060,7 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta) | |||
| 5060 | void *p; | 5060 | void *p; |
| 5061 | ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1 | 5061 | ptrdiff_t nbytes = (BUF_Z_BYTE (b) - BUF_BEG_BYTE (b) + BUF_GAP_SIZE (b) + 1 |
| 5062 | + delta); | 5062 | + delta); |
| 5063 | BLOCK_INPUT; | 5063 | block_input (); |
| 5064 | #if defined USE_MMAP_FOR_BUFFERS | 5064 | #if defined USE_MMAP_FOR_BUFFERS |
| 5065 | p = mmap_realloc ((void **) &b->text->beg, nbytes); | 5065 | p = mmap_realloc ((void **) &b->text->beg, nbytes); |
| 5066 | #elif defined REL_ALLOC | 5066 | #elif defined REL_ALLOC |
| @@ -5071,12 +5071,12 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta) | |||
| 5071 | 5071 | ||
| 5072 | if (p == NULL) | 5072 | if (p == NULL) |
| 5073 | { | 5073 | { |
| 5074 | UNBLOCK_INPUT; | 5074 | unblock_input (); |
| 5075 | memory_full (nbytes); | 5075 | memory_full (nbytes); |
| 5076 | } | 5076 | } |
| 5077 | 5077 | ||
| 5078 | BUF_BEG_ADDR (b) = (unsigned char *) p; | 5078 | BUF_BEG_ADDR (b) = (unsigned char *) p; |
| 5079 | UNBLOCK_INPUT; | 5079 | unblock_input (); |
| 5080 | } | 5080 | } |
| 5081 | 5081 | ||
| 5082 | 5082 | ||
| @@ -5085,7 +5085,7 @@ enlarge_buffer_text (struct buffer *b, ptrdiff_t delta) | |||
| 5085 | static void | 5085 | static void |
| 5086 | free_buffer_text (struct buffer *b) | 5086 | free_buffer_text (struct buffer *b) |
| 5087 | { | 5087 | { |
| 5088 | BLOCK_INPUT; | 5088 | block_input (); |
| 5089 | 5089 | ||
| 5090 | #if defined USE_MMAP_FOR_BUFFERS | 5090 | #if defined USE_MMAP_FOR_BUFFERS |
| 5091 | mmap_free ((void **) &b->text->beg); | 5091 | mmap_free ((void **) &b->text->beg); |
| @@ -5096,7 +5096,7 @@ free_buffer_text (struct buffer *b) | |||
| 5096 | #endif | 5096 | #endif |
| 5097 | 5097 | ||
| 5098 | BUF_BEG_ADDR (b) = NULL; | 5098 | BUF_BEG_ADDR (b) = NULL; |
| 5099 | UNBLOCK_INPUT; | 5099 | unblock_input (); |
| 5100 | } | 5100 | } |
| 5101 | 5101 | ||
| 5102 | 5102 | ||