This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c/9539: builtin [long/set]jmp not working properly with Windows signals


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]