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;