Author: zoltan
Date: 2005-03-13 10:50:11 -0500 (Sun, 13 Mar 2005)
New Revision: 41761
Modified:
trunk/mono/mono/mini/ChangeLog
trunk/mono/mono/mini/mini-amd64.c
trunk/mono/mono/mini/mini-amd64.h
trunk/mono/mono/mini/mini-exceptions.c
trunk/mono/mono/mini/mini.c
Log:
2005-03-13 Zoltan Varga <[EMAIL PROTECTED]>
* mini.c (sigsegv_signal_handler): Fix reading of context.
* mini-exceptions.c: Fix up stack overflow handling.
* mini-amd64.h mini-amd64.c: Fix up stack overflow handling.
Modified: trunk/mono/mono/mini/ChangeLog
===================================================================
--- trunk/mono/mono/mini/ChangeLog 2005-03-13 14:38:48 UTC (rev 41760)
+++ trunk/mono/mono/mini/ChangeLog 2005-03-13 15:50:11 UTC (rev 41761)
@@ -1,5 +1,11 @@
2005-03-13 Zoltan Varga <[EMAIL PROTECTED]>
+ * mini.c (sigsegv_signal_handler): Fix reading of context.
+
+ * mini-exceptions.c: Fix up stack overflow handling.
+
+ * mini-amd64.h mini-amd64.c: Fix up stack overflow handling.
+
* tramp-amd64.c (create_specific_trampoline): Optimize trampoline size.
* exceptions-amd64.c (mono_amd64_exceptions_init): Remove this.
Modified: trunk/mono/mono/mini/mini-amd64.c
===================================================================
--- trunk/mono/mono/mini/mini-amd64.c 2005-03-13 14:38:48 UTC (rev 41760)
+++ trunk/mono/mono/mini/mini-amd64.c 2005-03-13 15:50:11 UTC (rev 41761)
@@ -13,6 +13,7 @@
#include "mini.h"
#include <string.h>
#include <math.h>
+#include <unistd.h>
#include <mono/metadata/appdomain.h>
#include <mono/metadata/debug-helpers.h>
@@ -5816,51 +5817,51 @@
return -1;
}
-void
-mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
+#ifdef MONO_ARCH_SIGSEGV_ON_ALTSTACK
+
+static void
+setup_stack (MonoJitTlsData *tls)
{
-#ifdef MONO_ARCH_SIGSEGV_ON_ALTSTACK
pthread_t self = pthread_self();
pthread_attr_t attr;
- void *staddr = NULL;
size_t stsize = 0;
struct sigaltstack sa;
-#endif
+ guint8 *staddr = NULL;
+ guint8 *current = (guint8*)&staddr;
- if (!tls_offset_inited) {
- tls_offset_inited = TRUE;
+ if (mono_running_on_valgrind ())
+ return;
- lmf_tls_offset = read_tls_offset_from_method
(mono_get_lmf_addr);
- appdomain_tls_offset = read_tls_offset_from_method
(mono_domain_get);
- //thread_tls_offset = read_tls_offset_from_method
(mono_thread_current);
- }
-
-#ifdef MONO_ARCH_SIGSEGV_ON_ALTSTACK
-
/* Determine stack boundaries */
- if (!mono_running_on_valgrind ()) {
#ifdef HAVE_PTHREAD_GETATTR_NP
- pthread_getattr_np( self, &attr );
+ pthread_getattr_np( self, &attr );
#else
#ifdef HAVE_PTHREAD_ATTR_GET_NP
- pthread_attr_get_np( self, &attr );
+ pthread_attr_get_np( self, &attr );
#elif defined(sun)
- pthread_attr_init( &attr );
- pthread_attr_getstacksize( &attr, &stsize );
+ pthread_attr_init( &attr );
+ pthread_attr_getstacksize( &attr, &stsize );
#else
#error "Not implemented"
#endif
#endif
#ifndef sun
- pthread_attr_getstack( &attr, &staddr, &stsize );
+ pthread_attr_getstack( &attr, (void**)&staddr, &stsize );
#endif
- }
- /*
- * staddr seems to be wrong for the main thread, so we keep the value in
- * tls->end_of_stack
+ g_assert (staddr);
+
+ g_assert ((current > staddr) && (current < staddr + stsize));
+
+ tls->end_of_stack = staddr + stsize;
+
+ /*
+ * threads created by nptl does not seem to have a guard page, and
+ * since the main thread is not created by us, we can't even set one.
+ * Increasing stsize fools the SIGSEGV signal handler into thinking this
+ * is a stack overflow exception.
*/
- tls->stack_size = stsize;
+ tls->stack_size = stsize + getpagesize ();
/* Setup an alternate signal stack */
tls->signal_stack = g_malloc (SIGNAL_STACK_SIZE);
@@ -5870,7 +5871,24 @@
sa.ss_size = SIGNAL_STACK_SIZE;
sa.ss_flags = SS_ONSTACK;
sigaltstack (&sa, NULL);
+}
+
#endif
+
+void
+mono_arch_setup_jit_tls_data (MonoJitTlsData *tls)
+{
+ if (!tls_offset_inited) {
+ tls_offset_inited = TRUE;
+
+ lmf_tls_offset = read_tls_offset_from_method
(mono_get_lmf_addr);
+ appdomain_tls_offset = read_tls_offset_from_method
(mono_domain_get);
+ //thread_tls_offset = read_tls_offset_from_method
(mono_thread_current);
+ }
+
+#ifdef MONO_ARCH_SIGSEGV_ON_ALTSTACK
+ setup_stack (tls);
+#endif
}
void
Modified: trunk/mono/mono/mini/mini-amd64.h
===================================================================
--- trunk/mono/mono/mini/mini-amd64.h 2005-03-13 14:38:48 UTC (rev 41760)
+++ trunk/mono/mono/mini/mini-amd64.h 2005-03-13 15:50:11 UTC (rev 41761)
@@ -191,13 +191,8 @@
#ifdef HAVE_WORKING_SIGALTSTACK
-/*
- * FIXME: For some reason, when sigaltstack is enabled, the uc_mcontext member
- * in ucontext_t is not at the offset indicated by the definition of
ucontext_t.
- */
+#define MONO_ARCH_SIGSEGV_ON_ALTSTACK
-//#define MONO_ARCH_SIGSEGV_ON_ALTSTACK
-
/* NetBSD doesn't define SA_STACK */
#ifndef SA_STACK
#define SA_STACK SA_ONSTACK
Modified: trunk/mono/mono/mini/mini-exceptions.c
===================================================================
--- trunk/mono/mono/mini/mini-exceptions.c 2005-03-13 14:38:48 UTC (rev
41760)
+++ trunk/mono/mono/mini/mini-exceptions.c 2005-03-13 15:50:11 UTC (rev
41761)
@@ -553,6 +553,7 @@
*/
if (obj == domain->stack_overflow_ex) {
obj = mono_get_exception_stack_overflow ();
+ stack_overflow = TRUE;
}
else if (obj == domain->null_reference_ex) {
obj = mono_get_exception_null_reference ();
@@ -565,9 +566,6 @@
mono_ex = NULL;
}
- if (obj == domain->stack_overflow_ex)
- stack_overflow = TRUE;
-
if (!call_filter)
call_filter = mono_arch_get_call_filter ();
@@ -658,7 +656,7 @@
/* catch block */
if ((ei->flags ==
MONO_EXCEPTION_CLAUSE_NONE) || (ei->flags == MONO_EXCEPTION_CLAUSE_FILTER)) {
- /* store the exception
object int cfg->excvar */
+ /* store the exception
object in cfg->excvar */
g_assert
(ei->exvar_offset);
*((gpointer *)((char
*)MONO_CONTEXT_GET_BP (ctx) + ei->exvar_offset)) = obj;
}
Modified: trunk/mono/mono/mini/mini.c
===================================================================
--- trunk/mono/mono/mini/mini.c 2005-03-13 14:38:48 UTC (rev 41760)
+++ trunk/mono/mono/mini/mini.c 2005-03-13 15:50:11 UTC (rev 41761)
@@ -9535,7 +9535,7 @@
{
MonoException *exc;
MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
- struct sigcontext *ctx = (struct sigcontext
*)&(((ucontext_t*)context)->uc_mcontext);
+ GET_CONTEXT
/* Can't allocate memory using Boehm GC on altstack */
if (jit_tls->stack_size &&
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches