[Glibc-bsd-commits] r4507 - trunk/glibc-ports/linuxthreads

Petr Salinger ps-guest at alioth.debian.org
Thu May 30 17:51:42 UTC 2013


Author: ps-guest
Date: 2013-05-30 17:51:42 +0000 (Thu, 30 May 2013)
New Revision: 4507

Modified:
   trunk/glibc-ports/linuxthreads/manager.c
Log:
manager.c part of "these are now mandatory":

USE___THREAD
HAVE_TLS_SUPPORT
FLOATING_STACKS
USE_TLS
HAVE___THREAD  
HAVE_Z_NODELETE
__ASSUME_REALTIME_SIGNALS




Modified: trunk/glibc-ports/linuxthreads/manager.c
===================================================================
--- trunk/glibc-ports/linuxthreads/manager.c	2013-05-30 17:42:37 UTC (rev 4506)
+++ trunk/glibc-ports/linuxthreads/manager.c	2013-05-30 17:51:42 UTC (rev 4507)
@@ -66,20 +66,7 @@
 /* Stack segment numbers are also indices into the __pthread_handles array. */
 /* Stack segment number 0 is reserved for the initial thread. */
 
-#if FLOATING_STACKS
 # define thread_segment(seq) NULL
-#else
-static inline pthread_descr thread_segment(int seg)
-{
-# ifdef _STACK_GROWS_UP
-  return (pthread_descr)(THREAD_STACK_START_ADDRESS + (seg - 1) * STACK_SIZE)
-         + 1;
-# else
-  return (pthread_descr)(THREAD_STACK_START_ADDRESS - (seg - 1) * STACK_SIZE)
-         - 1;
-# endif
-}
-#endif
 
 /* Flag set in signal handler to record child termination */
 
@@ -127,11 +114,6 @@
 #ifdef INIT_THREAD_SELF
   INIT_THREAD_SELF(self, 1);
 #endif
-#if !(USE_TLS && HAVE___THREAD)
-  /* Set the error variable.  */
-  self->p_errnop = &self->p_errno;
-  self->p_h_errnop = &self->p_h_errno;
-#endif
   /* Block all signals except __pthread_sig_cancel and SIGTRAP */
   sigfillset(&manager_mask);
   sigdelset(&manager_mask, __pthread_sig_cancel); /* for thread termination */
@@ -290,14 +272,9 @@
       __sched_setscheduler(THREAD_GETMEM(self, p_pid),
                            SCHED_OTHER, &default_params);
     }
-#if !(USE_TLS && HAVE___THREAD)
-  /* Initialize thread-locale current locale to point to the global one.
-     With __thread support, the variable's initializer takes care of this.  */
-  __uselocale (LC_GLOBAL_LOCALE);
-#else
   /* Initialize __resp.  */
   __resp = &self->p_res;
-#endif
+
   /* Make gdb aware of new thread */
   if (__pthread_threads_debug && __pthread_sig_debug > 0) {
     request.req_thread = self;
@@ -334,10 +311,6 @@
   pthread_start_thread (arg);
 }
 
-#if defined USE_TLS && !FLOATING_STACKS
-# error "TLS can only work with floating stacks"
-#endif
-
 static int pthread_allocate_stack(const pthread_attr_t *attr,
                                   pthread_descr default_new_thread,
                                   int pagesize,
@@ -352,23 +325,16 @@
   char * guardaddr;
   size_t stacksize, guardsize;
 
-#ifdef USE_TLS
   /* TLS cannot work with fixed thread descriptor addresses.  */
   assert (default_new_thread == NULL);
-#endif
 
   if (attr != NULL && attr->__stackaddr_set)
     {
 #ifdef _STACK_GROWS_UP
       /* The user provided a stack. */
-# ifdef USE_TLS
       /* This value is not needed.  */
       new_thread = (pthread_descr) attr->__stackaddr;
       new_thread_bottom = (char *) new_thread;
-# else
-      new_thread = (pthread_descr) attr->__stackaddr;
-      new_thread_bottom = (char *) (new_thread + 1);
-# endif
       guardaddr = attr->__stackaddr + attr->__stacksize;
       guardsize = 0;
 #else
@@ -382,12 +348,7 @@
 	 addresses, stackaddr would be the lowest address in the stack
 	 segment, so that it is consistently close to the initial sp
 	 value. */
-# ifdef USE_TLS
       new_thread = (pthread_descr) attr->__stackaddr;
-# else
-      new_thread =
-        (pthread_descr) ((long)(attr->__stackaddr) & -sizeof(void *)) - 1;
-# endif
       new_thread_bottom = (char *) attr->__stackaddr - attr->__stacksize;
       guardaddr = new_thread_bottom;
       guardsize = 0;
@@ -395,10 +356,6 @@
 #ifndef THREAD_SELF
       __pthread_nonstandard_stacks = 1;
 #endif
-#ifndef USE_TLS
-      /* Clear the thread data structure.  */
-      memset (new_thread, '\0', sizeof (*new_thread));
-#endif
       stacksize = attr->__stacksize;
     }
   else
@@ -412,7 +369,6 @@
       void *map_addr;
 
       /* Allocate space for stack and thread descriptor at default address */
-#if FLOATING_STACKS
       if (attr != NULL)
 	{
 	  guardsize = page_roundup (attr->__guardsize, granularity);
@@ -439,133 +395,25 @@
 	mprotect (guardaddr, guardsize, PROT_NONE);
 
       new_thread_bottom = (char *) map_addr;
-#  ifdef USE_TLS
       new_thread = ((pthread_descr) (new_thread_bottom + stacksize
 				     + guardsize));
-#  else
-      new_thread = ((pthread_descr) (new_thread_bottom + stacksize
-				     + guardsize)) - 1;
-#  endif
 # elif _STACK_GROWS_DOWN
       guardaddr = map_addr;
       if (guardsize > 0)
 	mprotect (guardaddr, guardsize, PROT_NONE);
 
       new_thread_bottom = (char *) map_addr + guardsize;
-#  ifdef USE_TLS
       new_thread = ((pthread_descr) (new_thread_bottom + stacksize));
-#  else
-      new_thread = ((pthread_descr) (new_thread_bottom + stacksize)) - 1;
-#  endif
 # elif _STACK_GROWS_UP
       guardaddr = map_addr + stacksize;
       if (guardsize > 0)
 	mprotect (guardaddr, guardsize, PROT_NONE);
 
       new_thread = (pthread_descr) map_addr;
-#  ifdef USE_TLS
       new_thread_bottom = (char *) new_thread;
-#  else
-      new_thread_bottom = (char *) (new_thread + 1);
-#  endif
 # else
 #  error You must define a stack direction
 # endif /* Stack direction */
-#else /* !FLOATING_STACKS */
-      void *res_addr;
-
-      if (attr != NULL)
-	{
-	  guardsize = page_roundup (attr->__guardsize, granularity);
-	  stacksize = STACK_SIZE - guardsize;
-	  stacksize = MIN (stacksize,
-			   page_roundup (attr->__stacksize, granularity));
-	}
-      else
-	{
-	  guardsize = granularity;
-	  stacksize = STACK_SIZE - granularity;
-	}
-
-# ifdef NEED_SEPARATE_REGISTER_STACK
-      new_thread = default_new_thread;
-      new_thread_bottom = (char *) (new_thread + 1) - stacksize - guardsize;
-      /* Includes guard area, unlike the normal case.  Use the bottom
-       end of the segment as backing store for the register stack.
-       Needed on IA64.  In this case, we also map the entire stack at
-       once.  According to David Mosberger, that's cheaper.  It also
-       avoids the risk of intermittent failures due to other mappings
-       in the same region.  The cost is that we might be able to map
-       slightly fewer stacks.  */
-
-      /* First the main stack: */
-      map_addr = (caddr_t)((char *)(new_thread + 1) - stacksize / 2);
-      res_addr = mmap(map_addr, stacksize / 2,
-		      PROT_READ | PROT_WRITE | PROT_EXEC,
-		      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-      if (res_addr != map_addr)
-	{
-	  /* Bad luck, this segment is already mapped. */
-	  if (res_addr != MAP_FAILED)
-	    munmap(res_addr, stacksize / 2);
-	  return -1;
-	}
-      /* Then the register stack:	*/
-      map_addr = (caddr_t)new_thread_bottom;
-      res_addr = mmap(map_addr, stacksize/2,
-		      PROT_READ | PROT_WRITE | PROT_EXEC,
-		      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-      if (res_addr != map_addr)
-	{
-	  if (res_addr != MAP_FAILED)
-	    munmap(res_addr, stacksize / 2);
-	  munmap((caddr_t)((char *)(new_thread + 1) - stacksize/2),
-		 stacksize/2);
-	  return -1;
-	}
-
-      guardaddr = new_thread_bottom + stacksize/2;
-      /* We leave the guard area in the middle unmapped.	*/
-# else  /* !NEED_SEPARATE_REGISTER_STACK */
-#  ifdef _STACK_GROWS_DOWN
-      new_thread = default_new_thread;
-      new_thread_bottom = (char *) (new_thread + 1) - stacksize;
-      map_addr = new_thread_bottom - guardsize;
-      res_addr = mmap(map_addr, stacksize + guardsize,
-		      PROT_READ | PROT_WRITE | PROT_EXEC,
-		      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-      if (res_addr != map_addr)
-	{
-	  /* Bad luck, this segment is already mapped. */
-	  if (res_addr != MAP_FAILED)
-	    munmap (res_addr, stacksize + guardsize);
-	  return -1;
-	}
-
-      /* We manage to get a stack.  Protect the guard area pages if
-	 necessary.  */
-      guardaddr = map_addr;
-      if (guardsize > 0)
-	mprotect (guardaddr, guardsize, PROT_NONE);
-#  else
-      /* The thread description goes at the bottom of this area, and
-       * the stack starts directly above it.
-       */
-      new_thread = (pthread_descr)((unsigned long)default_new_thread &~ (STACK_SIZE - 1));
-      map_addr = mmap(new_thread, stacksize + guardsize,
-		      PROT_READ | PROT_WRITE | PROT_EXEC,
-		      MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-      if (map_addr == MAP_FAILED)
-	  return -1;
-
-      new_thread_bottom = map_addr + sizeof(*new_thread);
-      guardaddr = map_addr + stacksize;
-      if (guardsize > 0)
-	  mprotect (guardaddr, guardsize, PROT_NONE);
-
-#  endif /* stack direction */
-# endif  /* !NEED_SEPARATE_REGISTER_STACK */
-#endif   /* !FLOATING_STACKS */
     }
   *out_new_thread = (char *) new_thread;
   *out_new_thread_bottom = new_thread_bottom;
@@ -596,7 +444,6 @@
   int pagesize = __getpagesize();
   int saved_errno = 0;
 
-#ifdef USE_TLS
   new_thread = _dl_allocate_tls (NULL);
   if (new_thread == NULL)
     return EAGAIN;
@@ -604,10 +451,6 @@
   /* pthread_descr is below TP.  */
   new_thread = (pthread_descr) ((char *) new_thread - TLS_PRE_TCB_SIZE);
 # endif
-#else
-  /* Prevent warnings.  */
-  new_thread = NULL;
-#endif
 
   /* First check whether we have to change the policy and if yes, whether
      we can  do this.  Normally this should be done by examining the
@@ -620,12 +463,10 @@
     {
       if (sseg >= PTHREAD_THREADS_MAX)
 	{
-#ifdef USE_TLS
 # if TLS_DTV_AT_TP
 	  new_thread = (pthread_descr) ((char *) new_thread + TLS_PRE_TCB_SIZE);
 # endif
 	  _dl_deallocate_tls (new_thread, true);
-#endif
 	  return EAGAIN;
 	}
       if (__pthread_handles[sseg].h_descr != NULL)
@@ -634,11 +475,7 @@
 				 pagesize, &stack_addr, &new_thread_bottom,
                                  &guardaddr, &guardsize, &stksize) == 0)
 	{
-#ifdef USE_TLS
 	  new_thread->p_stackaddr = stack_addr;
-#else
-	  new_thread = (pthread_descr) stack_addr;
-#endif
 	  break;
 	}
     }
@@ -648,22 +485,17 @@
   new_thread_id = sseg + pthread_threads_counter;
   /* Initialize the thread descriptor.  Elements which have to be
      initialized to zero already have this value.  */
-#if !defined USE_TLS || !TLS_DTV_AT_TP
+#if !TLS_DTV_AT_TP
   new_thread->p_header.data.tcb = new_thread;
   new_thread->p_header.data.self = new_thread;
 #endif
-#if TLS_MULTIPLE_THREADS_IN_TCB || !defined USE_TLS || !TLS_DTV_AT_TP
+#if TLS_MULTIPLE_THREADS_IN_TCB || !TLS_DTV_AT_TP
   new_thread->p_multiple_threads = 1;
 #endif
   new_thread->p_tid = new_thread_id;
   new_thread->p_lock = &(__pthread_handles[sseg].h_lock);
   new_thread->p_cancelstate = PTHREAD_CANCEL_ENABLE;
   new_thread->p_canceltype = PTHREAD_CANCEL_DEFERRED;
-#if !(USE_TLS && HAVE___THREAD)
-  new_thread->p_errnop = &new_thread->p_errno;
-  new_thread->p_h_errnop = &new_thread->p_h_errno;
-  new_thread->p_resp = &new_thread->p_res;
-#endif
   new_thread->p_guardaddr = guardaddr;
   new_thread->p_guardsize = guardsize;
   new_thread->p_nr = sseg;
@@ -809,28 +641,17 @@
 	munmap((caddr_t)new_thread_bottom,
 	       2 * stacksize + new_thread->p_guardsize);
 #elif _STACK_GROWS_UP
-# ifdef USE_TLS
 	size_t stacksize = guardaddr - stack_addr;
 	munmap(stack_addr, stacksize + guardsize);
-# else
-	size_t stacksize = guardaddr - (char *)new_thread;
-	munmap(new_thread, stacksize + guardsize);
-# endif
 #else
-# ifdef USE_TLS
 	size_t stacksize = stack_addr - new_thread_bottom;
-# else
-	size_t stacksize = (char *)(new_thread+1) - new_thread_bottom;
-# endif
 	munmap(new_thread_bottom - guardsize, guardsize + stacksize);
 #endif
       }
-#ifdef USE_TLS
 # if TLS_DTV_AT_TP
     new_thread = (pthread_descr) ((char *) new_thread + TLS_PRE_TCB_SIZE);
 # endif
     _dl_deallocate_tls (new_thread, true);
-#endif
     __pthread_handles[sseg].h_descr = NULL;
     __pthread_handles[sseg].h_bottom = NULL;
     __pthread_handles_num--;
@@ -892,21 +713,12 @@
       /* Free the stack and thread descriptor area */
       char *guardaddr = th->p_guardaddr;
 #ifdef _STACK_GROWS_UP
-# ifdef USE_TLS
       size_t stacksize = guardaddr - th->p_stackaddr;
       guardaddr = th->p_stackaddr;
-# else
-      size_t stacksize = guardaddr - (char *)th;
-      guardaddr = (char *)th;
-# endif
 #else
       /* Guardaddr is always set, even if guardsize is 0.  This allows
 	 us to compute everything else.  */
-# ifdef USE_TLS
       size_t stacksize = th->p_stackaddr - guardaddr - guardsize;
-# else
-      size_t stacksize = (char *)(th+1) - guardaddr - guardsize;
-# endif
 # ifdef NEED_SEPARATE_REGISTER_STACK
       /* Take account of the register stack, which is below guardaddr.  */
       guardaddr -= stacksize;
@@ -918,12 +730,10 @@
 
     }
 
-#ifdef USE_TLS
 # if TLS_DTV_AT_TP
   th = (pthread_descr) ((char *) th + TLS_PRE_TCB_SIZE);
 # endif
   _dl_deallocate_tls (th, true);
-#endif
 }
 
 /* Handle threads that have exited */




More information about the Glibc-bsd-commits mailing list