[Openmcl-devel] signal(SIGFPE, SIG_IGN) problem?

Gary Byers gb at clozure.com
Tue Aug 27 01:15:52 UTC 2013


My (quaint and possibly antiquated) notion is that libraries have no
business deciding how applications handling signals, especially
if the application would do something other than terminate on receipt
of the signal.  (I'd try to make a more persuasive argument about this,
but the last several times that I've tried to do so I've paused midway
and started yelling at those kids to get off my lawn ...)

Regardless of whether one believes that libraries should override application
signal handling or not, it's not clear to me how ignoring SIGFPE affects 
attempts to do integer division by 0.  A little C program:

--------
/* Save as "div0.c".  Compile with
$ cc -m64 -g -O0 -o div0 div0.c
*/
#include <signal.h>

int
div(int x, int y)
{
   return x/y;
}

int
main()
{
   signal(SIGFPE, SIG_IGN);
   return div(1,0);
}
---------

will, when executed, loop forever on OSX and terminate abnormally on Linux.
(Things can behave differently at higher optimization levels; the intent of
the "-O0" option was to force an integer division by 0 to occur to see what
happened.)  I'm not sure what the intent of ignoring SIGFPE is supposed to
be:  ignoring integer-division-by-0 doesn't seem to do anything useful, and
most C programs run with true FP exceptions masked.

If you can't convince the author of this code to not change the handling of
SIGFPE (or can't do so without also asking them to get off your lawn), your
best bet may be to try to guard against that change as well as you can:

;;; Kids: don't try this at home!
(defun call-preserving-sigfpe-handling (thunk)
   (rlet ((action :sigaction))
     (#_sigaction #$SIGFPE (%null-ptr) action) ; get CCL's SIGFPE-handling info
     (unwind-protect
         (funcall thunk)
       (#_sigaction #$SIGFPE action (%null-ptr))))) ; restore CCL's handling of SIGFPE

? (call-preserving-sigfpe-handling (lambda () (open-shared-library ...)))




On Tue, 27 Aug 2013, Park SungMin wrote:

>
> dear, ccl-devs.
>
> I'm now working with libpd(https://github.com/libpd/libpd) ?
> libpd is C library for multimedia programming?
> libpd have this line?.(in "libpd_init" function?.)
>
> void libpd_init(void) {
>  signal(SIGFPE, SIG_IGN);
> 
> ?.
> ?
> }
>
> after execute that function??
> DIVISION-BY-ZERO code is not return.(C,Lisp both?)
>
> void sched_set_using_audio(int flag) {
> ?.
> return  44100*64/0;
> }
>
> before that function return INF(call in CCL use external-call)
> but after ?not return?that function. and (/ 10 0) is not return?
> (and servaral cocoa-api code not return...)
>
> maybe?this is not bug,just signal(SIGFPE, SIG_IGN) is crash in ccl?.right?
> in SBCL, LispWorks not problem(before/after execute signal function..)
>
> I find solution, avoid that problem?.
>
>
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel



More information about the Openmcl-devel mailing list