Feature #5097 ยป 0001-allocate-th-altstack-early-run-GC-on-allocation-fail.patch
signal.c | ||
---|---|---|
423 | 423 |
#ifdef POSIX_SIGNAL |
424 | 424 | |
425 | 425 |
#ifdef USE_SIGALTSTACK |
426 |
#ifdef SIGSTKSZ |
|
427 |
#define ALT_STACK_SIZE (SIGSTKSZ*2) |
|
428 |
#else |
|
429 |
#define ALT_STACK_SIZE (4*1024) |
|
430 |
#endif |
|
431 | 426 |
/* alternate stack for SIGSEGV */ |
432 | 427 |
void |
433 | 428 |
rb_register_sigaltstack(rb_thread_t *th) |
434 | 429 |
{ |
435 | 430 |
stack_t newSS, oldSS; |
436 | 431 | |
437 |
if (th->altstack) return; |
|
438 | ||
439 |
newSS.ss_sp = th->altstack = malloc(ALT_STACK_SIZE); |
|
432 |
newSS.ss_sp = th->altstack; |
|
440 | 433 |
if (newSS.ss_sp == NULL) |
441 |
/* should handle error */ |
|
442 |
rb_bug("rb_register_sigaltstack. malloc error\n"); |
|
434 |
rb_bug("rb_register_sigaltstack: th->altstack not initialized\n"); |
|
443 | 435 |
newSS.ss_size = ALT_STACK_SIZE; |
444 | 436 |
newSS.ss_flags = 0; |
445 | 437 |
vm.c | ||
---|---|---|
1754 | 1754 |
else { |
1755 | 1755 |
#ifdef USE_SIGALTSTACK |
1756 | 1756 |
if (th->altstack) { |
1757 |
free(th->altstack); |
|
1757 |
xfree(th->altstack);
|
|
1758 | 1758 |
} |
1759 | 1759 |
#endif |
1760 | 1760 |
ruby_xfree(ptr); |
... | ... | |
1817 | 1817 |
rb_thread_t *th; |
1818 | 1818 |
obj = TypedData_Make_Struct(klass, rb_thread_t, &thread_data_type, th); |
1819 | 1819 |
#endif |
1820 | ||
1820 | 1821 |
return obj; |
1821 | 1822 |
} |
1822 | 1823 | |
... | ... | |
1825 | 1826 |
{ |
1826 | 1827 |
th->self = self; |
1827 | 1828 | |
1829 |
#ifdef USE_SIGALTSTACK |
|
1830 |
th->altstack = xmalloc(ALT_STACK_SIZE); |
|
1831 |
#endif |
|
1828 | 1832 |
/* allocate thread stack */ |
1829 | 1833 |
th->stack_size = RUBY_VM_THREAD_STACK_SIZE; |
1830 | 1834 |
th->stack = thread_recycle_stack(th->stack_size); |
vm_core.h | ||
---|---|---|
744 | 744 |
#pragma GCC visibility pop |
745 | 745 |
#endif |
746 | 746 | |
747 |
#ifdef SIGSTKSZ |
|
748 |
#define ALT_STACK_SIZE (SIGSTKSZ*2) |
|
749 |
#else |
|
750 |
#define ALT_STACK_SIZE (4*1024) |
|
751 |
#endif |
|
752 | ||
753 |
#if defined(MINSIGSTKSZ) && (ALT_STACK_SIZE < MINSIGSTKSZ) |
|
754 |
#undef ALT_STACK_SIZE |
|
755 |
#define ALT_STACK_SIZE MINSIGSTKSZ |
|
756 |
#endif |
|
757 | ||
747 | 758 |
#endif /* RUBY_VM_CORE_H */ |