Implement the calculation of stack bounds on windows. Fixes #11624.
authorZoltan Varga <vargaz@gmail.com>
Sat, 6 Apr 2013 08:05:28 +0000 (10:05 +0200)
committerZoltan Varga <vargaz@gmail.com>
Sat, 6 Apr 2013 08:05:28 +0000 (10:05 +0200)
mono/metadata/icall.c
mono/metadata/threads.c

index 2388fbc4d93540090982a03641a218b5e1667aea..72ff703939f9d524355d79c9c9159166b054b95b 100644 (file)
@@ -4853,6 +4853,7 @@ ves_icall_System_Reflection_Assembly_GetExecutingAssembly (void)
        MONO_ARCH_SAVE_REGS;
 
        mono_stack_walk_no_il (get_executing, &dest);
+       g_assert (dest);
        return mono_assembly_get_object (mono_domain_get (), dest->klass->image->assembly);
 }
 
index 443744595d84f1a2d6aedcb887600cfa2b40ab67..6d582f15e859dfc08c92ce17d498647ed17eb823 100644 (file)
@@ -816,10 +816,22 @@ mono_thread_get_stack_bounds (guint8 **staddr, size_t *stsize)
        *staddr = (guint8*)((gssize)*staddr & ~(mono_pagesize () - 1));
        return;
        /* FIXME: simplify the mess below */
-#elif !defined(HOST_WIN32)
+#elif defined(HOST_WIN32)
+       /* http://en.wikipedia.org/wiki/Win32_Thread_Information_Block */
+       void* tib = (void*)__readfsdword(0x18);
+       guint8 *stackTop = (guint8*)*(int*)((char*)tib + 4);
+       guint8 *stackBottom = (guint8*)*(int*)((char*)tib + 8);
+
+       *staddr = stackBottom;
+       *stsize = stackTop - stackBottom;
+       return;
+#else
        pthread_attr_t attr;
        guint8 *current = (guint8*)&attr;
 
+       *staddr = NULL;
+       *stsize = (size_t)-1;
+
        pthread_attr_init (&attr);
 #  ifdef HAVE_PTHREAD_GETATTR_NP
        pthread_getattr_np (pthread_self(), &attr);
@@ -854,9 +866,6 @@ mono_thread_get_stack_bounds (guint8 **staddr, size_t *stsize)
 #  endif
 
        pthread_attr_destroy (&attr);
-#else
-       *staddr = NULL;
-       *stsize = (size_t)-1;
 #endif
 
        /* When running under emacs, sometimes staddr is not aligned to a page size */