git-main_stack
authorGNU Libc Maintainers <debian-glibc@lists.debian.org>
Sat, 16 Sep 2023 09:12:43 +0000 (10:12 +0100)
committerAurelien Jarno <aurel32@debian.org>
Sat, 16 Sep 2023 09:12:43 +0000 (10:12 +0100)
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.

Gbp-Pq: Topic hurd-i386
Gbp-Pq: Name git-main_stack.diff

sysdeps/mach/hurd/htl/pt-sysdep.c

index 3960ffd6dc6b21365bac4ee256738aee3146ce53..aa946110cb732e647c005617d151ba36f12c4c6b 100644 (file)
@@ -62,12 +62,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).  */