Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix bugs which cause crashes when threading is involved.

  • Loading branch information...
commit 1d2ac6eb1e08600a43054e9966041f25487c9e7f 1 parent efe05ae
@FooBarWidget FooBarWidget authored
Showing with 25 additions and 25 deletions.
  1. +1 −0  eval.c
  2. +14 −17 gc.c
  3. +1 −0  node.h
  4. +9 −8 rubysig.h
View
1  eval.c
@@ -12405,6 +12405,7 @@ rb_thread_group(thread)
th->stk_size = 0;\
th->stk_max = 0;\
th->wait_for = 0;\
+ th->gc_stack_end = (VALUE *) STACK_GROW_DIRECTION;\
IA64_INIT(th->bstr_ptr = 0);\
IA64_INIT(th->bstr_len = 0);\
IA64_INIT(th->bstr_max = 0);\
View
31 gc.c
@@ -715,8 +715,6 @@ VALUE *rb_gc_stack_start = 0;
VALUE *rb_gc_register_stack_start = 0;
#endif
-VALUE *rb_gc_stack_end = (VALUE *)STACK_GROW_DIRECTION;
-
#ifdef DJGPP
/* set stack size (http://www.delorie.com/djgpp/v2faq/faq15_9.html) */
@@ -813,22 +811,24 @@ ruby_stack_check()
#if STACK_WIPE_METHOD
void rb_gc_wipe_stack(void)
{
- VALUE *stack_end = rb_gc_stack_end;
- VALUE *sp = __sp();
- rb_gc_stack_end = sp;
+ if (curr_thread) {
+ VALUE *stack_end = rb_curr_thread->gc_stack_end;
+ VALUE *sp = __sp();
+ rb_curr_thread->gc_stack_end = sp;
#if STACK_WIPE_METHOD == 1
#warning clearing of "ghost references" from the call stack has been disabled
#elif STACK_WIPE_METHOD == 2 /* alloca ghost stack before clearing it */
- if (__stack_past(sp, stack_end)) {
- size_t bytes = __stack_depth((char *)stack_end, (char *)sp);
- STACK_UPPER(sp = nativeAllocA(bytes), stack_end = nativeAllocA(bytes));
- __stack_zero(stack_end, sp);
- }
+ if (__stack_past(sp, stack_end)) {
+ size_t bytes = __stack_depth((char *)stack_end, (char *)sp);
+ STACK_UPPER(sp = nativeAllocA(bytes), stack_end = nativeAllocA(bytes));
+ __stack_zero(stack_end, sp);
+ }
#elif STACK_WIPE_METHOD == 3 /* clear unallocated area past stack pointer */
- __stack_zero(stack_end, sp); /* will crash if compiler pushes a temp. here */
+ __stack_zero(stack_end, sp); /* will crash if compiler pushes a temp. here */
#else
#error unsupported method of clearing ghost references from the stack
#endif
+ }
}
#else
#warning clearing of "ghost references" from the call stack completely disabled
@@ -1803,10 +1803,10 @@ garbage_collect()
garbage_collect_0(top);
# else /* no native alloca() available */
garbage_collect_0(top);
- {
+ if (rb_curr_thread) {
VALUE *paddedLimit = __stack_grow(gc_stack_limit, GC_STACK_PAD);
- if (__stack_past(rb_gc_stack_end, paddedLimit))
- rb_gc_stack_end = paddedLimit;
+ if (__stack_past(rb_curr_thread->gc_stack_end, paddedLimit))
+ rb_curr_thread->gc_stack_end = paddedLimit;
}
rb_gc_wipe_stack(); /* wipe the whole stack area reserved for this gc */
# endif
@@ -2659,9 +2659,6 @@ Init_GC()
{
VALUE rb_mObSpace;
-#if !STACK_GROW_DIRECTION
- rb_gc_stack_end = stack_grow_direction(&rb_mObSpace);
-#endif
rb_mGC = rb_define_module("GC");
rb_define_singleton_method(rb_mGC, "start", rb_gc_start, 0);
rb_define_singleton_method(rb_mGC, "enable", rb_gc_enable, 0);
View
1  node.h
@@ -416,6 +416,7 @@ struct rb_thread {
VALUE *stk_pos;
VALUE *stk_base;
VALUE *guard;
+ VALUE *gc_stack_end;
#ifdef __ia64
size_t bstr_len;
size_t bstr_max;
View
17 rubysig.h
@@ -152,7 +152,6 @@ void rb_trap_restore_mask _((void));
RUBY_EXTERN int rb_thread_critical;
void rb_thread_schedule _((void));
-RUBY_EXTERN VALUE *rb_gc_stack_end;
RUBY_EXTERN int rb_gc_stack_grow_direction; /* -1 for down or 1 for up */
#if STACK_GROW_DIRECTION > 0
@@ -268,12 +267,14 @@ RUBY_EXTERN VALUE *__sp(void);
#if STACK_WIPE_METHOD == 0
#define rb_gc_wipe_stack() ((void)0)
#elif STACK_WIPE_METHOD == 4
-#define rb_gc_wipe_stack() { \
- VALUE *end = rb_gc_stack_end; \
- VALUE *sp = __sp(); \
- rb_gc_stack_end = sp; \
- __stack_zero(end, sp); \
-}
+#define rb_gc_wipe_stack() do { \
+ if (rb_curr_thread) { \
+ VALUE *end = rb_curr_thread->gc_stack_end; \
+ VALUE *sp = __sp(); \
+ rb_curr_thread->gc_stack_end = sp; \
+ __stack_zero(end, sp); \
+ } \
+} while (0)
#else
RUBY_EXTERN void rb_gc_wipe_stack(void);
#endif
@@ -283,7 +284,7 @@ RUBY_EXTERN void rb_gc_wipe_stack(void);
*/
#define rb_gc_update_stack_extent() do { \
VALUE *sp = __sp(); \
- if __stack_past(rb_gc_stack_end, sp) rb_gc_stack_end = sp; \
+ if (rb_curr_thread && __stack_past(rb_curr_thread->gc_stack_end, sp)) rb_curr_thread->gc_stack_end = sp; \
} while(0)
Please sign in to comment.
Something went wrong with that request. Please try again.