diff mbox series

[09/13] nptl: Simplify the change_stack_perm calling convention

Message ID ef929637e500700116868d02f0f359ad2e0bbd5b.1620323953.git.fweimer@redhat.com
State Committed
Commit ee07b3a7222746fafc5d5cb2163c9609b81615ef
Headers show
Series Linux: Move most stack management out of libpthread | expand

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Florian Weimer May 6, 2021, 6:11 p.m. UTC
Only ia64 needs the page mask, and it is straightforward
to compute the value within the function itself.
---
 nptl/allocatestack.c | 29 +++++------------------------
 1 file changed, 5 insertions(+), 24 deletions(-)

Comments

Carlos O'Donell May 9, 2021, 9:42 p.m. UTC | #1
On 5/6/21 2:11 PM, Florian Weimer via Libc-alpha wrote:
> Only ia64 needs the page mask, and it is straightforward
> to compute the value within the function itself.

LGTM.

Tested on x86_64 and i686 without regression.

Tested-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>


> ---
>  nptl/allocatestack.c | 29 +++++------------------------
>  1 file changed, 5 insertions(+), 24 deletions(-)
> 
> diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
> index 71cfa874d1..46089163f4 100644
> --- a/nptl/allocatestack.c
> +++ b/nptl/allocatestack.c
> @@ -293,13 +293,10 @@ queue_stack (struct pthread *stack)
>  
>  
>  static int
> -change_stack_perm (struct pthread *pd
> -#ifdef NEED_SEPARATE_REGISTER_STACK
> -		   , size_t pagemask
> -#endif
> -		   )
> +change_stack_perm (struct pthread *pd)
>  {
>  #ifdef NEED_SEPARATE_REGISTER_STACK
> +  size_t pagemask = __getpagesize () - 1;
>    void *stack = (pd->stackblock
>  		 + (((((pd->stackblock_size - pd->guardsize) / 2)
>  		      & pagemask) + pd->guardsize) & pagemask));
> @@ -628,11 +625,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
>  	  if (__builtin_expect ((GL(dl_stack_flags) & PF_X) != 0
>  				&& (prot & PROT_EXEC) == 0, 0))
>  	    {
> -	      int err = change_stack_perm (pd
> -#ifdef NEED_SEPARATE_REGISTER_STACK
> -					   , ~pagesize_m1
> -#endif
> -					   );
> +	      int err = change_stack_perm (pd);
>  	      if (err != 0)
>  		{
>  		  /* Free the stack memory we just allocated.  */
> @@ -796,20 +789,12 @@ __make_stacks_executable (void **stack_endp)
>    if (err != 0)
>      return err;
>  
> -#ifdef NEED_SEPARATE_REGISTER_STACK
> -  const size_t pagemask = ~(__getpagesize () - 1);
> -#endif
> -
>    lll_lock (GL (dl_stack_cache_lock), LLL_PRIVATE);
>  
>    list_t *runp;
>    list_for_each (runp, &GL (dl_stack_used))
>      {
> -      err = change_stack_perm (list_entry (runp, struct pthread, list)
> -#ifdef NEED_SEPARATE_REGISTER_STACK
> -			       , pagemask
> -#endif
> -			       );
> +      err = change_stack_perm (list_entry (runp, struct pthread, list));
>        if (err != 0)
>  	break;
>      }
> @@ -820,11 +805,7 @@ __make_stacks_executable (void **stack_endp)
>    if (err == 0)
>      list_for_each (runp, &GL (dl_stack_cache))
>        {
> -	err = change_stack_perm (list_entry (runp, struct pthread, list)
> -#ifdef NEED_SEPARATE_REGISTER_STACK
> -				 , pagemask
> -#endif
> -				 );
> +	err = change_stack_perm (list_entry (runp, struct pthread, list));
>  	if (err != 0)
>  	  break;
>        }
>
diff mbox series

Patch

diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index 71cfa874d1..46089163f4 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -293,13 +293,10 @@  queue_stack (struct pthread *stack)
 
 
 static int
-change_stack_perm (struct pthread *pd
-#ifdef NEED_SEPARATE_REGISTER_STACK
-		   , size_t pagemask
-#endif
-		   )
+change_stack_perm (struct pthread *pd)
 {
 #ifdef NEED_SEPARATE_REGISTER_STACK
+  size_t pagemask = __getpagesize () - 1;
   void *stack = (pd->stackblock
 		 + (((((pd->stackblock_size - pd->guardsize) / 2)
 		      & pagemask) + pd->guardsize) & pagemask));
@@ -628,11 +625,7 @@  allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
 	  if (__builtin_expect ((GL(dl_stack_flags) & PF_X) != 0
 				&& (prot & PROT_EXEC) == 0, 0))
 	    {
-	      int err = change_stack_perm (pd
-#ifdef NEED_SEPARATE_REGISTER_STACK
-					   , ~pagesize_m1
-#endif
-					   );
+	      int err = change_stack_perm (pd);
 	      if (err != 0)
 		{
 		  /* Free the stack memory we just allocated.  */
@@ -796,20 +789,12 @@  __make_stacks_executable (void **stack_endp)
   if (err != 0)
     return err;
 
-#ifdef NEED_SEPARATE_REGISTER_STACK
-  const size_t pagemask = ~(__getpagesize () - 1);
-#endif
-
   lll_lock (GL (dl_stack_cache_lock), LLL_PRIVATE);
 
   list_t *runp;
   list_for_each (runp, &GL (dl_stack_used))
     {
-      err = change_stack_perm (list_entry (runp, struct pthread, list)
-#ifdef NEED_SEPARATE_REGISTER_STACK
-			       , pagemask
-#endif
-			       );
+      err = change_stack_perm (list_entry (runp, struct pthread, list));
       if (err != 0)
 	break;
     }
@@ -820,11 +805,7 @@  __make_stacks_executable (void **stack_endp)
   if (err == 0)
     list_for_each (runp, &GL (dl_stack_cache))
       {
-	err = change_stack_perm (list_entry (runp, struct pthread, list)
-#ifdef NEED_SEPARATE_REGISTER_STACK
-				 , pagemask
-#endif
-				 );
+	err = change_stack_perm (list_entry (runp, struct pthread, list));
 	if (err != 0)
 	  break;
       }