Exception handling in gcc-3
Thomas Pfaff
tpfaff@gmx.net
Fri Nov 8 02:28:00 GMT 2002
Hi Danny,
i just had the time to look at the eh changes in gcc-3 for throwing
exceptions across DLL/EXE boundaries.
While the code works in 99% for cygwin and mingw it has one disadvantage
for cygwin: The atom name is lost after a fork.
See following example:
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <pthread.h>
#include <iostream>
using namespace std;
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define SHAREDPTR_LETTER0 'a'
#define SHAREDPTR_LETTER1 'A'
int main (void)
{
char s[sizeof(void*) * 8 + 1];
ATOM atom;
try
{
memset (s, SHAREDPTR_LETTER0, sizeof(void*) * 8);
s[sizeof(void*) * 8] = '\0';
switch (fork ())
{
case -1:
return 0;
case 0:
atom = FindAtomA (s);
throw "child";
default:
atom = FindAtomA (s);
throw "parent";
}
}
catch (const char *str)
{
char szAtom[16];
sprintf( szAtom, "0x%08x", (int) atom );
cout << "got " << str << "s exception, atom " << szAtom << endl;
}
catch (...)
{
cout << "got exception" << endl;
}
return 0;
}
If a dll is loaded dynamically after a fork the shared information is lost
and throwing exceptions from a dll does not work anymore.
For that reason i have created a different version that uses a shared
pointer that is contained in the cygwin1.dll, now it works in all test
cases. (And since i always link against libmingwthrd.a i added this
function to mthr.c too, but this is not applicable for all mingw users).
I have attached my code.
You may notice that i have moved 2 additional static vars in the shared
area (object_mutex and marker from unwind-dw2-fde.c) and that i have
modified the shared pointer allocation a bit.
Comments are welcome.
Thomas
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: eh_shared.c
URL: <http://cygwin.com/pipermail/cygwin-developers/attachments/20021108/b923cf02/attachment.c>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: w32-shared-ptr.c
URL: <http://cygwin.com/pipermail/cygwin-developers/attachments/20021108/b923cf02/attachment-0001.c>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: unwind.patch
URL: <http://cygwin.com/pipermail/cygwin-developers/attachments/20021108/b923cf02/attachment.ksh>
More information about the Cygwin-developers
mailing list