public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Samuel Thibault <sthibaul@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc] htl: Fix stack information for main thread
Date: Sun,  3 Sep 2023 19:13:03 +0000 (GMT)	[thread overview]
Message-ID: <20230903191303.21B6C3858D33@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=807690610916df8aef17cd14bfadd5d4b6e699a9

commit 807690610916df8aef17cd14bfadd5d4b6e699a9
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Sun Sep 3 21:11:09 2023 +0200

    htl: Fix stack information for main thread
    
    We can easily directly ask the kernel with vm_region rather than
    assuming a one-page stack.

Diff:
---
 sysdeps/mach/hurd/htl/pt-sysdep.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/sysdeps/mach/hurd/htl/pt-sysdep.c b/sysdeps/mach/hurd/htl/pt-sysdep.c
index 030a7c7a9e..afef7841f8 100644
--- a/sysdeps/mach/hurd/htl/pt-sysdep.c
+++ b/sysdeps/mach/hurd/htl/pt-sysdep.c
@@ -60,12 +60,36 @@ _init_routine (void *stack)
 
   if (stack != NULL)
     {
-      /* We are getting initialized due to dlopening a library using libpthread
-         while the main program was not linked against libpthread.  */
+      /* We are given a stack, use it.  */
+
+      /* Get the stack area information */
+      vm_address_t addr = (vm_address_t) stack;
+      vm_size_t vm_size;
+      vm_prot_t prot, max_prot;
+      vm_inherit_t inherit;
+      boolean_t is_shared;
+      memory_object_name_t obj;
+      vm_offset_t offset;
+
+      if (vm_region (__mach_task_self (), &addr,
+		     &vm_size, &prot, &max_prot, &inherit, &is_shared,
+		     &obj, &offset) == KERN_SUCCESS)
+	__mach_port_deallocate (__mach_task_self (), obj);
+      else
+	{
+	  /* Uh.  Assume at least a page.  */
+	  vm_size = __vm_page_size;
+#if _STACK_GROWS_DOWN
+	  addr = (vm_address_t) stack - vm_size;
+#else
+	  addr = (vm_address_t) stack + vm_size;
+#endif
+	}
+
       /* Avoid allocating another stack */
       attrp = &attr;
       __pthread_attr_init (attrp);
-      __pthread_attr_setstack (attrp, stack, __vm_page_size);
+      __pthread_attr_setstack (attrp, (void *) addr, vm_size);
     }
 
   /* Create the pthread structure for the main thread (i.e. us).  */

                 reply	other threads:[~2023-09-03 19:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230903191303.21B6C3858D33@sourceware.org \
    --to=sthibaul@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).