&& mprotect (oldguard, guard - oldguard, PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
&& mprotect (oldguard, guard - oldguard, prot) != 0)
allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,		ALLOCATE_STACK_PARMS){  struct pthread *pd;  size_t size;  size_t pagesize_m1 = __getpagesize () - 1;  void *stacktop;  assert (attr != NULL);  assert (powerof2 (pagesize_m1 + 1));  assert (TCB_ALIGNMENT >= STACK_ALIGN);  /* Get the stack size from the attribute if it is set.  Otherwise we     use the default we determined at start time.  */  size = attr->stacksize ?: __default_stacksize;  /* Get memory for the stack.  */  if (__builtin_expect (attr->flags & ATTR_FLAG_STACKADDR, 0))    {      uintptr_t adj;      /* If the user also specified the size of the stack make sure it	 is large enough.  */      if (attr->stacksize != 0	  && attr->stacksize < (__static_tls_size + MINIMAL_REST_STACK))	return EINVAL;      /* Adjust stack size for alignment of the TLS block.  */#if TLS_TCB_AT_TP      adj = ((uintptr_t) attr->stackaddr - TLS_TCB_SIZE)	    & __static_tls_align_m1;      assert (size > adj + TLS_TCB_SIZE);#elif TLS_DTV_AT_TP      adj = ((uintptr_t) attr->stackaddr - __static_tls_size)	    & __static_tls_align_m1;      assert (size > adj);#endif      /* The user provided some memory.  Let's hope it matches the	 size...  We do not allocate guard pages if the user provided	 the stack.  It is the user's responsibility to do this if it	 is wanted.  */#if TLS_TCB_AT_TP      pd = (struct pthread *) ((uintptr_t) attr->stackaddr			       - TLS_TCB_SIZE - adj);#elif TLS_DTV_AT_TP      pd = (struct pthread *) (((uintptr_t) attr->stackaddr			        - __static_tls_size - adj)			       - TLS_PRE_TCB_SIZE);#endif      /* The user provided stack memory needs to be cleared.  */      memset (pd, '\0', sizeof (struct pthread));      /* The first TSD block is included in the TCB.  */      pd->specific[0] = pd->specific_1stblock;#if defined __ASSUME_CLONE_STOPPED && LLL_LOCK_INITIALIZER != 0      /* Initialize the lock.  */      pd->lock = LLL_LOCK_INITIALIZER;#endif      /* Remember the stack-related values.  */      pd->stackblock = (char *) attr->stackaddr - size;      pd->stackblock_size = size;      /* This is a user-provided stack.  It will not be queued in the	 stack cache nor will the memory (except the TLS memory) be freed.  */      pd->user_stack = true;      /* This is at least the second thread.  */      pd->header.multiple_threads = 1;#ifndef TLS_MULTIPLE_THREADS_IN_TCB      __pthread_multiple_threads = *__libc_multiple_threads_ptr = 1;#endif#ifdef NEED_DL_SYSINFO      /* Copy the sysinfo value from the parent.  */      pd->header.sysinfo = THREAD_GETMEM (THREAD_SELF, header.sysinfo);#endif      /* The process ID is also the same as that of the caller.  */      pd->pid = THREAD_GETMEM (THREAD_SELF, pid);      /* Allocate the DTV for this thread.  */      if (_dl_allocate_tls (TLS_TPADJ (pd)) == NULL)	/* Something went wrong.  */	return errno;      /* Prepare to modify global data.  */      lll_lock (stack_cache_lock);      /* And add to the list of stacks in use.  */      list_add (&pd->list, &__stack_user);      lll_unlock (stack_cache_lock);    }  else    {      /* Allocate some anonymous memory.  If possible use the	 cache.  */      size_t guardsize;      size_t reqsize;      void *mem;#if COLORING_INCREMENT != 0      /* Add one more page for stack coloring.  Don't do it for stacks	 with 16 times pagesize or larger.  This might just cause	 unnecessary misalignment.  */      if (size <= 16 * pagesize_m1)	size += pagesize_m1 + 1;#endif      /* Adjust the stack size for alignment.  */      size &= ~__static_tls_align_m1;      assert (size != 0);      /* Make sure the size of the stack is enough for the guard and	 eventually the thread descriptor.  */      guardsize = (attr->guardsize + pagesize_m1) & ~pagesize_m1;      if (__builtin_expect (size < (guardsize + __static_tls_size				    + MINIMAL_REST_STACK + pagesize_m1 + 1),			    0))	/* The stack is too small (or the guard too large).  */	return EINVAL;      /* Try to get a stack from the cache.  */      reqsize = size;      pd = get_cached_stack (&size, &mem);      if (pd == NULL)	{	  /* To avoid aliasing effects on a larger scale then pages we	     adjust the allocated stack size if necessary.  This way	     allocations directly following each other will not have	     aliasing problems.  */#if MULTI_PAGE_ALIASING != 0	  if ((size % MULTI_PAGE_ALIASING) == 0)	    size += pagesize_m1 + 1;#endif	  mem = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,		      MAP_PRIVATE | MAP_ANONYMOUS | ARCH_MAP_FLAGS, -1, 0);	  if (__builtin_expect (mem == MAP_FAILED, 0))	    {#ifdef ARCH_RETRY_MMAP	      mem = ARCH_RETRY_MMAP (size);	      if (__builtin_expect (mem == MAP_FAILED, 0))#endif		return errno;	    }	  /* SIZE is guaranteed to be greater than zero.	     So we can never get a null pointer back from mmap.  */	  assert (mem != NULL);#if COLORING_INCREMENT != 0	  /* Atomically increment NCREATED.  */	  unsigned int ncreated = (atomic_exchange_and_add (&nptl_ncreated, 1)				   + 1);	  /* We chose the offset for coloring by incrementing it for	     every new thread by a fixed amount.  The offset used	     module the page size.  Even if coloring would be better	     relative to higher alignment values it makes no sense to	     do it since the mmap() interface does not allow us to	     specify any alignment for the returned memory block.  */	  size_t coloring = (ncreated * COLORING_INCREMENT) & pagesize_m1;	  /* Make sure the coloring offsets does not disturb the alignment	     of the TCB and static TLS block.  */	  if (__builtin_expect ((coloring & __static_tls_align_m1) != 0, 0))	    coloring = (((coloring + __static_tls_align_m1)			 & ~(__static_tls_align_m1))			& ~pagesize_m1);#else	  /* Unless specified we do not make any adjustments.  */# define coloring 0#endif	  /* Place the thread descriptor at the end of the stack.  */#if TLS_TCB_AT_TP	  pd = (struct pthread *) ((char *) mem + size - coloring) - 1;#elif TLS_DTV_AT_TP	  pd = (struct pthread *) ((((uintptr_t) mem + size - coloring				    - __static_tls_size)				    & ~__static_tls_align_m1)				   - TLS_PRE_TCB_SIZE);#endif	  /* Remember the stack-related values.  */	  pd->stackblock = mem;	  pd->stackblock_size = size;	  /* We allocated the first block thread-specific data array.	     This address will not change for the lifetime of this	     descriptor.  */	  pd->specific[0] = pd->specific_1stblock;#if defined __ASSUME_CLONE_STOPPED && LLL_LOCK_INITIALIZER != 0	  /* Initialize the lock.  */	  pd->lock = LLL_LOCK_INITIALIZER;#endif	  /* This is at least the second thread.  */	  pd->header.multiple_threads = 1;#ifndef TLS_MULTIPLE_THREADS_IN_TCB	  __pthread_multiple_threads = *__libc_multiple_threads_ptr = 1;#endif#ifdef NEED_DL_SYSINFO	  /* Copy the sysinfo value from the parent.  */	  pd->header.sysinfo = THREAD_GETMEM (THREAD_SELF, header.sysinfo);#endif	  /* The process ID is also the same as that of the caller.  */	  pd->pid = THREAD_GETMEM (THREAD_SELF, pid);	  /* Allocate the DTV for this thread.  */	  if (_dl_allocate_tls (TLS_TPADJ (pd)) == NULL)	    {	      /* Something went wrong.  */	      int err = errno;	      /* Free the stack memory we just allocated.  */	      (void) munmap (mem, size);	      return err;	    }	  /* Prepare to modify global data.  */	  lll_lock (stack_cache_lock);	  /* And add to the list of stacks in use.  */	  list_add (&pd->list, &stack_used);	  lll_unlock (stack_cache_lock);	  /* Note that all of the stack and the thread descriptor is	     zeroed.  This means we do not have to initialize fields	     with initial value zero.  This is specifically true for	     the 'tid' field which is always set back to zero once the	     stack is not used anymore and for the 'guardsize' field	     which will be read next.  */	}      /* Create or resize the guard area if necessary.  */      if (__builtin_expect (guardsize > pd->guardsize, 0))	{#ifdef NEED_SEPARATE_REGISTER_STACK	  char *guard = mem + (((size - guardsize) / 2) & ~pagesize_m1);#else	  char *guard = mem;#endif	  if (mprotect (guard, guardsize, PROT_NONE) != 0)	    {	      int err;	    mprot_error:	      err = errno;	      lll_lock (stack_cache_lock);	      /* Remove the thread from the list.  */	      list_del (&pd->list);	      lll_unlock (stack_cache_lock);	      /* Get rid of the TLS block we allocated.  */	      _dl_deallocate_tls (TLS_TPADJ (pd), false);	      /* Free the stack memory regardless of whether the size		 of the cache is over the limit or not.  If this piece		 of memory caused problems we better do not use it		 anymore.  Uh, and we ignore possible errors.  There		 is nothing we could do.  */	      (void) munmap (mem, size);	      return err;	    }	  pd->guardsize = guardsize;	}      else if (__builtin_expect (pd->guardsize - guardsize > size - reqsize,				 0))	{	  /* The old guard area is too large.  */#ifdef NEED_SEPARATE_REGISTER_STACK	  char *guard = mem + (((size - guardsize) / 2) & ~pagesize_m1);	  char *oldguard = mem + (((size - pd->guardsize) / 2) & ~pagesize_m1);	  if (oldguard < guard	      && mprotect (oldguard, guard - oldguard,			   PROT_READ | PROT_WRITE | PROT_EXEC) != 0)	    goto mprot_error;	  if (mprotect (guard + guardsize,			oldguard + pd->guardsize - guard - guardsize,			PROT_READ | PROT_WRITE | PROT_EXEC) != 0)	    goto mprot_error;#else	  if (mprotect ((char *) mem + guardsize, pd->guardsize - guardsize,			PROT_READ | PROT_WRITE | PROT_EXEC) != 0)	    goto mprot_error;#endif	  pd->guardsize = guardsize;	}    }#ifndef __ASSUME_CLONE_STOPPED  /* Initialize the lock.  We have to do this unconditionally if the     CLONE_STOPPED flag is not available since then the stillborn     thread could be canceled while the lock is taken.  */  pd->lock = LLL_LOCK_INITIALIZER;#endif  /* We place the thread descriptor at the end of the stack.  */  *pdp = pd;#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  stacktop = (char *) (pd - 1);#endif#ifdef NEED_SEPARATE_REGISTER_STACK  *stack = pd->stackblock;  *stacksize = stacktop - *stack;#else  *stack = stacktop;#endif  return 0;}