Author: zoltan
Date: 2007-12-25 18:40:47 -0500 (Tue, 25 Dec 2007)
New Revision: 91887

Modified:
   trunk/mono/mono/metadata/ChangeLog
   trunk/mono/mono/metadata/boehm-gc.c
Log:
2007-12-26  Zoltan Varga  <[EMAIL PROTECTED]>

        * boehm-gc.c (mono_gc_base_init): Moved the setting of GC_stackbottom 
here from
        mini.c.


Modified: trunk/mono/mono/metadata/ChangeLog
===================================================================
--- trunk/mono/mono/metadata/ChangeLog  2007-12-25 23:40:08 UTC (rev 91886)
+++ trunk/mono/mono/metadata/ChangeLog  2007-12-25 23:40:47 UTC (rev 91887)
@@ -1,5 +1,8 @@
 2007-12-26  Zoltan Varga  <[EMAIL PROTECTED]>
 
+       * boehm-gc.c (mono_gc_base_init): Moved the setting of GC_stackbottom 
here from
+       mini.c.
+
        * object.c (mono_class_compute_gc_descriptor): Move the 
GC_init_gcj_malloc () 
        call to boehm-gc.c.
 

Modified: trunk/mono/mono/metadata/boehm-gc.c
===================================================================
--- trunk/mono/mono/metadata/boehm-gc.c 2007-12-25 23:40:08 UTC (rev 91886)
+++ trunk/mono/mono/metadata/boehm-gc.c 2007-12-25 23:40:47 UTC (rev 91887)
@@ -23,6 +23,8 @@
 #include "private/pthread_support.h"
 #endif
 
+static gboolean gc_initialized = FALSE;
+
 static void
 mono_gc_warning (char *msg, GC_word arg)
 {
@@ -32,6 +34,59 @@
 void
 mono_gc_base_init (void)
 {
+       if (gc_initialized)
+               return;
+
+       /*
+        * Handle the case when we are called from a thread different from the 
main thread,
+        * confusing libgc.
+        * FIXME: Move this to libgc where it belongs.
+        *
+        * we used to do this only when running on valgrind,
+        * but it happens also in other setups.
+        */
+#if defined(HAVE_PTHREAD_GETATTR_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK)
+       {
+               size_t size;
+               void *sstart;
+               pthread_attr_t attr;
+               pthread_getattr_np (pthread_self (), &attr);
+               pthread_attr_getstack (&attr, &sstart, &size);
+               pthread_attr_destroy (&attr); 
+               /*g_print ("stackbottom pth is: %p\n", (char*)sstart + size);*/
+#ifdef __ia64__
+               /*
+                * The calculation above doesn't seem to work on ia64, also we 
need to set
+                * GC_register_stackbottom as well, but don't know how.
+                */
+#else
+               /* apparently with some linuxthreads implementations sstart can 
be NULL,
+                * fallback to the more imprecise method (bug# 78096).
+                */
+               if (sstart) {
+                       GC_stackbottom = (char*)sstart + size;
+               } else {
+                       int dummy;
+                       gsize stack_bottom = (gsize)&dummy;
+                       stack_bottom += 4095;
+                       stack_bottom &= ~4095;
+                       GC_stackbottom = (char*)stack_bottom;
+               }
+#endif
+       }
+#elif defined(HAVE_PTHREAD_GET_STACKSIZE_NP) && 
defined(HAVE_PTHREAD_GET_STACKADDR_NP)
+               GC_stackbottom = (char*)pthread_get_stackaddr_np (pthread_self 
());
+#else
+       {
+               int dummy;
+               gsize stack_bottom = (gsize)&dummy;
+               stack_bottom += 4095;
+               stack_bottom &= ~4095;
+               /*g_print ("stackbottom is: %p\n", (char*)stack_bottom);*/
+               GC_stackbottom = (char*)stack_bottom;
+       }
+#endif
+
        GC_init ();
        GC_no_dls = TRUE;
        GC_oom_fn = mono_gc_out_of_memory;
@@ -42,6 +97,8 @@
 #ifdef HAVE_GC_GCJ_MALLOC
        GC_init_gcj_malloc (5, NULL);
 #endif
+
+       gc_initialized = TRUE;
 }
 
 void

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to