summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormdejong <mdejong>2004-10-28 20:11:20 (GMT)
committermdejong <mdejong>2004-10-28 20:11:20 (GMT)
commit0ccfc6f18ee6f98aa2fc15b62a3c482dd8b927f6 (patch)
tree9bb49317eeb43485136c3d94e429cce9a543f9e0
parent92a4dd618e3ce6574420a66f92fa1c4f53edefb3 (diff)
downloadtk-0ccfc6f18ee6f98aa2fc15b62a3c482dd8b927f6.zip
tk-0ccfc6f18ee6f98aa2fc15b62a3c482dd8b927f6.tar.gz
tk-0ccfc6f18ee6f98aa2fc15b62a3c482dd8b927f6.tar.bz2
* win/tkWin32Dll.c (DllMain, _except_dllmain_detach_handler):
Back port HAVE_NO_SEH handler code from CVS HEAD to fix gcc build breakage caused by 2004-10-26 back port.
-rw-r--r--ChangeLog6
-rw-r--r--win/tkWin32Dll.c121
2 files changed, 126 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index d1fcd12..8354bd4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2004-10-28 Mo DeJong <mdejong@users.sourceforge.net>
+
+ * win/tkWin32Dll.c (DllMain, _except_dllmain_detach_handler):
+ Back port HAVE_NO_SEH handler code from CVS HEAD to fix
+ gcc build breakage caused by 2004-10-26 back port.
+
2004-10-28 Don Porter <dgp@users.sourceforge.net>
* README: Bumped to patch level 8.4.8
diff --git a/win/tkWin32Dll.c b/win/tkWin32Dll.c
index fde647b..bf9ba29 100644
--- a/win/tkWin32Dll.c
+++ b/win/tkWin32Dll.c
@@ -8,18 +8,52 @@
* 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.6.2.1 2004/10/27 00:37:38 davygrvy Exp $
+ * RCS: @(#) $Id: tkWin32Dll.c,v 1.6.2.2 2004/10/28 20:11:20 mdejong Exp $
*/
#include "tkWinInt.h"
#ifndef STATIC_BUILD
+#if defined(HAVE_NO_SEH) && defined(TCL_MEM_DEBUG)
+static void *INITIAL_ESP,
+ *INITIAL_EBP,
+ *INITIAL_HANDLER,
+ *RESTORED_ESP,
+ *RESTORED_EBP,
+ *RESTORED_HANDLER;
+#endif /* HAVE_NO_SEH && TCL_MEM_DEBUG */
+
+#ifdef HAVE_NO_SEH
+static
+__attribute__ ((cdecl))
+EXCEPTION_DISPOSITION
+_except_dllmain_detach_handler(
+ struct _EXCEPTION_RECORD *ExceptionRecord,
+ void *EstablisherFrame,
+ struct _CONTEXT *ContextRecord,
+ void *DispatcherContext);
+#endif /* HAVE_NO_SEH */
+
+#ifdef HAVE_NO_SEH
+
+/* Need to add noinline flag to DllMain declaration so that gcc -O3
+ * does not inline asm code into DllEntryPoint and cause a
+ * compile time error because of redefined local labels.
+ */
+
+BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason,
+ LPVOID reserved)
+ __attribute__ ((noinline));
+
+#else
+
/*
* The following declaration is for the VC++ DLL entry point.
*/
BOOL WINAPI DllMain _ANSI_ARGS_((HINSTANCE hInst,
DWORD reason, LPVOID reserved));
+#endif /* HAVE_NO_SEH */
/*
*----------------------------------------------------------------------
@@ -93,7 +127,27 @@ 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 %0" "\n\t"
+ "pushl %%fs:0" "\n\t"
+ "movl %%esp, %%fs:0"
+ :
+ : "r" (_except_dllmain_detach_handler) );
+#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,11 +156,76 @@ 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;
}
+/*
+ *----------------------------------------------------------------------
+ *
+ * _except_dllmain_detach_handler --
+ *
+ * SEH exception handler for DllMain.
+ *
+ * Results:
+ * See DllMain.
+ *
+ * Side effects:
+ * See DllMain.
+ *
+ *----------------------------------------------------------------------
+ */
+#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");
+ return 0; /* Function does not return */
+}
+#endif /* HAVE_NO_SEH */
+
#endif /* !STATIC_BUILD */