Project

General

Profile

Feature #2294 ยป ruby_bind_stack_after_refactoring.patch

sunaku (Suraj Kurapati), 10/31/2009 02:25 PM

View differences:

ChangeLog
313 313

  
314 314
Mon Oct 25 13:28:00 2009  Suraj N. Kurapati <sunaku@gmail.com>
315 315

  
316
	* include/ruby/ruby.h: declare ruby_bind_stack(). [ruby-core:26361]
317

  
318
	* gc.c: implement ruby_bind_stack().  restrict GC marking
319
	  region to ruby_bind_stack() boundaries for main thread.
320

  
321
Mon Oct 25 13:28:00 2009  Suraj N. Kurapati <sunaku@gmail.com>
322

  
316 323
	* gc.c: refactor common code from mark_current_machine_context()
317 324
	  and rb_gc_mark_machine_stack() into get_machine_stack_bounds().
318 325

  
gc.c
19 19
#include "eval_intern.h"
20 20
#include "vm_core.h"
21 21
#include "gc.h"
22
#include <assert.h>
22 23
#include <stdio.h>
23 24
#include <setjmp.h>
24 25
#include <sys/types.h>
......
2089 2090

  
2090 2091
void rb_vm_mark(void *ptr);
2091 2092

  
2093
static VALUE *ruby_stack_lower_bound = 0,
2094
             *ruby_stack_upper_bound = 0;
2095

  
2096
void
2097
ruby_bind_stack(void *lower, void *upper)
2098
{
2099
    assert(upper > lower);
2100
    ruby_stack_lower_bound = lower;
2101
    ruby_stack_upper_bound = upper;
2102
}
2103

  
2092 2104
static void
2093 2105
get_machine_stack_bounds(rb_thread_t *th, VALUE **stack_start, VALUE **stack_end, unsigned stack_end_increment)
2094 2106
{
......
2108 2120
        *stack_end = th->machine_stack_end + stack_end_increment;
2109 2121
    }
2110 2122
#endif
2123

  
2124
    if (th == th->vm->main_thread) {
2125
        if (ruby_stack_lower_bound && *stack_start < ruby_stack_lower_bound) {
2126
          *stack_start = ruby_stack_lower_bound;
2127
        }
2128

  
2129
        if (ruby_stack_upper_bound && *stack_end > ruby_stack_upper_bound) {
2130
          *stack_end = ruby_stack_upper_bound;
2131
        }
2132
    }
2111 2133
}
2112 2134

  
2113 2135
static void
include/ruby/ruby.h
1143 1143
#define RUBY_INIT_STACK \
1144 1144
    VALUE variable_in_this_stack_frame; \
1145 1145
    ruby_init_stack(&variable_in_this_stack_frame);
1146
/*
1147
 * Binds Ruby's stack to the region of memory that spans from the given
1148
 * "lower" boundary up to (but not including) the given "upper" boundary.
1149
 * Note that these boundaries _do not_ protect against stack overflow!
1150
 */
1151
void ruby_bind_stack(void *lower, void *upper);
1146 1152
void ruby_init(void);
1147 1153
void *ruby_options(int, char**);
1148 1154
int ruby_run_node(void *);
1149
-