delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/12/19/10:30:43

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,SPF_SOFTFAIL
X-Spam-Check-By: sourceware.org
Message-ID: <4B2CF1A0.1060201@byu.net>
Date: Sat, 19 Dec 2009 08:30:40 -0700
From: Eric Blake <ebb9 AT byu DOT net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666
MIME-Version: 1.0
To: cygwin AT cygwin DOT com, mark AT maxrnd DOT com
Subject: Re: 2nd occurrence of signal not being handled?
References: <loom DOT 20091219T060807-696 AT post DOT gmane DOT org>
In-Reply-To: <loom.20091219T060807-696@post.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

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Mark Geisert on 12/18/2009 10:23 PM:
> 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);

Within this handler, SIGSEGV is still blocked.  Why?  because...

> }
> 
> int
> main()
> {
>     struct sigaction    sa;
> 
>     sa.sa_handler = segv_handler;
>     sa.sa_flags   = 0;

...you didn't request SA_NODEFER.  But calling siglongjmp from within the
handler only restores the original mask (and thus unblocking SIGSEGV), if...

>     sigemptyset(&sa.sa_mask);
> 
>     sigaction(SIGSEGV, &sa, NULL);
> 
>     switch(sigsetjmp(trapoline, 0)) {

...you call sigsetjmp with a non-zero savemask argument.  Therefore...

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

...when you get here, your signal mask still includes SIGSEGV...

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

...and causing a fault when SIGSEGV is blocked is fatal.  Meanwhile, it
didn't help that your program has undefined behavior: since you didn't
pass enough arguments to printf, the program is allowed to do whatever it
wants.

>             ++step;
> 
>         default:
>             printf("case %d reached\n", step);
>             break;
>     }
> 
>     return 0;
> }

And as far as I can tell, your problem is not cygwin-specific.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9 AT byu DOT net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkss8aAACgkQ84KuGfSFAYA1LgCggTQg11EsbFzySEz73JkNZLkM
/cAAoLsynutWk+vKcDY6OHzdGnj2/vDx
=FNAm
-----END PGP SIGNATURE-----

--
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