File bind_stack.patch of Package ruby19.openSUSE_12.2_Update

diff -wruN -x '*~' -x '*.o' -x '*.a' -x '*.so' -x '*.so.[0-9]' -x autom4te.cache -x .deps -x .libs -x Makefile ../orig-ruby-1.9.3-p194/gc.c ./gc.c
--- ../orig-ruby-1.9.3-p194/gc.c	2012-02-22 09:57:21.000000000 +0100
+++ ./gc.c	2013-01-04 14:23:14.184993470 +0100
@@ -22,6 +22,7 @@
 #include "gc.h"
 #include "constant.h"
 #include <stdio.h>
+#include <assert.h>
 #include <setjmp.h>
 #include <sys/types.h>
 
@@ -2089,6 +2090,24 @@
     return TRUE;
 }
 
+static VALUE *ruby_stack_lower_bound = 0, *ruby_stack_upper_bound = 0;
+static char ruby_stack_is_bound = 0;
+
+void
+ruby_bind_stack(void *lower_bound, void *upper_bound)
+{
+    assert(upper_bound > lower_bound && lower_bound > 0);
+    ruby_stack_lower_bound = lower_bound;
+    ruby_stack_upper_bound = upper_bound;
+    ruby_stack_is_bound = 1;
+}
+
+#define FIX_STACK_BOUNDS(start, end, th) \
+     if (ruby_stack_is_bound && th == th->vm->main_thread) { \
+          if (start < ruby_stack_lower_bound) { start = ruby_stack_lower_bound; } \
+          if (end   > ruby_stack_upper_bound) { end   = ruby_stack_upper_bound; } \
+     }
+
 static void
 before_gc_sweep(rb_objspace_t *objspace)
 {
@@ -2415,6 +2434,7 @@
 
     SET_STACK_END;
     GET_STACK_BOUNDS(stack_start, stack_end, 1);
+    FIX_STACK_BOUNDS(stack_start, stack_end, th);
 
     mark_locations_array(objspace, save_regs_gc_mark.v, numberof(save_regs_gc_mark.v));
 
@@ -2522,6 +2542,7 @@
     VALUE *stack_start, *stack_end;
 
     GET_STACK_BOUNDS(stack_start, stack_end, 0);
+    FIX_STACK_BOUNDS(stack_start, stack_end, th);
     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 -wruN -x '*~' -x '*.o' -x '*.a' -x '*.so' -x '*.so.[0-9]' -x autom4te.cache -x .deps -x .libs -x Makefile ../orig-ruby-1.9.3-p194/include/ruby/ruby.h ./include/ruby/ruby.h
--- ../orig-ruby-1.9.3-p194/include/ruby/ruby.h	2013-01-04 14:23:00.752443196 +0100
+++ ./include/ruby/ruby.h	2013-01-04 14:23:14.184993470 +0100
@@ -1224,6 +1224,17 @@
 #define RUBY_INIT_STACK \
     VALUE variable_in_this_stack_frame; \
     ruby_init_stack(&variable_in_this_stack_frame);
+/*
+ *  Binds the stack of Ruby's main thread to the region of memory that spans
+ *  inclusively from the given lower boundary to the given upper boundary:
+ *
+ *      (lower) <= (stack pointer of Ruby's main thread) <= (upper)
+ *
+ *  These boundaries do not protect Ruby's main thread against stack
+ *  overflow and they do not apply to non-main Ruby threads (whose stacks
+ *  are dynamically allocated and managed by the native Operating System).
+ */
+void ruby_bind_stack(void *lower_bound, void *upper_bound);
 void ruby_init(void);
 void ruby_init_prelude(void);
 void *ruby_options(int, char**);
openSUSE Build Service is sponsored by