Project

General

Profile

Feature #5097 » 0001-allocate-th-altstack-early-run-GC-on-allocation-fail.patch

normalperson (Eric Wong), 07/29/2011 06:03 AM

View differences:

signal.c
#ifdef POSIX_SIGNAL
#ifdef USE_SIGALTSTACK
#ifdef SIGSTKSZ
#define ALT_STACK_SIZE (SIGSTKSZ*2)
#else
#define ALT_STACK_SIZE (4*1024)
#endif
/* alternate stack for SIGSEGV */
void
rb_register_sigaltstack(rb_thread_t *th)
{
stack_t newSS, oldSS;
if (th->altstack) return;
newSS.ss_sp = th->altstack = malloc(ALT_STACK_SIZE);
newSS.ss_sp = th->altstack;
if (newSS.ss_sp == NULL)
/* should handle error */
rb_bug("rb_register_sigaltstack. malloc error\n");
rb_bug("rb_register_sigaltstack: th->altstack not initialized\n");
newSS.ss_size = ALT_STACK_SIZE;
newSS.ss_flags = 0;
vm.c
else {
#ifdef USE_SIGALTSTACK
if (th->altstack) {
free(th->altstack);
xfree(th->altstack);
}
#endif
ruby_xfree(ptr);
......
rb_thread_t *th;
obj = TypedData_Make_Struct(klass, rb_thread_t, &thread_data_type, th);
#endif
return obj;
}
......
{
th->self = self;
#ifdef USE_SIGALTSTACK
th->altstack = xmalloc(ALT_STACK_SIZE);
#endif
/* allocate thread stack */
th->stack_size = RUBY_VM_THREAD_STACK_SIZE;
th->stack = thread_recycle_stack(th->stack_size);
vm_core.h
#pragma GCC visibility pop
#endif
#ifdef SIGSTKSZ
#define ALT_STACK_SIZE (SIGSTKSZ*2)
#else
#define ALT_STACK_SIZE (4*1024)
#endif
#if defined(MINSIGSTKSZ) && (ALT_STACK_SIZE < MINSIGSTKSZ)
#undef ALT_STACK_SIZE
#define ALT_STACK_SIZE MINSIGSTKSZ
#endif
#endif /* RUBY_VM_CORE_H */
(5-5/7)