From b176c1f53bff2a7df2a7fb57cd60ae4c230fa2f0 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 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 --- 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 43dcdd1a52b4..236f59139366 100644 --- a/src/unix/thread.c +++ b/src/unix/thread.c @@ -28,6 +28,7 @@ #include #include /* getrlimit() */ +#include /* getpagesize() */ #include @@ -81,10 +82,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;