From ad9b04215b70b74abe2bef811f148dcd649f3366 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 10 May 2016 15:22:38 +0200 Subject: [PATCH] darwin: make thread stack multiple of page size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pthread_attr_setstacksize() expects that the stack size is a multiple of the page size so make sure that it is. Fixes a regression introduced in commit 3db07cc ("osx: set the default thread stack size to RLIMIT_STACK") that made the program abort under certain configurations; GNU Emacs on OS X apparently sets RLIMIT_STACK to odd values when executing child processes. Fixes: https://github.com/nodejs/node/issues/6563 PR-URL: https://github.com/libuv/libuv/pull/864 Reviewed-By: Saúl Ibarra Corretgé --- src/unix/thread.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/unix/thread.c b/src/unix/thread.c index c35bc926bf0..56bb8a47aed 100644 --- a/src/unix/thread.c +++ b/src/unix/thread.c @@ -28,6 +28,7 @@ #include #include /* getrlimit() */ +#include /* getpagesize() */ #include @@ -82,10 +83,13 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) { if (pthread_attr_init(attr)) abort(); - if (lim.rlim_cur != RLIM_INFINITY && - lim.rlim_cur >= PTHREAD_STACK_MIN) { - if (pthread_attr_setstacksize(attr, lim.rlim_cur)) - abort(); + if (lim.rlim_cur != RLIM_INFINITY) { + /* pthread_attr_setstacksize() expects page-aligned values. */ + lim.rlim_cur -= lim.rlim_cur % (rlim_t) getpagesize(); + + if (lim.rlim_cur >= PTHREAD_STACK_MIN) + if (pthread_attr_setstacksize(attr, lim.rlim_cur)) + abort(); } #else attr = NULL;