From patchwork Sat May 15 12:34:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 43432 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 3CA503951C87; Sat, 15 May 2021 12:34:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CA503951C87 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1621082091; bh=pNiUeXqGBoAWJGcHg182Q3/MjYDPoI7Kaee6NDWHX8I=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=cmnW1OmgfmKy9MoYF7NjVC43Mikoxm+Bs4+2omIkQFhysmkiohn/p+pe7BmqoLMBe gFGrS2GNxoR44xc+Mr86QwzWMpCdFz9Ev56c7VsRAcRWgR8tweuFIZsLOYYwbiIRUl Tv5gRlZc6VjM2uplmoKdIRWb+Aawd70VrRhR2PFY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by sourceware.org (Postfix) with ESMTPS id D98F1393C84A for ; Sat, 15 May 2021 12:34:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D98F1393C84A Received: by mail-pj1-x102c.google.com with SMTP id t11so1205358pjm.0 for ; Sat, 15 May 2021 05:34:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pNiUeXqGBoAWJGcHg182Q3/MjYDPoI7Kaee6NDWHX8I=; b=Or068c7j6vWk/IL7QPbkBL4FH2hzR4va02uNtYHYLYeoRPZWxom5MVSSZ6HAvSEB47 GvSSt18Q0S93/DSVOUwqJmIbhJj3+0sbBxWIJn5IZC7KOPDy/YAo0J5lt07TnuuOvtI3 UOM+JZbzPOuF8JVaPBFIF8safU0vtrcxwVY97tBehtcJ8wnT01WocqOZ71g4nFW91ovj nDsSUsvquRVLGiO59WNM3S1AedFrzZa/EBDdn2OEL8Dp5Y21/t3TgjUfj9CpQ8CymUUA ur5/J2SMO/PXiZnoaE/cYPJfGu8Gqvlc+/k3Q0aWgHO++S6XEdIZB6xpHgox2X/wsuWM tAuA== X-Gm-Message-State: AOAM5309UWIqnrQseA9lXQK9hgTVPekxKfRyevRKVuvR2bCXdXjEYnKP MQX9aUt8LeMLXzz7LxlSAdUmuD3mwdLlwg== X-Google-Smtp-Source: ABdhPJyNUx9N4ihfYQvWi6ZUZxcHuQK4/3OA3MHHVMuGXkTh2Q9YGmRthv4gbgfqgJlJlQY65knP9Q== X-Received: by 2002:a17:902:bd87:b029:ee:e0ae:cf0a with SMTP id q7-20020a170902bd87b02900eee0aecf0amr50890306pls.1.1621082086030; Sat, 15 May 2021 05:34:46 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.56.39.231]) by smtp.gmail.com with ESMTPSA id z20sm6376260pjq.47.2021.05.15.05.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 May 2021 05:34:44 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 416B4C0377; Sat, 15 May 2021 05:34:42 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 2/5] nptl: Always pass stack size to create_thread Date: Sat, 15 May 2021 05:34:39 -0700 Message-Id: <20210515123442.1432385-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210515123442.1432385-1-hjl.tools@gmail.com> References: <20210515123442.1432385-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3035.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Florian Weimer Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Since the stack size argument for create_thread is now unconditional, always pass stack size to create_thread. --- nptl/allocatestack.c | 59 ++++--------------------------------------- nptl/createthread.c | 3 ++- nptl/pthread_create.c | 17 +++++++------ 3 files changed, 16 insertions(+), 63 deletions(-) diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c index c0a5c4d96d..1a9ba5a52a 100644 --- a/nptl/allocatestack.c +++ b/nptl/allocatestack.c @@ -33,47 +33,6 @@ #include #include -#ifndef NEED_SEPARATE_REGISTER_STACK - -/* Most architectures have exactly one stack pointer. Some have more. */ -# define STACK_VARIABLES void *stackaddr = NULL - -/* How to pass the values to the 'create_thread' function. */ -# define STACK_VARIABLES_ARGS stackaddr - -/* How to declare function which gets there parameters. */ -# define STACK_VARIABLES_PARMS void *stackaddr - -/* How to declare allocate_stack. */ -# define ALLOCATE_STACK_PARMS void **stack - -/* This is how the function is called. We do it this way to allow - other variants of the function to have more parameters. */ -# define ALLOCATE_STACK(attr, pd) allocate_stack (attr, pd, &stackaddr) - -#else - -/* We need two stacks. The kernel will place them but we have to tell - the kernel about the size of the reserved address space. */ -# define STACK_VARIABLES void *stackaddr = NULL; size_t stacksize = 0 - -/* How to pass the values to the 'create_thread' function. */ -# define STACK_VARIABLES_ARGS stackaddr, stacksize - -/* How to declare function which gets there parameters. */ -# define STACK_VARIABLES_PARMS void *stackaddr, size_t stacksize - -/* How to declare allocate_stack. */ -# define ALLOCATE_STACK_PARMS void **stack, size_t *stacksize - -/* This is how the function is called. We do it this way to allow - other variants of the function to have more parameters. */ -# define ALLOCATE_STACK(attr, pd) \ - allocate_stack (attr, pd, &stackaddr, &stacksize) - -#endif - - /* Default alignment of stack. */ #ifndef STACK_ALIGN # define STACK_ALIGN __alignof__ (long double) @@ -249,7 +208,7 @@ advise_stack_range (void *mem, size_t size, uintptr_t pd, size_t guardsize) PDP must be non-NULL. */ static int allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, - ALLOCATE_STACK_PARMS) + void **stack, size_t *stacksize) { struct pthread *pd; size_t size; @@ -597,25 +556,17 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, /* We place the thread descriptor at the end of the stack. */ *pdp = pd; -#if _STACK_GROWS_DOWN void *stacktop; -# if TLS_TCB_AT_TP +#if TLS_TCB_AT_TP /* The stack begins before the TCB and the static TLS block. */ stacktop = ((char *) (pd + 1) - __static_tls_size); -# elif TLS_DTV_AT_TP +#elif TLS_DTV_AT_TP stacktop = (char *) (pd - 1); -# endif +#endif -# ifdef NEED_SEPARATE_REGISTER_STACK + *stacksize = stacktop - pd->stackblock; *stack = pd->stackblock; - *stacksize = stacktop - *stack; -# else - *stack = stacktop; -# endif -#else - *stack = pd->stackblock; -#endif return 0; } diff --git a/nptl/createthread.c b/nptl/createthread.c index 46943b33fe..2ac83111ec 100644 --- a/nptl/createthread.c +++ b/nptl/createthread.c @@ -25,7 +25,8 @@ static int create_thread (struct pthread *pd, const struct pthread_attr *attr, - bool *stopped_start, STACK_VARIABLES_PARMS, bool *thread_ran) + bool *stopped_start, void *stackaddr, size_t stacksize, + bool *thread_ran) { /* If the implementation needs to do some tweaks to the thread after it has been created at the OS level, it can set STOPPED_START here. */ diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index 770656453d..cacd1285aa 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -202,8 +202,8 @@ static struct rtld_global *__nptl_rtld_global __attribute_used__ be set to true iff the thread actually started up and then got canceled before calling user code (*PD->start_routine). */ static int create_thread (struct pthread *pd, const struct pthread_attr *attr, - bool *stopped_start, STACK_VARIABLES_PARMS, - bool *thread_ran); + bool *stopped_start, void *stackaddr, + size_t stacksize, bool *thread_ran); #include @@ -457,7 +457,8 @@ int __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg) { - STACK_VARIABLES; + void *stackaddr = NULL; + size_t stacksize = 0; /* Avoid a data race in the multi-threaded case. */ if (__libc_single_threaded) @@ -477,7 +478,7 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr, } struct pthread *pd = NULL; - int err = ALLOCATE_STACK (iattr, &pd); + int err = allocate_stack (iattr, &pd, &stackaddr, &stacksize); int retval = 0; if (__glibc_unlikely (err != 0)) @@ -622,8 +623,8 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr, /* We always create the thread stopped at startup so we can notify the debugger. */ - retval = create_thread (pd, iattr, &stopped_start, - STACK_VARIABLES_ARGS, &thread_ran); + retval = create_thread (pd, iattr, &stopped_start, stackaddr, + stacksize, &thread_ran); if (retval == 0) { /* We retain ownership of PD until (a) (see CONCURRENCY NOTES @@ -654,8 +655,8 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr, } } else - retval = create_thread (pd, iattr, &stopped_start, - STACK_VARIABLES_ARGS, &thread_ran); + retval = create_thread (pd, iattr, &stopped_start, stackaddr, + stacksize, &thread_ran); /* Return to the previous signal mask, after creating the new thread. */