delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/12/19/00:24:21

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=AWL,BAYES_00,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: 2nd occurrence of signal not being handled?
Date: Sat, 19 Dec 2009 05:23:42 +0000 (UTC)
Lines: 54
Message-ID: <loom.20091219T060807-696@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'm trying to get a larger application working but have an issue with signal
handling.  I've boiled the issue down to the STC below.  It causes two access
violations, only the first of which gets handled by the SIGSEGV signal handler
I've registered for the purpose.  The second access violation kills the program,
as if the handler were no longer registered.  Using diagnostic code not shown
I've made sure the handler is still registered, but somehow it's not being
called by Cygwin's internal fault handling.  Or maybe there's some subtle
mistake in my use of the signal functions.  Any advice would be appreciated.

..mark

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

volatile int    step = 0;
sigjmp_buf      trapoline;

void
segv_handler(int sig)
{
    printf("case %d: SIGSEGV handled\n", step++);
    siglongjmp(trapoline, step);
}

int
main()
{
    struct sigaction    sa;

    sa.sa_handler = segv_handler;
    sa.sa_flags   = 0;
    sigemptyset(&sa.sa_mask);

    sigaction(SIGSEGV, &sa, NULL);

    switch(sigsetjmp(trapoline, 0)) {
        case 0:
            printf("case %d reached\n", step);
            printf("case %d: %08X\n", *(int *) 42);
            ++step;

        case 1:
            printf("case %d reached\n", step);
            printf("case %d: %08X\n", *(int *) 42);
            ++step;

        default:
            printf("case %d reached\n", step);
            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