public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Danny Smith <dannysmith@clear.net.nz>
To: gcc@gcc.gnu.org
Cc: Cygwin <cygwin@cygwin.com>,
	mingw-dvlpr <mingw-dvlpr@lists.sourceforge.net>
Subject: stdcall lib functions with exception throwing callbacks vs Dwarf2 EH
Date: Tue, 23 Nov 2004 22:41:00 -0000	[thread overview]
Message-ID: <001701c4d1ab$949322e0$0a6d65da@DANNY> (raw)

Hi, 
I've been trying to get DW2 EH exception handling working
on windows targets with general success, but have hit a snag.

If a C library function that takes a callback arg is compiled
using stdcall convention, C++ exception thrown by the callback
result in abort.

If the C libarary function uses normal (cdelc) calling convention
than exceptions thrown by callback are handled.

Example:



==============================================
/* callback.c  library functions */
/* compile this with c */

void
caller_c (void (*callback)(void))
{
  callback();
}


void __attribute__((stdcall))
caller_s (void (*callback)(void))
{
  callback();
}

==============================================

/* main.cc */
#include <stdio.h>
extern "C"
{
  typedef void (*foo)(void);
  extern void  caller_c (foo); 
  extern void __attribute__ ((__stdcall__)) caller_s (foo);  
}

void callback (void) 
{
  printf ("Hello from callback\n");
  fflush (stdout);  
  throw 1;
}


int main ()
{
  try {
    printf ("Testing cdecl\n");
    caller_c (callback);
  }
  catch (int) {
    printf ("Caught cdecl\n"); 
  }

  try {
    printf ("\nTesting stdcall\n");
    caller_s (callback);
  }
  catch (int) {
    printf ("Caught stdcall\n");
  }

return 0;
}

==================================================

Compiling with sjlj enabled compiler:

gcc -c -o callback.o callback.c
g++-sjlj -o main-sjlj.exe main.cc callback.o

Both throws are caught.

However, if using DW2 EH enabled compiler

g++-dw2 -omain-dw2.exe main.cc callback.o

I get this:

> Testing cdecl
> Hello from callback
> Caught cdecl

> Testing stdcall
> Hello from callback
>
> abnormal program termination.


This is significant for windows targets, since the
OS win32 api uses stdcall almost exclusively.

Before I pull any more hair out trying, does any one have any hints on
how to use an MD_FALLBACK_FRAME_STATE_FOR to workaround, or is this a
blocker for the use of DW2 EH on windows targets.

Danny

             reply	other threads:[~2004-11-23 22:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-23 22:41 Danny Smith [this message]
2004-11-24  0:47 ` Richard Henderson
2004-11-24  7:08   ` Ranjit Mathew
2004-11-24  8:08   ` Danny Smith
2004-11-24  8:26     ` Richard Henderson
2004-11-24  9:41       ` Aaron W. LaFramboise
2004-11-24 17:40         ` Richard Henderson
2004-11-24 18:19           ` Andrew Haley
2004-11-24  8:40   ` Danny Smith
2004-11-24 19:00     ` Richard Henderson
2004-11-24 19:57       ` Andrew Pinski
2004-11-24 20:02         ` Richard Henderson
2004-11-24 21:23       ` Danny Smith
2004-11-24  6:34 ` Aaron W. LaFramboise
2004-11-24  6:58   ` Christopher Faylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='001701c4d1ab$949322e0$0a6d65da@DANNY' \
    --to=dannysmith@clear.net.nz \
    --cc=cygwin@cygwin.com \
    --cc=dannysmith@users.sourceforge.net \
    --cc=gcc@gcc.gnu.org \
    --cc=mingw-dvlpr@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).