diff options
author | Yusuke Endoh <[email protected]> | 2020-03-06 21:32:42 +0900 |
---|---|---|
committer | Yusuke Endoh <[email protected]> | 2020-03-06 21:41:34 +0900 |
commit | 0256e4f0f5e10f0a15cbba2cd64e252dfa864e4a (patch) | |
tree | 09f9e3f9247456d089c5d26102cbe9793938db36 /thread_pthread.c | |
parent | baaf6815704ef36160e45244b844b633ed51c3b4 (diff) |
thread_pthread.c: allocate sigaltstack before pthread_create
A new (not-initialized-yet) pthread attempts to allocate sigaltstack by
using xmalloc. It may cause GC, but because the thread is not
initialized yet, ruby_native_thread_p() returns false, which leads to
"[FATAL] failed to allocate memory" and exit.
In fact, we can observe the error message in the log of OpenBSD CI:
https://rubyci.org/logs/rubyci.s3.amazonaws.com/openbsd-current/ruby-master/log/20200306T083005Z.log.html.gz
This changeset allocates sigaltstack before pthread is created.
Diffstat (limited to 'thread_pthread.c')
-rw-r--r-- | thread_pthread.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/thread_pthread.c b/thread_pthread.c index 29284ff0f9..b9ac63f298 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -950,7 +950,7 @@ static void * thread_start_func_1(void *th_ptr) { rb_thread_t *th = th_ptr; - RB_ALTSTACK_INIT(void *altstack); + RB_ALTSTACK_INIT(void *altstack, th->altstack); #if USE_THREAD_CACHE thread_start: #endif @@ -1099,6 +1099,9 @@ native_thread_create(rb_thread_t *th) const size_t stack_size = th->vm->default_params.thread_machine_stack_size + th->vm->default_params.thread_vm_stack_size; const size_t space = space_size(stack_size); +#ifdef USE_SIGALTSTACK + th->altstack = rb_allocate_sigaltstack(); +#endif th->ec->machine.stack_maxsize = stack_size - space; CHECK_ERR(pthread_attr_init(&attr)); |