public inbox for insight@sourceware.org
 help / color / mirror / Atom feed
* MinGW setjmp SEGV
@ 2005-08-05 13:44 Andrew STUBBS
  2005-08-05 14:01 ` Dave Korn
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Andrew STUBBS @ 2005-08-05 13:44 UTC (permalink / raw)
  To: insight

[-- Attachment #1: Type: text/plain, Size: 1101 bytes --]

Hi,

I have been trying to build Insight 6.1 (patched into GDB 6.3) for MinGW  
(and Linux and Solaris but they weren't much trouble).

The problem I hit has been previously reported here:  
http://sources.redhat.com/ml/insight/2004-q1/msg00021.html.

There are a number of patches required to make it build, but most are  
trivial and may not be relevant since 6.1 so I shall not post them.  
Basically I had to check whether the cygwin filename-handling tcl  
functions exist before using them, define __INSIDE_CYGWIN__ in a couple of  
tcl/tk files, and rename the hooks because they now have a 'deprecated'  
prefix.

However, the most serious failure was caused by broken code in the tcl dll  
screwing up the SEH and causing setjmp to fail. This problem has been  
fixed in the latest tcl at tcl.sourceforge.net.

The attached patch (code copied from sourceforge) is sufficient to fix the  
issue. Note that I have included the diff of the whole file and it  
includes one of the minor changes mentioned above.

Hopefully this patch will help others who have hit the same problem.

Andrew Stubbs

[-- Attachment #2: insight-win.patch --]
[-- Type: application/octet-stream, Size: 5419 bytes --]

--- /view/stubbsa-import/vob/insight.cmp/src/tcl/win/tclWin32Dll.c	2005-08-05 14:21:03.000000000 +0100
+++ /view/stubbsa-import/vob/insight.cmp/src/tcl/win/tclWin32Dll.c@@/main/INSIGHT-6.1	2005-07-29 16:22:32.000000000 +0100
@@ -12,10 +12,6 @@
  * RCS: @(#) $Id: tclWin32Dll.c,v 1.16 2002/06/13 09:40:01 vincentdarley Exp $
  */
 
-/* The following is a workaround for a w32api problem.
-   See http://sources.redhat.com/ml/insight/2004-q4/msg00039.html */
-#define __INSIDE_CYGWIN__
-
 #include "tclWinInt.h"
 
 /*
@@ -42,23 +38,6 @@
 static int platformId;		/* Running under NT, or 95/98? */
 
 #ifdef HAVE_NO_SEH
-/*
- * Unlike Borland and Microsoft, we don't register exception handlers by
- * pushing registration records onto the runtime stack. Instead, we register
- * them by creating an EXCEPTION_REGISTRATION within the activation record.
- */
-
-typedef struct EXCEPTION_REGISTRATION {
-    struct EXCEPTION_REGISTRATION *link;
-    EXCEPTION_DISPOSITION (*handler)(
-	    struct _EXCEPTION_RECORD*, void*, struct _CONTEXT*, void*);
-    void *ebp;
-    void *esp;
-    int status;
-} EXCEPTION_REGISTRATION;
-#endif
-
-#ifdef HAVE_NO_SEH
 static void *ESP;
 static void *EBP;
 #endif /* HAVE_NO_SEH */
@@ -368,111 +347,65 @@
 int
 TclpCheckStackSpace()
 {
-
-#ifdef HAVE_NO_SEH
-    EXCEPTION_REGISTRATION registration;
-#endif
     int retval = 0;
 
     /*
-     * We can recurse only if there is at least TCL_WIN_STACK_THRESHOLD bytes
-     * of stack space left. alloca() is cheap on windows; basically it just
-     * subtracts from the stack pointer causing the OS to throw an exception
-     * if the stack pointer is set below the bottom of the stack.
+     * We can recurse only if there is at least TCL_WIN_STACK_THRESHOLD
+     * bytes of stack space left.  alloca() is cheap on windows; basically
+     * it just subtracts from the stack pointer causing the OS to throw an
+     * exception if the stack pointer is set below the bottom of the stack.
      */
 
 #ifdef HAVE_NO_SEH
     __asm__ __volatile__ (
+            "movl  %esp, _ESP" "\n\t"
+            "movl  %ebp, _EBP");
 
-	/*
-	 * Construct an EXCEPTION_REGISTRATION to protect the call to __alloca
-	 */
-
-	"leal	%[registration], %%edx"		"\n\t"
-	"movl	%%fs:0,		%%eax"		"\n\t"
-	"movl	%%eax,		0x0(%%edx)"	"\n\t" /* link */
-	"leal	1f,		%%eax"		"\n\t"
-	"movl	%%eax,		0x4(%%edx)"	"\n\t" /* handler */
-	"movl	%%ebp,		0x8(%%edx)"	"\n\t" /* ebp */
-	"movl	%%esp,		0xc(%%edx)"	"\n\t" /* esp */
-	"movl	%[error],	0x10(%%edx)"	"\n\t" /* status */
-	
-	/*
-	 * Link the EXCEPTION_REGISTRATION on the chain
-	 */
-
-	"movl	%%edx,		%%fs:0"		"\n\t"
-
-	/*
-	 * Attempt a call to __alloca, to determine whether there's sufficient
-	 * memory to be had.
-	 */
-
-	"movl	%[size],	%%eax"		"\n\t"
-	"pushl	%%eax"				"\n\t"
-	"call	__alloca"			"\n\t"
-
-	/*
-	 * Come here on a normal exit. Recover the EXCEPTION_REGISTRATION and
-	 * store a TCL_OK status
-	 */
-
-	"movl	%%fs:0,		%%edx"		"\n\t"
-	"movl	%[ok],		%%eax"		"\n\t"
-	"movl	%%eax,		0x10(%%edx)"	"\n\t"
-	"jmp	2f"				"\n"
-
-	/*
-	 * Come here on an exception. Get the EXCEPTION_REGISTRATION that we
-	 * previously put on the chain.
-	 */
-
-	"1:"					"\t"
-	"movl	%%fs:0,		%%edx"		"\n\t"
-	"movl	0x8(%%edx),	%%edx"		"\n\t"
-	
-	/* 
-	 * Come here however we exited. Restore context from the
-	 * EXCEPTION_REGISTRATION in case the stack is unbalanced.
-	 */
-	
-	"2:"					"\t"
-	"movl	0xc(%%edx),	%%esp"		"\n\t"
-	"movl	0x8(%%edx),	%%ebp"		"\n\t"
-	"movl	0x0(%%edx),	%%eax"		"\n\t"
-	"movl	%%eax,		%%fs:0"		"\n\t"
-	
-	:
-	/* No outputs */
-	:
-	[registration]	"m"	(registration),
-	[ok]		"i"	(TCL_OK),
-	[error]		"i"	(TCL_ERROR),
-	[size]		"i"	(TCL_WIN_STACK_THRESHOLD)
-	:
-	"%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"
-	);
-    retval = (registration.status == TCL_OK);
-
-#else /* !HAVE_NO_SEH */
-    __try {
-#ifdef HAVE_ALLOCA_GCC_INLINE
-	__asm__ __volatile__ (
-	    "movl  %0, %%eax" "\n\t"
-	    "call  __alloca" "\n\t"
-	    :
-	    : "i"(TCL_WIN_STACK_THRESHOLD)
-	    : "%eax");
+    __asm__ __volatile__ (
+            "pushl $__except_checkstackspace_handler" "\n\t"
+            "pushl %fs:0" "\n\t"
+            "mov   %esp, %fs:0");
 #else
+    __try {
+#endif /* HAVE_NO_SEH */
 	alloca(TCL_WIN_STACK_THRESHOLD);
-#endif /* HAVE_ALLOCA_GCC_INLINE */
 	retval = 1;
+#ifdef HAVE_NO_SEH
+    __asm__ __volatile__ (
+            "jmp   checkstackspace_pop" "\n"
+            "checkstackspace_reentry:" "\n\t"
+            "movl  _ESP, %esp" "\n\t"
+            "movl  _EBP, %ebp");
+
+    __asm__ __volatile__ (
+            "checkstackspace_pop:" "\n\t"
+            "mov   (%esp), %eax" "\n\t"
+            "mov   %eax, %fs:0" "\n\t"
+            "add   $8, %esp");
+#else
     } __except (EXCEPTION_EXECUTE_HANDLER) {}
 #endif /* HAVE_NO_SEH */
-    
+
+    /*
+     * Avoid using control flow statements in the SEH guarded block!
+     */
     return retval;
 }
-
+#ifdef HAVE_NO_SEH
+static
+__attribute__ ((cdecl))
+EXCEPTION_DISPOSITION
+_except_checkstackspace_handler(
+    struct _EXCEPTION_RECORD *ExceptionRecord,
+    void *EstablisherFrame,
+    struct _CONTEXT *ContextRecord,
+    void *DispatcherContext)
+{
+    __asm__ __volatile__ (
+            "jmp checkstackspace_reentry");
+    return 0; /* Function does not return */
+}
+#endif /* HAVE_NO_SEH */
 \f
 /*
  *----------------------------------------------------------------------

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2005-09-21 21:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-05 13:44 MinGW setjmp SEGV Andrew STUBBS
2005-08-05 14:01 ` Dave Korn
2005-08-05 14:40   ` Andrew STUBBS
2005-08-05 15:28     ` Dave Korn
2005-08-05 15:57       ` Andrew STUBBS
2005-08-05 16:35         ` Dave Korn
2005-08-05 21:43 ` Steven Johnson
2005-08-08  9:38   ` Andrew STUBBS
2005-09-21  2:25 ` Dave Murphy
2005-09-21  9:00   ` Andrew STUBBS
2005-09-21 21:25     ` Dave Murphy

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).