#ifndef inhibit_libc
#include <errno.h>
+#include <signal.h>
#include <pthread.h>
#include "generic-morestack.h"
extern int pthread_setspecific (pthread_key_t, const void *)
__attribute__ ((weak));
+extern int pthread_sigmask (int, const sigset_t *, sigset_t *)
+ __attribute__ ((weak));
+
/* The key for the list of stack segments to free when the thread
exits. This is created by pthread_key_create. */
static void
free_segments (void* arg)
{
+ /* We must block signals in case the signal handler tries to split
+ the stack. We leave them blocked while the thread exits. */
+ if (pthread_sigmask)
+ {
+ sigset_t mask;
+
+ sigfillset (&mask);
+ pthread_sigmask (SIG_BLOCK, &mask, NULL);
+ }
+
__morestack_release_segments ((struct stack_segment **) arg, 1);
}