From b8d7d368c01d638f99f4569bfcb80dea976a9b6c Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Wed, 8 Jul 2015 01:22:23 +0300 Subject: [PATCH] Fix GC_get_stack_base if called before GC_init (Win32) (Apply part of commit db2b9f1 from 'racket_gc' branch.) * os_dep.c (GC_get_stack_base): Call GC_setpagesize if GC_page_size is not initialized (only if MSWIN32 but not CYGWIN32). --- os_dep.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/os_dep.c b/os_dep.c index 9128b169..b7adf5e6 100644 --- a/os_dep.c +++ b/os_dep.c @@ -749,10 +749,17 @@ GC_INNER word GC_page_size = 0; GC_API int GC_CALL GC_get_stack_base(struct GC_stack_base *sb) { - ptr_t trunc_sp = (ptr_t)((word)GC_approx_sp() & ~(GC_page_size - 1)); + ptr_t trunc_sp; + word size; + + /* Set page size if it is not ready (so client can use this */ + /* function even before GC is initialized). */ + if (!GC_page_size) GC_setpagesize(); + + trunc_sp = (ptr_t)((word)GC_approx_sp() & ~(GC_page_size - 1)); /* FIXME: This won't work if called from a deeply recursive */ /* client code (and the committed stack space has grown). */ - word size = GC_get_writable_length(trunc_sp, 0); + size = GC_get_writable_length(trunc_sp, 0); GC_ASSERT(size != 0); sb -> mem_base = trunc_sp + size; return GC_SUCCESS; -- 2.40.0