public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Daniel Barlow <dan@telent.net>
To: linux-kernel@vger.kernel.org
Subject: 2.4, arch-dependent floating point exception and trap handling
Date: Tue, 30 Jul 2002 14:06:57 +0100	[thread overview]
Message-ID: <873cu1nz4e.fsf@noetbook.telent.net> (raw)


I'm seeing discrepancies between the way that floating point
exceptions are handled on different architectures.  Briefly, I have a
program that uses the glibc function feenableexcept() to enable SIGFPE
on divide-by-zero errors, then installs a SIGFPE handler that uses
sigsetjmp/siglongjmp, then divides 1.0 by 0.0 twice.

What I expect to happen is for my signal handler to be called twice.
What actually happens varies:

On Alpha: 2.4.19-pre1-ac2, gcc version 2.95.4 20011002, PCA56 (SX164)

:; cc -o foo foo.c -lm -mieee
foo.c: In function `main':
foo.c:23: warning: assignment from incompatible pointer type
:; ./foo
exceptions enabled: 0
exceptions enabled: 40000
hello
in handler
abort
in handler
abort
terminating

- exactly as expected

On x86: 2.4.19-rc1, gcc version 2.95.4 20011002 , Pentium III (Coppermine)

my signal handler is called the first time, and then the second
attempt gets "inf".  I've run this under gdb as well; the second SIGFPE is 
not received by the process

:; gcc -o foo foo.c -lm
foo.c: In function `main':
foo.c:23: warning: assignment from incompatible pointer type
:; ./foo
exceptions enabled: 0
exceptions enabled: 4
hello
in handler
abort
a/b=inf
terminating


On PPC: 2.4.19-pre8, gcc version 2.95.4 20011002,  266MHz 740/750 rev 2.2
(tangerine iMac) I have x86-like behaviour

:; cc -o foo foo.c -lm
foo.c: In function `main':
foo.c:23: warning: assignment from incompatible pointer type
:; ./foo
exceptions enabled: 0
exceptions enabled: 4000000
hello
in handler
abort
a/b=inf
terminating

All of these are uniprocessor machines running uniprocessor kernels.
The behaviour I'd like _most_ is for the pre-signal environment to be
restored, but at least to get the same behaviour everywhere would be a
good thing.

I append the test program I've been using so you can tell me whether
my whole approach is misguided

---cut here---
#include <signal.h>
#include <stdio.h>
#include <sys/signal.h>
#include <ucontext.h>
#include <fenv.h>
#include <setjmp.h>

sigjmp_buf env;
double a=1.0,b=0.0;

int handler(int signal, struct siginfo *info, struct ucontext *context) {
    printf("in handler\n");
    siglongjmp(env,signal);
}

main() {
    struct sigaction sa;

    a=1.0;
    printf("exceptions enabled: %x\n", fegetexcept());
    feenableexcept(FE_DIVBYZERO);   
    printf("exceptions enabled: %x\n", fegetexcept());
    sa.sa_sigaction = handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_SIGINFO | SA_RESTART;
    sigaction(SIGFPE, &sa, NULL); 
    printf("hello\n");
    /* first time */
    if(sigsetjmp(env,1)) printf("abort\n");
    else                 printf("a/b=%f\n", a/b);

    /* now try again, see if things were restored */
    if(sigsetjmp(env,1)) printf("abort\n");
    else                 printf("a/b=%f\n", a/b);
    printf("terminating\n");
}

--- cut here ---

If this message should have been sent elsewhere (e.g. to port-specific
lists or maintainers) please feel free to tell me where and/or to
forward it.

Thanks!


-dan

-- 

  http://ww.telent.net/cliki/ - Link farm for free CL-on-Unix resources 

             reply	other threads:[~2002-07-30 13:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-30 13:06 Daniel Barlow [this message]
2002-07-31 12:47 ` 2.4, arch-dependent floating point exception and trap handling Anton Blanchard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=873cu1nz4e.fsf@noetbook.telent.net \
    --to=dan@telent.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox