Improve stack base detection on MS-Windows.
authorJean-Claude Beaudoin <jean.claude.beaudoin@gmail.com>
Sat, 3 Nov 2012 00:19:40 +0000 (20:19 -0400)
committerJean-Claude Beaudoin <jean.claude.beaudoin@gmail.com>
Sat, 3 Nov 2012 00:19:40 +0000 (20:19 -0400)
src/c/stacks.d
src/gc/os_dep.c

index 731a6ac..62ae874 100644 (file)
@@ -898,6 +898,9 @@ void mkcl_init_call_stack_overflow_area(MKCL, char * const stack_mark_address)
     char * stack_base = mbi.AllocationBase;
     mkcl_index stack_size = stack_top - stack_base;
 
+    if (mbi_size != sizeof(mbi))
+      mkcl_C_lose(env, "mkcl_init_call_stack_overflow_area() failed on VirtualQuery");
+
 # if 0
     printf("\ntid = %d, mbi info: BaseAddress = 0x%p, AllocationBase = 0x%p, RegionSize = %lu",
           (env->own_thread ? env->own_thread->thread.tid : 0),
index 9fffff6..bdcd971 100644 (file)
@@ -734,6 +734,8 @@ MK_GC_INNER word MK_GC_page_size = 0;
                             || (prot) == PAGE_WRITECOPY \
                             || (prot) == PAGE_EXECUTE_READWRITE \
                             || (prot) == PAGE_EXECUTE_WRITECOPY)
+
+#  if 1  /* "#if 0" for MKCL 1.2.0 and later, "#if 1" before. */
     /* Return the number of bytes that are writable starting at p.      */
     /* The pointer p is assumed to be page aligned.                     */
     /* If base is not 0, *base becomes the beginning of the             */
@@ -765,6 +767,24 @@ MK_GC_INNER word MK_GC_page_size = 0;
       sb -> mem_base = trunc_sp + size;
       return MK_GC_SUCCESS;
     }
+#  else
+    MK_GC_API int MK_GC_CALL MK_GC_get_stack_base(struct MK_GC_stack_base *sb)
+    { /* JCB */
+      word a_var = 0;
+      MEMORY_BASIC_INFORMATION mbi;
+
+      SIZE_T mbi_size = VirtualQuery(&a_var, &mbi, sizeof(mbi));
+
+      ptr_t stack_top = mbi.BaseAddress + mbi.RegionSize;
+      ptr_t stack_base = mbi.AllocationBase;
+      word stack_size = stack_top - stack_base;
+
+      if (mbi_size != sizeof(mbi)) ABORT("Weird VirtualQuery result");
+
+      sb -> mem_base = stack_top;
+      return MK_GC_SUCCESS;
+    }
+#  endif
 # else /* CYGWIN32 */
     /* An alternate version for Cygwin (adapted from Dave Korn's        */
     /* gcc version of boehm-gc).                                        */