From 3fd79bd70e9949cf38e890b38319d6fb084e5ee8 Mon Sep 17 00:00:00 2001 From: Rodrigo Kumpera Date: Fri, 30 May 2014 14:11:46 -0400 Subject: [PATCH] fix win thread size calc. --- mono/utils/mono-threads-windows.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mono/utils/mono-threads-windows.c b/mono/utils/mono-threads-windows.c index 605ebf58a76..2da72f92a94 100644 --- a/mono/utils/mono-threads-windows.c +++ b/mono/utils/mono-threads-windows.c @@ -190,6 +190,7 @@ __readfsdword (unsigned long offset) void mono_threads_core_get_stack_bounds (guint8 **staddr, size_t *stsize) { + MEMORY_BASIC_INFORMATION meminfo; #ifdef TARGET_AMD64 /* win7 apis */ NT_TIB* tib = (NT_TIB*)NtCurrentTeb(); @@ -201,9 +202,17 @@ mono_threads_core_get_stack_bounds (guint8 **staddr, size_t *stsize) guint8 *stackTop = (guint8*)*(int*)((char*)tib + 4); guint8 *stackBottom = (guint8*)*(int*)((char*)tib + 8); #endif + /* + Windows stacks are expanded on demand, one page at time. The TIB reports + only the currently allocated amount. + VirtualQuery will return the actual limit for the bottom, which is what we want. + */ + if (VirtualQuery (&meminfo, &meminfo, sizeof (meminfo)) == sizeof (meminfo)) + stackBottom = MIN (stackBottom, (guint8*)meminfo.AllocationBase); *staddr = stackBottom; *stsize = stackTop - stackBottom; + } gboolean -- 2.25.1