public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/9539: builtin [long/set]jmp not working properly with Windows signals
@ 2003-02-02 18:26 obry
  0 siblings, 0 replies; only message in thread
From: obry @ 2003-02-02 18:26 UTC (permalink / raw)
  To: gcc-gnats


>Number:         9539
>Category:       c
>Synopsis:       builtin [long/set]jmp not working properly with Windows signals
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Feb 02 18:26:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     obry@gnat.com
>Release:        GCC 2.8.1 and GCC 3.2.2
>Organization:
>Environment:
Windows NT/XP with:
  - MingW C compiler 3.2
  - C compiler coming with GNAT 3.x (GCC 2.8.1)
  - GCC 3.2.2
>Description:

A signal handler is not working properly the second time it is called. Look at the following program.

We install an exception handler. This handler will be triggered each time a signal is raised. In run() we explicitely read memory at address 0x0. This raise an exception access violation. This signal is captured the first time. The second time the program freeze somewhere in OS code...

Maybe there is some specific code to call before leaving the exception handler?
>How-To-Repeat:
Compile the following program and run it:
$ gcc -o code code.c
$ ./code

/* This program run fine if it uses the standard [set/long]jmp and freeze at
   the second signal if it uses the builtin version. 
*/

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

/* Just uncomment the following line to reproduce the bug
   If commented out, we use the OS [set/long]jmp and the program works as
   expected.
*/
#define BUILTIN

#ifdef BUILTIN
#define setjmp __builtin_setjmp
#define longjmp __builtin_longjmp
#else
#endif

static jmp_buf jb;

void
run (void)
{
  int *addr = 0x0;
  int a;

  {
    setjmp (jb);
    printf ("let's go\n"); fflush (stdout);

    /* let's raise an exception access violation */
    a = *addr;
  }
}

static LONG
error_handler (info)
     PEXCEPTION_POINTERS info;
{
  printf ("Error Handler\n"); fflush (stdout);

  longjmp (jb, 1);
  return EXCEPTION_CONTINUE_EXECUTION;
}

int
main (void)
{
  int *addr = 0x0;
  int a;

  printf ("Install error handler\n"); fflush (stdout);

  SetUnhandledExceptionFilter (error_handler);

  run();
}
>Fix:
No fix to propose.

I'd like to hear what you think about this.
>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-02-02 18:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-02 18:26 c/9539: builtin [long/set]jmp not working properly with Windows signals obry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).