pd->header.data.sysinfo = THREAD_GETMEM (THREAD_SELF, header.data.sysinfo);
pd->sysinfo = THREAD_GETMEM (THREAD_SELF, sysinfo);
allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,		void **stack){  struct pthread *pd;  size_t size;  size_t pagesize_m1 = __getpagesize () - 1;  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.  */      adj = ((uintptr_t) attr->stackaddr) & __static_tls_align_m1;      assert (size > adj);      /* 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.  */      pd = (struct pthread *) (((uintptr_t) attr->stackaddr - adj)			       & ~(__alignof (struct pthread) - 1)) - 1;      /* 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 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 - adj;      /* 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.data.multiple_threads = 1;#ifdef NEED_DL_SYSINFO      /* Copy the sysinfo value from the parent.  */      pd->header.data.sysinfo	= THREAD_GETMEM (THREAD_SELF, header.data.sysinfo);#endif      /* Allocate the DTV for this thread.  */      if (_dl_allocate_tls (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->header.data.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 to 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)	{	  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))	    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);	  /* 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.  */	  pd = (struct pthread *) ((char *) mem + size - coloring) - 1;	  /* 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 LLL_LOCK_INITIALIZER != 0	  /* Initialize the lock.  */	  pd->lock = LLL_LOCK_INITIALIZER;#endif	  /* This is at least the second thread.  */	  pd->header.data.multiple_threads = 1;#ifdef NEED_DL_SYSINFO	  /* Copy the sysinfo value from the parent.  */	  pd->header.data.sysinfo	    = THREAD_GETMEM (THREAD_SELF, header.data.sysinfo);#endif	  /* Allocate the DTV for this thread.  */	  if (_dl_allocate_tls (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->header.data.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))	{	  if (mprotect (mem, guardsize, PROT_NONE) != 0)	    {	      int err;	    mprot_error:	      err = errno;	      lll_lock (stack_cache_lock);	      /* Remove the thread from the list.  */	      list_del (&pd->header.data.list);	      lll_unlock (stack_cache_lock);	      /* Get rid of the TLS block we allocated.  */	      _dl_deallocate_tls (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.  */	  if (mprotect ((char *) mem + guardsize, pd->guardsize - guardsize,			PROT_READ | PROT_WRITE | PROT_EXEC) != 0)	    goto mprot_error;	  pd->guardsize = guardsize;	}    }  /* 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.  */  *stack = ((char *) (pd + 1) - __static_tls_size);#else# error "Implement me"#endif  return 0;}