www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1999/08/28/23:16:09

Mailing-List: contact cygwin-developers-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-developers-unsubscribe-archive-cygwin-developers=delorie DOT com AT sourceware DOT cygnus DOT com>
List-Subscribe: <mailto:cygwin-developers-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin-developers/>
List-Post: <mailto:cygwin-developers AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-developers-help AT sourceware DOT cygnus DOT com>,
<http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-developers-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin-developers AT sourceware DOT cygnus DOT com
Message-Id: <199908290315.WAA14969@mercury.xraylith.wisc.edu>
To: Vadim Egorov <egorovv AT 1c DOT ru>
cc: "cygwin-developers AT sourceware DOT cygnus DOT com" <cygwin-developers AT sourceware DOT cygnus DOT com>
Subject: Re: longjmp problem
In-Reply-To: Your message of "Fri, 27 Aug 1999 13:40:03 +0400."
<37C65CF3 DOT 50E89A09 AT 1c DOT ru>
Date: Sat, 28 Aug 1999 22:15:25 -0500
From: Mumit Khan <khan AT xraylith DOT wisc DOT EDU>

Vadim Egorov <egorovv AT 1c DOT ru> writes:
> Hello,
> 
> There is a problem with setjmp/longjmp/signals/exceptions that can be
> demonstrated by the following code:
> 
> static jmp_buf	env;
> static sigset_t set = {0};
> 
> static void sig_handler(int sig)
> {
>     sigprocmask(SIG_UNBLOCK, &set, 0);
>     longjmp(env, sig);
> }
> 
> int main(int argc, char * * argv)
> {
>     sigaddset(&set, SIGSEGV);
> 
>     for ( int i = 0 ; i < 2; i++)
>     {
>         if ( setjmp(env) == 0 ) 
>         {
>             signal(SIGSEGV, ssig_handler);
>             printf("exception ...");
>             *(int*)0 = 1;
>         }
>         else
>         {
>             printf("trapped\n");
>         }
>     }
>     return 0;
> 
> }
> 
> It traps exception only once and than hangs. The problem seems to be in
> longjmp code. 

Interesting. It works every so often, and hangs the other times. strace
output shows that the signal is not being unblocked correctly, probably
due to the signal state not being restored correctly.

Almost the same behaviour I had writter earlier regarding FP exceptions.

I haven't tried your example under newer snapshots, so hopefully someone
else will try it out.

> If I load CRTDLL.DLL dynamically and use setjmp/longjmp from 
> there all works. I traced MS longjmp and noticed that it calls RtlUnwind 
> which seems do the trick.

This is of course dangerous since you're mixing runtimes, and anything
can happen. MSVCRT and CRTDLL provides two different setjmp/longjmp
pairs -- one "normal" that unwinds the stack to handle structure exceptions
and other with "ex" (you need to include setjmpex.h) that does not.

> In addition this code works on Linux without signal unblocking - it is
> necessary only if SIGSEGV is signaled by raise.

I have to go review the POSIX docs on this. I remember the issue of 
undefined behaviour if SEGV, FPE, etc are ignored if not raised by
software exception via raise() or kill(). But your code as far as I 
know is conforming and should work on POSIX systems.

Regards,
Mumit

- Raw text -


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