diff options
| author | Paul Eggert | 2012-09-05 14:33:53 -0700 |
|---|---|---|
| committer | Paul Eggert | 2012-09-05 14:33:53 -0700 |
| commit | 20ef56dbc88f517ebf60d89577fc89870d9fe888 (patch) | |
| tree | e93c0bc49e89e86836575b2b4443c699a237621d /src/floatfns.c | |
| parent | a4e6c042f8f66c47209d76d863adbf5ea3f84a96 (diff) | |
| download | emacs-20ef56dbc88f517ebf60d89577fc89870d9fe888.tar.gz emacs-20ef56dbc88f517ebf60d89577fc89870d9fe888.zip | |
Fix race conditions with signal handlers and errno.
Be more systematic about preserving errno whenever a signal
handler returns, even if it's not in the main thread. Do this by
renaming signal handlers to distinguish between signal delivery
and signal handling. All uses changed.
* atimer.c (deliver_alarm_signal): Rename from alarm_signal_handler.
* data.c (deliver_arith_signal): Rename from arith_error.
* dispnew.c (deliver_window_change_signal): Rename from
window_change_signal.
* emacs.c (deliver_error_signal): Rename from fatal_error_signal.
(deliver_danger_signal) [SIGDANGER]: Rename from memory_warning_signal.
* keyboard.c (deliver_input_available_signal): Rename from
input_available_signal.
(deliver_user_signal): Rename from handle_user_signal.
(deliver_interrupt_signal): Rename from interrupt_signal.
* process.c (deliver_pipe_signal): Rename from send_process_trap.
(deliver_child_signal): Rename from sigchld_handler.
* atimer.c (handle_alarm_signal):
* data.c (handle_arith_signal):
* dispnew.c (handle_window_change_signal):
* emacs.c (handle_fatal_signal, handle_danger_signal):
* keyboard.c (handle_input_available_signal):
* keyboard.c (handle_user_signal, handle_interrupt_signal):
* process.c (handle_pipe_signal, handle_child_signal):
New functions, with the actual signal-handling code taken from the
original respective signal handlers, sans the sporadic attempts to
preserve errno, since that's now done by handle_on_main_thread.
* atimer.c (alarm_signal_handler): Remove unnecessary decl.
* emacs.c, floatfns.c, lisp.h: Remove unused FLOAT_CATCH_SIGKILL cruft.
* emacs.c (main_thread) [FORWARD_SIGNAL_TO_MAIN_THREAD]:
Move to sysdep.c.
(main) [FORWARD_SIGNAL_TO_MAIN_THREAD]:
Move initialization of main_thread to sysdep.c's init_signals.
* process.c (waitpid) [!WNOHANG]: #define to wait; that's good enough for
our usage, and simplifies the mainline code.
(record_child_status_change): New static function, as a helper
for handle_child_signal, and with most of the old child handler's
contents.
(CAN_HANDLE_MULTIPLE_CHILDREN): New constant.
(handle_child_signal): Use the above.
* sysdep.c (main_thread) [FORWARD_SIGNAL_TO_MAIN_THREAD]:
Moved here from emacs.c.
(init_signals) [FORWARD_SIGNAL_TO_MAIN_THREAD]: Initialize it;
code moved here from emacs.c's main function.
* sysdep.c, syssignal.h (handle_on_main_thread): New function,
replacing the old SIGNAL_THREAD_CHECK. All uses changed. This
lets callers save and restore errno properly.
Diffstat (limited to 'src/floatfns.c')
| -rw-r--r-- | src/floatfns.c | 35 |
1 files changed, 0 insertions, 35 deletions
diff --git a/src/floatfns.c b/src/floatfns.c index 706fe7ae1a0..f59cf58228a 100644 --- a/src/floatfns.c +++ b/src/floatfns.c | |||
| @@ -37,9 +37,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 37 | Define FLOAT_CHECK_ERRNO if the float library routines set errno. | 37 | Define FLOAT_CHECK_ERRNO if the float library routines set errno. |
| 38 | This has no effect if HAVE_MATHERR is defined. | 38 | This has no effect if HAVE_MATHERR is defined. |
| 39 | 39 | ||
| 40 | Define FLOAT_CATCH_SIGILL if the float library routines signal SIGILL. | ||
| 41 | (What systems actually do this? Please let us know.) | ||
| 42 | |||
| 43 | Define FLOAT_CHECK_DOMAIN if the float library doesn't handle errors by | 40 | Define FLOAT_CHECK_DOMAIN if the float library doesn't handle errors by |
| 44 | either setting errno, or signaling SIGFPE/SIGILL. Otherwise, domain and | 41 | either setting errno, or signaling SIGFPE/SIGILL. Otherwise, domain and |
| 45 | range checking will happen before calling the float routines. This has | 42 | range checking will happen before calling the float routines. This has |
| @@ -99,10 +96,6 @@ extern double logb (double); | |||
| 99 | # include <errno.h> | 96 | # include <errno.h> |
| 100 | #endif | 97 | #endif |
| 101 | 98 | ||
| 102 | #ifdef FLOAT_CATCH_SIGILL | ||
| 103 | static void float_error (); | ||
| 104 | #endif | ||
| 105 | |||
| 106 | /* True while executing in floating point. | 99 | /* True while executing in floating point. |
| 107 | This tells float_error what to do. */ | 100 | This tells float_error what to do. */ |
| 108 | 101 | ||
| @@ -947,31 +940,6 @@ Rounds the value toward zero. */) | |||
| 947 | return make_float (d); | 940 | return make_float (d); |
| 948 | } | 941 | } |
| 949 | 942 | ||
| 950 | #ifdef FLOAT_CATCH_SIGILL | ||
| 951 | static void | ||
| 952 | float_error (int signo) | ||
| 953 | { | ||
| 954 | if (! in_float) | ||
| 955 | fatal_error_signal (signo); | ||
| 956 | |||
| 957 | #ifdef BSD_SYSTEM | ||
| 958 | sigsetmask (SIGEMPTYMASK); | ||
| 959 | #else | ||
| 960 | /* Must reestablish handler each time it is called. */ | ||
| 961 | signal (SIGILL, float_error); | ||
| 962 | #endif /* BSD_SYSTEM */ | ||
| 963 | |||
| 964 | SIGNAL_THREAD_CHECK (signo); | ||
| 965 | in_float = 0; | ||
| 966 | |||
| 967 | xsignal1 (Qarith_error, float_error_arg); | ||
| 968 | } | ||
| 969 | |||
| 970 | /* Another idea was to replace the library function `infnan' | ||
| 971 | where SIGILL is signaled. */ | ||
| 972 | |||
| 973 | #endif /* FLOAT_CATCH_SIGILL */ | ||
| 974 | |||
| 975 | #ifdef HAVE_MATHERR | 943 | #ifdef HAVE_MATHERR |
| 976 | int | 944 | int |
| 977 | matherr (struct exception *x) | 945 | matherr (struct exception *x) |
| @@ -1006,9 +974,6 @@ matherr (struct exception *x) | |||
| 1006 | void | 974 | void |
| 1007 | init_floatfns (void) | 975 | init_floatfns (void) |
| 1008 | { | 976 | { |
| 1009 | #ifdef FLOAT_CATCH_SIGILL | ||
| 1010 | signal (SIGILL, float_error); | ||
| 1011 | #endif | ||
| 1012 | in_float = 0; | 977 | in_float = 0; |
| 1013 | } | 978 | } |
| 1014 | 979 | ||