delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/09/17/15:46:54

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_66,SPF_HELO_PASS,SPF_PASS
X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Mark Geisert <mark AT maxrnd DOT com>
Subject: I want my FPE!
Date: Thu, 17 Sep 2009 19:46:15 +0000 (UTC)
Lines: 54
Message-ID: <loom.20090917T213422-417@post.gmane.org>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

I would like to get control when floating-point exceptions occur, but the simple
approach doesn't seem to work; see the STC below.  It shows SIGSEGV can be
trapped but not SIGFPE.  In another experiment I tried extending libsigsegv to
handle FP exceptions but got the same results.

Is there something I need to do to "condition" the Cygwin environment to
generate FP exceptions?  I saw the code in winsup/something/or/other to map x86
FP exceptions to SIGFPE but it seems somehow the exceptions aren't being
generated in the first place.
Thanks much,

..mark

#include <setjmp.h>
#include <signal.h>
#include <stdio.h>

jmp_buf trapoline;

void segv_handler(int x)
{
    puts("SIGSEGV handled, continuing");
    longjmp(trapoline, 1);
}

void fpe_handler(int x)
{
    puts("SIGFPE handled, continuing");
    longjmp(trapoline, 2);
}

int main()
{
    signal(SIGSEGV, segv_handler);
    signal(SIGFPE, fpe_handler);

    switch(setjmp(trapoline)) {
        case 0:
            // first, force a SIGSEGV
            printf("%X\n", *(int *) 42);
            break;

        case 1:
            // second, force a SIGFPE
            printf("%f\n", 1E200 * 1E200);
            break;

        case 2:
            // all done
            break;
    }

    return 0;
}


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019