From patchwork Sun Sep 3 19:13:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 75196 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 65A513858032 for ; Sun, 3 Sep 2023 19:13:24 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from sonata.ens-lyon.org (sonata.ens-lyon.org [140.77.166.138]) by sourceware.org (Postfix) with ESMTPS id 4B6B43858C2C for ; Sun, 3 Sep 2023 19:13:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B6B43858C2C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bounce.ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by sonata.ens-lyon.org (Postfix) with ESMTP id 28E6C20152; Sun, 3 Sep 2023 21:13:09 +0200 (CEST) Received: from sonata.ens-lyon.org ([127.0.0.1]) by localhost (sonata.ens-lyon.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KbMneFGdk0QJ; Sun, 3 Sep 2023 21:13:09 +0200 (CEST) Received: from begin (lfbn-bor-1-1163-184.w92-158.abo.wanadoo.fr [92.158.138.184]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by sonata.ens-lyon.org (Postfix) with ESMTPSA id E805A2014B; Sun, 3 Sep 2023 21:13:08 +0200 (CEST) Received: from samy by begin with local (Exim 4.96) (envelope-from ) id 1qcsWy-005cls-0j; Sun, 03 Sep 2023 21:13:08 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [hurd,commited] htl: Fix stack information for main thread Date: Sun, 3 Sep 2023 21:13:07 +0200 Message-Id: <20230903191307.1340668-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: commit-hurd@gnu.org Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" We can easily directly ask the kernel with vm_region rather than assuming a one-page stack. --- 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). */