summaryrefslogtreecommitdiff
path: root/hurd/hurdsig.c
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2013-10-25 00:46:50 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2013-10-25 00:46:50 +0200
commit5df5f8f8a04a278d653f7bac8199fafdd2f01cbf (patch)
treea4cfcbfcbe5937e9cda8ac5464c0e08340d7e111 /hurd/hurdsig.c
parent59ff42dc062f858c9e143a41baef62ee05d3b360 (diff)
parentb3320e243e29a0451fb5aa6d39c6bfe2200504dc (diff)
Merge branch 't/tls-threadvar' into refs/top-bases/tschwinge/Roger_Whittaker
Conflicts: hurd/hurd/signal.h sysdeps/mach/hurd/i386/init-first.c
Diffstat (limited to 'hurd/hurdsig.c')
-rw-r--r--hurd/hurdsig.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/hurd/hurdsig.c b/hurd/hurdsig.c
index 75110d8800..2d7b003454 100644
--- a/hurd/hurdsig.c
+++ b/hurd/hurdsig.c
@@ -20,6 +20,7 @@
#include <string.h>
#include <cthreads.h> /* For `struct mutex'. */
+#include <pthread.h>
#include <mach.h>
#include <mach/thread_switch.h>
@@ -45,7 +46,6 @@ thread_t _hurd_msgport_thread;
/* These are set up by _hurdsig_init. */
unsigned long int __hurd_sigthread_stack_base;
unsigned long int __hurd_sigthread_stack_end;
-unsigned long int *__hurd_sigthread_variables;
/* Per-thread signal state. */
__thread struct hurd_sigstate *_hurd_sigstate;
@@ -1458,7 +1458,11 @@ _hurdsig_init (const int *intarray, size_t intarraysize)
/* Start the signal thread listening on the message port. */
- if (__hurd_threadvar_stack_mask == 0)
+#pragma weak cthread_fork
+#pragma weak cthread_detach
+#pragma weak pthread_getattr_np
+#pragma weak pthread_attr_getstack
+ if (!cthread_fork)
{
err = __thread_create (__mach_task_self (), &_hurd_msgport_thread);
assert_perror (err);
@@ -1473,12 +1477,6 @@ _hurdsig_init (const int *intarray, size_t intarraysize)
assert_perror (err);
__hurd_sigthread_stack_end = __hurd_sigthread_stack_base + stacksize;
- __hurd_sigthread_variables =
- malloc (__hurd_threadvar_max * sizeof (unsigned long int));
- if (__hurd_sigthread_variables == NULL)
- __libc_fatal ("hurd: Can't allocate threadvars for signal thread\n");
- memset (__hurd_sigthread_variables, 0,
- __hurd_threadvar_max * sizeof (unsigned long int));
/* Reinitialize the MiG support routines so they will use a per-thread
variable for the cached reply port. */
@@ -1489,6 +1487,7 @@ _hurdsig_init (const int *intarray, size_t intarraysize)
}
else
{
+ cthread_t thread;
/* When cthreads is being used, we need to make the signal thread a
proper cthread. Otherwise it cannot use mutex_lock et al, which
will be the cthreads versions. Various of the message port RPC
@@ -1498,9 +1497,20 @@ _hurdsig_init (const int *intarray, size_t intarraysize)
we'll let the signal thread's per-thread variables be found as for
any normal cthread, and just leave the magic __hurd_sigthread_*
values all zero so they'll be ignored. */
-#pragma weak cthread_fork
-#pragma weak cthread_detach
- cthread_detach (cthread_fork ((cthread_fn_t) &_hurd_msgport_receive, 0));
+ cthread_detach (thread = cthread_fork ((cthread_fn_t) &_hurd_msgport_receive, 0));
+
+ if (pthread_getattr_np)
+ {
+ /* Record stack layout for fork() */
+ pthread_attr_t attr;
+ void *addr;
+ size_t size;
+
+ pthread_getattr_np ((pthread_t) thread, &attr);
+ pthread_attr_getstack (&attr, &addr, &size);
+ __hurd_sigthread_stack_base = (uintptr_t) addr;
+ __hurd_sigthread_stack_end = __hurd_sigthread_stack_base + size;
+ }
/* XXX We need the thread port for the signal thread further on
in this thread (see hurdfault.c:_hurdsigfault_init).