public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [hurd,commited] hurd: Fix getting signal thread stack layout for fork
@ 2018-03-17 21:53 Samuel Thibault
  0 siblings, 0 replies; only message in thread
From: Samuel Thibault @ 2018-03-17 21:53 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault

* hurd/hurdsig.c: Include <pthread.h>.
(_hurdsig_init): Call pthread_getattr_np and pthread_attr_getstack to
get the signal thread stack layout.
---
 ChangeLog      |  6 ++++++
 hurd/hurdsig.c | 20 +++++++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 175bcafe66..7f4721b06e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2018-03-17  Samuel Thibault  <samuel.thibault@ens-lyon.org>
+
+	* hurd/hurdsig.c: Include <pthread.h>.
+	(_hurdsig_init): Call pthread_getattr_np and pthread_attr_getstack to
+	get the signal thread stack layout.
+
 2018-03-16  Samuel Thibault  <samuel.thibault@ens-lyon.org>
 
 	* sysdeps/generic/thread_state.h (MACHINE_NEW_THREAD_STATE_FLAVOR):
diff --git a/hurd/hurdsig.c b/hurd/hurdsig.c
index 4f5bb9a8da..198546fbb3 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>
 
@@ -1297,7 +1298,24 @@ _hurdsig_init (const int *intarray, size_t intarraysize)
          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));
+#pragma weak pthread_getattr_np
+#pragma weak pthread_attr_getstack
+      cthread_t thread = cthread_fork ((cthread_fn_t) &_hurd_msgport_receive,
+				       0);
+      cthread_detach (thread);
+
+      if (pthread_getattr_np)
+	{
+	  /* Record signal thread 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).
-- 
2.16.2

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-03-17 21:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-17 21:53 [hurd,commited] hurd: Fix getting signal thread stack layout for fork Samuel Thibault

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).