From c4c7111cd3749b65b78b2b0255d49ab0d7874e13 Mon Sep 17 00:00:00 2001 From: Suraj N. Kurapati Date: Sat, 24 Oct 2009 20:55:11 -0700 Subject: [PATCH] add ruby_bind_stack() to inform GC about explicit stack boundaries --- gc.c | 18 ++++++++++++++++++ include/ruby/ruby.h | 1 + 2 files changed, 19 insertions(+), 0 deletions(-) diff --git a/gc.c b/gc.c index ddfe39b..798cbd9 100644 --- a/gc.c +++ b/gc.c @@ -2088,6 +2088,16 @@ obj_free(rb_objspace_t *objspace, VALUE obj) void rb_vm_mark(void *ptr); +static VALUE *ruby_gc_stack_lower = 0, + *ruby_gc_stack_upper = 0; + +void +ruby_bind_stack(VALUE *lower, VALUE *upper) +{ + ruby_gc_stack_lower = lower; + ruby_gc_stack_upper = upper; +} + static void mark_current_machine_context(rb_objspace_t *objspace, rb_thread_t *th) { @@ -2120,6 +2130,14 @@ mark_current_machine_context(rb_objspace_t *objspace, rb_thread_t *th) (VALUE*)save_regs_gc_mark, sizeof(save_regs_gc_mark) / sizeof(VALUE)); + if (ruby_gc_stack_upper && stack_end > ruby_gc_stack_upper) { + stack_end = ruby_gc_stack_upper; + } + + if (ruby_gc_stack_lower && stack_start < ruby_gc_stack_lower) { + stack_end = ruby_gc_stack_lower; + } + rb_gc_mark_locations(stack_start, stack_end); #ifdef __ia64 rb_gc_mark_locations(th->machine_register_stack_start, th->machine_register_stack_end); diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 19f146e..8001a18 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1138,6 +1138,7 @@ void ruby_init_stack(volatile VALUE*); #define RUBY_INIT_STACK \ VALUE variable_in_this_stack_frame; \ ruby_init_stack(&variable_in_this_stack_frame); +void ruby_bind_stack(VALUE *lower, VALUE *upper); void ruby_init(void); void *ruby_options(int, char**); int ruby_run_node(void *); -- 1.6.5.1