Skip to content

Commit 28d160f

Browse files
committed
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: nodejs/node#6563 PR-URL: libuv#864 Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
1 parent a8840fb commit 28d160f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/unix/thread.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include <sys/time.h>
3030
#include <sys/resource.h> /* getrlimit() */
31+
#include <unistd.h> /* getpagesize() */
3132

3233
#include <limits.h>
3334

@@ -81,10 +82,13 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {
8182
if (pthread_attr_init(attr))
8283
abort();
8384

84-
if (lim.rlim_cur != RLIM_INFINITY &&
85-
lim.rlim_cur >= PTHREAD_STACK_MIN) {
86-
if (pthread_attr_setstacksize(attr, lim.rlim_cur))
87-
abort();
85+
if (lim.rlim_cur != RLIM_INFINITY) {
86+
/* pthread_attr_setstacksize() expects page-aligned values. */
87+
lim.rlim_cur -= lim.rlim_cur % (rlim_t) getpagesize();
88+
89+
if (lim.rlim_cur >= PTHREAD_STACK_MIN)
90+
if (pthread_attr_setstacksize(attr, lim.rlim_cur))
91+
abort();
8892
}
8993
#else
9094
attr = NULL;

0 commit comments

Comments
 (0)