Project

General

Profile

Feature #2294 ยป ruby_bind_stack_r25604.patch

patch against SVN trunk r25604 - sunaku (Suraj Kurapati), 11/04/2009 02:28 AM

View differences:

ChangeLog
402 402

  
403 403
	* io.c (io_cntl): F_DUPFD is platform dependent.
404 404

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

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

  
409
	* gc.c: implement ruby_bind_stack().  restrict GC marking
410
	  region to ruby_bind_stack() boundaries for main thread.
411

  
405 412
Sun Oct 25 10:19:09 2009  Nobuyoshi Nakada  <nobu@ruby-lang.org>
406 413

  
407 414
	* ext/dl/handle.c (rb_dlhandle_close): fixed an invalid local
gc.c
20 20
#include "vm_core.h"
21 21
#include "gc.h"
22 22
#include <stdio.h>
23
#include <assert.h>
23 24
#include <setjmp.h>
24 25
#include <sys/types.h>
25 26

  
......
2099 2100
     (start = STACK_END, end = STACK_START) : (start = STACK_START, end = STACK_END+appendix))
2100 2101
#endif
2101 2102

  
2103
static VALUE *ruby_stack_lower_bound = 0, *ruby_stack_upper_bound = 0;
2104
static char ruby_stack_is_bound = 0;
2105

  
2106
void
2107
ruby_bind_stack(void *lower_bound, void *upper_bound)
2108
{
2109
    assert(upper_bound > lower_bound && lower_bound > 0);
2110
    ruby_stack_lower_bound = lower_bound;
2111
    ruby_stack_upper_bound = upper_bound;
2112
    ruby_stack_is_bound = 1;
2113
}
2114

  
2115
#define FIX_STACK_BOUNDS(start, end, th) \
2116
     if (ruby_stack_is_bound && th == th->vm->main_thread) { \
2117
          if (start < ruby_stack_lower_bound) { start = ruby_stack_lower_bound; } \
2118
          if (end   > ruby_stack_upper_bound) { end   = ruby_stack_upper_bound; } \
2119
     }
2120

  
2102 2121
static void
2103 2122
mark_current_machine_context(rb_objspace_t *objspace, rb_thread_t *th)
2104 2123
{
......
2111 2130

  
2112 2131
    SET_STACK_END;
2113 2132
    GET_STACK_BOUNDS(stack_start, stack_end, 1);
2133
    FIX_STACK_BOUNDS(stack_start, stack_end, th);
2114 2134

  
2115 2135
    mark_locations_array(objspace,
2116 2136
			 (VALUE*)save_regs_gc_mark,
......
2218 2238
    VALUE *stack_start, *stack_end;
2219 2239

  
2220 2240
    GET_STACK_BOUNDS(stack_start, stack_end, 0);
2241
    FIX_STACK_BOUNDS(stack_start, stack_end, th);
2221 2242
    rb_gc_mark_locations(stack_start, stack_end);
2222 2243
#ifdef __ia64
2223 2244
    rb_gc_mark_locations(th->machine_register_stack_start, th->machine_register_stack_end);
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 the stack of Ruby's main thread to the region of memory that spans
1148
 *  inclusively from the given lower boundary to the given upper boundary:
1149
 *
1150
 *      (lower) <= (stack pointer of Ruby's main thread) <= (upper)
1151
 *
1152
 *  These boundaries do not protect Ruby's main thread against stack
1153
 *  overflow and they do not apply to non-main Ruby threads (whose stacks
1154
 *  are dynamically allocated and managed by the native Operating System).
1155
 */
1156
void ruby_bind_stack(void *lower_bound, void *upper_bound);
1146 1157
void ruby_init(void);
1147 1158
void *ruby_options(int, char**);
1148 1159
int ruby_run_node(void *);
1149
-