Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
darwin: make thread stack multiple of page size
Browse files Browse the repository at this point in the history
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/libuv#864
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
  • Loading branch information
bnoordhuis committed May 10, 2016
1 parent a8840fb commit 28d160f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/unix/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <sys/time.h>
#include <sys/resource.h> /* getrlimit() */
#include <unistd.h> /* getpagesize() */

#include <limits.h>

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 28d160f

Please sign in to comment.