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
PR-URL: https://github.com/libuv/libuv/pull/864
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
Ben Noordhuis 2016-05-10 15:22:38 +02:00
parent a8840fb347
commit 28d160f3de

View File

@ -28,6 +28,7 @@
#include <sys/time.h>
#include <sys/resource.h> /* getrlimit() */
#include <unistd.h> /* getpagesize() */
#include <limits.h>
@ -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;