From d0cc770ddd6d60de01f58e7de080fffd2f051cd5 Mon Sep 17 00:00:00 2001 From: mdejong Date: Fri, 26 Dec 2003 04:14:38 +0000 Subject: * win/tkWin32Dll.c (DllMain): Add HAVE_NO_SEH blocks in place of __try and __except statements to support gcc builds. This is needed after David's changes on 2003-12-21. [Tcl patch 858493] --- ChangeLog | 7 ++++++ win/tkWin32Dll.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 121c350..2a623c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2003-12-25 Mo DeJong + + * win/tkWin32Dll.c (DllMain): Add HAVE_NO_SEH + blocks in place of __try and __except statements + to support gcc builds. This is needed after + David's changes on 2003-12-21. [Tcl patch 858493] + 2003-12-22 David Gravereaux * win/nmakehlp.c: diff --git a/win/tkWin32Dll.c b/win/tkWin32Dll.c index f5aa7ed..e02b5ea 100644 --- a/win/tkWin32Dll.c +++ b/win/tkWin32Dll.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkWin32Dll.c,v 1.7 2003/12/21 23:50:13 davygrvy Exp $ + * RCS: @(#) $Id: tkWin32Dll.c,v 1.8 2003/12/26 04:14:38 mdejong Exp $ */ #include "tkWinInt.h" @@ -93,7 +93,25 @@ DllMain(hInstance, reason, reserved) * condition. */ +#ifdef HAVE_NO_SEH +# ifdef TCL_MEM_DEBUG + __asm__ __volatile__ ( + "movl %%esp, %0" "\n\t" + "movl %%ebp, %1" "\n\t" + "movl %%fs:0, %2" "\n\t" + : "=m"(INITIAL_ESP), + "=m"(INITIAL_EBP), + "=r"(INITIAL_HANDLER) ); +# endif /* TCL_MEM_DEBUG */ + + __asm__ __volatile__ ( + "pushl %ebp" "\n\t" + "pushl $__except_dllmain_detach_handler" "\n\t" + "pushl %fs:0" "\n\t" + "movl %esp, %fs:0"); +#else __try { +#endif /* HAVE_NO_SEH */ /* * Run and remove our exit handlers, if they haven't already * been run. Just in case we are being unloaded prior to @@ -102,12 +120,64 @@ DllMain(hInstance, reason, reserved) */ TkFinalize(NULL); + +#ifdef HAVE_NO_SEH + __asm__ __volatile__ ( + "jmp dllmain_detach_pop" "\n" + "dllmain_detach_reentry:" "\n\t" + "movl %%fs:0, %%eax" "\n\t" + "movl 0x8(%%eax), %%esp" "\n\t" + "movl 0x8(%%esp), %%ebp" "\n" + "dllmain_detach_pop:" "\n\t" + "movl (%%esp), %%eax" "\n\t" + "movl %%eax, %%fs:0" "\n\t" + "add $12, %%esp" "\n\t" + : + : + : "%eax"); + +# ifdef TCL_MEM_DEBUG + __asm__ __volatile__ ( + "movl %%esp, %0" "\n\t" + "movl %%ebp, %1" "\n\t" + "movl %%fs:0, %2" "\n\t" + : "=m"(RESTORED_ESP), + "=m"(RESTORED_EBP), + "=r"(RESTORED_HANDLER) ); + + if (INITIAL_ESP != RESTORED_ESP) + Tcl_Panic("ESP restored incorrectly"); + if (INITIAL_EBP != RESTORED_EBP) + Tcl_Panic("EBP restored incorrectly"); + if (INITIAL_HANDLER != RESTORED_HANDLER) + Tcl_Panic("HANDLER restored incorrectly"); +# endif /* TCL_MEM_DEBUG */ +#else } __except (EXCEPTION_EXECUTE_HANDLER) { /* empty handler body */ } +#endif /* HAVE_NO_SEH */ break; } return TRUE; } +#ifdef HAVE_NO_SEH +static +__attribute__ ((cdecl)) +EXCEPTION_DISPOSITION +_except_dllmain_detach_handler( + struct _EXCEPTION_RECORD *ExceptionRecord, + void *EstablisherFrame, + struct _CONTEXT *ContextRecord, + void *DispatcherContext) +{ + __asm__ __volatile__ ( + "jmp dllmain_detach_reentry"); + /* Nuke compiler warning about unused static function */ + _except_dllmain_detach_handler(NULL, NULL, NULL, NULL); + return 0; /* Function does not return */ +} +#endif /* HAVE_NO_SEH */ + #endif /* !STATIC_BUILD */ -- cgit v0.12