Skip to content

Commit ad9b042

Browse files
bnoordhuisbrimworks
authored andcommitted
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 f2f50e4 commit ad9b042

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

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

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

0 commit comments

Comments
 (0)