Просмотр исходного кода

sync with glibc by moving the thread_desc stuff out of internals.h and into a new file descr.h ... also redo thread_desc init by specifying members in the struct by name rather than position

Mike Frysinger 20 лет назад
Родитель
Сommit
43014917a3

+ 310 - 0
libpthread/linuxthreads/descr.h

@@ -0,0 +1,310 @@
+/* Linuxthreads - a simple clone()-based implementation of Posix        */
+/* threads for Linux.                                                   */
+/* Copyright (C) 1996 Xavier Leroy (Xavier.Leroy@inria.fr)              */
+/*                                                                      */
+/* This program is free software; you can redistribute it and/or        */
+/* modify it under the terms of the GNU Library General Public License  */
+/* as published by the Free Software Foundation; either version 2       */
+/* of the License, or (at your option) any later version.               */
+/*                                                                      */
+/* This program is distributed in the hope that it will be useful,      */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of       */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        */
+/* GNU Library General Public License for more details.                 */
+
+#ifndef _DESCR_H
+#define _DESCR_H	1
+
+#include <features.h>
+#include <sched.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <tls.h>
+
+#if 1
+# include <bits/libc-tsd.h>
+#else
+/* Fast thread-specific data internal to libc.  */
+enum __libc_tsd_key_t { _LIBC_TSD_KEY_MALLOC = 0,
+			_LIBC_TSD_KEY_DL_ERROR,
+			_LIBC_TSD_KEY_RPC_VARS,
+			_LIBC_TSD_KEY_LOCALE,
+			_LIBC_TSD_KEY_CTYPE_B,
+			_LIBC_TSD_KEY_CTYPE_TOLOWER,
+			_LIBC_TSD_KEY_CTYPE_TOUPPER,
+			_LIBC_TSD_KEY_N };
+#endif
+
+/* The type of thread descriptors */
+typedef struct _pthread_descr_struct *pthread_descr;
+
+
+/* Some more includes.  */
+#include <pt-machine.h>
+#include "../linuxthreads_db/thread_dbP.h"
+
+
+/* Arguments passed to thread creation routine */
+struct pthread_start_args {
+  void *(*start_routine)(void *); /* function to run */
+  void *arg;                      /* its argument */
+  sigset_t mask;                  /* initial signal mask for thread */
+  int schedpolicy;                /* initial scheduling policy (if any) */
+  struct sched_param schedparam;  /* initial scheduling parameters (if any) */
+};
+
+
+/* Callback interface for removing the thread from waiting on an
+   object if it is cancelled while waiting or about to wait.
+   This hold a pointer to the object, and a pointer to a function
+   which ``extricates'' the thread from its enqueued state.
+   The function takes two arguments: pointer to the wait object,
+   and a pointer to the thread. It returns 1 if an extrication
+   actually occured, and hence the thread must also be signalled.
+   It returns 0 if the thread had already been extricated. */
+typedef struct _pthread_extricate_struct {
+    void *pu_object;
+    int (*pu_extricate_func)(void *, pthread_descr);
+} pthread_extricate_if;
+
+
+/* Atomic counter made possible by compare_and_swap */
+struct pthread_atomic {
+  long p_count;
+  int p_spinlock;
+};
+
+
+/* Context info for read write locks. The pthread_rwlock_info structure
+   is information about a lock that has been read-locked by the thread
+   in whose list this structure appears. The pthread_rwlock_context
+   is embedded in the thread context and contains a pointer to the
+   head of the list of lock info structures, as well as a count of
+   read locks that are untracked, because no info structure could be
+   allocated for them. */
+struct _pthread_rwlock_t;
+typedef struct _pthread_rwlock_info {
+  struct _pthread_rwlock_info *pr_next;
+  struct _pthread_rwlock_t *pr_lock;
+  int pr_lock_count;
+} pthread_readlock_info;
+
+
+/* We keep thread specific data in a special data structure, a two-level
+   array.  The top-level array contains pointers to dynamically allocated
+   arrays of a certain number of data pointers.  So we can implement a
+   sparse array.  Each dynamic second-level array has
+	PTHREAD_KEY_2NDLEVEL_SIZE
+   entries.  This value shouldn't be too large.  */
+#define PTHREAD_KEY_2NDLEVEL_SIZE	32
+
+/* We need to address PTHREAD_KEYS_MAX key with PTHREAD_KEY_2NDLEVEL_SIZE
+   keys in each subarray.  */
+#define PTHREAD_KEY_1STLEVEL_SIZE \
+  ((PTHREAD_KEYS_MAX + PTHREAD_KEY_2NDLEVEL_SIZE - 1) \
+   / PTHREAD_KEY_2NDLEVEL_SIZE)
+
+
+union dtv;
+
+struct _pthread_descr_struct
+{
+#if !defined USE_TLS || !TLS_DTV_AT_TP
+  /* This overlaps tcbhead_t (see tls.h), as used for TLS without threads.  */
+  union
+  {
+    struct
+    {
+      void *tcb;		/* Pointer to the TCB.  This is not always
+				   the address of this thread descriptor.  */
+      union dtv *dtvp;
+      pthread_descr self;	/* Pointer to this structure */
+      int multiple_threads;
+# ifdef NEED_DL_SYSINFO
+      uintptr_t sysinfo;
+# endif
+    } data;
+    void *__padding[16];
+  } p_header;
+# define p_multiple_threads p_header.data.multiple_threads
+#elif TLS_MULTIPLE_THREADS_IN_TCB
+  int p_multiple_threads;
+#endif
+
+  pthread_descr p_nextlive, p_prevlive;
+                                /* Double chaining of active threads */
+  pthread_descr p_nextwaiting;  /* Next element in the queue holding the thr */
+  pthread_descr p_nextlock;	/* can be on a queue and waiting on a lock */
+  pthread_t p_tid;              /* Thread identifier */
+  int p_pid;                    /* PID of Unix process */
+  int p_priority;               /* Thread priority (== 0 if not realtime) */
+  struct _pthread_fastlock * p_lock; /* Spinlock for synchronized accesses */
+  int p_signal;                 /* last signal received */
+  sigjmp_buf * p_signal_jmp;    /* where to siglongjmp on a signal or NULL */
+  sigjmp_buf * p_cancel_jmp;    /* where to siglongjmp on a cancel or NULL */
+  char p_terminated;            /* true if terminated e.g. by pthread_exit */
+  char p_detached;              /* true if detached */
+  char p_exited;                /* true if the assoc. process terminated */
+  void * p_retval;              /* placeholder for return value */
+  int p_retcode;                /* placeholder for return code */
+  pthread_descr p_joining;      /* thread joining on that thread or NULL */
+  struct _pthread_cleanup_buffer * p_cleanup; /* cleanup functions */
+  char p_cancelstate;           /* cancellation state */
+  char p_canceltype;            /* cancellation type (deferred/async) */
+  char p_canceled;              /* cancellation request pending */
+  char * p_in_sighandler;       /* stack address of sighandler, or NULL */
+  char p_sigwaiting;            /* true if a sigwait() is in progress */
+  struct pthread_start_args p_start_args; /* arguments for thread creation */
+  void ** p_specific[PTHREAD_KEY_1STLEVEL_SIZE]; /* thread-specific data */
+#if !(USE_TLS && HAVE___THREAD)
+  void * p_libc_specific[_LIBC_TSD_KEY_N]; /* thread-specific data for libc */
+  int * p_errnop;               /* pointer to used errno variable */
+  int p_errno;                  /* error returned by last system call */
+  int * p_h_errnop;             /* pointer to used h_errno variable */
+  int p_h_errno;                /* error returned by last netdb function */
+#endif
+  int p_userstack;		/* nonzero if the user provided the stack */
+  void *p_guardaddr;		/* address of guard area or NULL */
+  size_t p_guardsize;		/* size of guard area */
+  pthread_descr p_self;		/* Pointer to this structure */
+  int p_nr;                     /* Index of descriptor in __pthread_handles */
+  int p_report_events;		/* Nonzero if events must be reported.  */
+  td_eventbuf_t p_eventbuf;     /* Data for event.  */
+  struct pthread_atomic p_resume_count; /* number of times restart() was
+					   called on thread */
+  char p_woken_by_cancel;       /* cancellation performed wakeup */
+  char p_condvar_avail;		/* flag if conditional variable became avail */
+  char p_sem_avail;             /* flag if semaphore became available */
+  pthread_extricate_if *p_extricate; /* See above */
+  pthread_readlock_info *p_readlock_list;  /* List of readlock info structs */
+  pthread_readlock_info *p_readlock_free;  /* Free list of structs */
+  int p_untracked_readlock_count;	/* Readlocks not tracked by list */
+  int p_inheritsched;           /* copied from the thread attribute */
+#if HP_TIMING_AVAIL
+  hp_timing_t p_cpuclock_offset; /* Initial CPU clock for thread.  */
+#endif
+#ifdef USE_TLS
+  char *p_stackaddr;		/* Stack address.  */
+#endif
+  size_t p_alloca_cutoff;	/* Maximum size which should be allocated
+				   using alloca() instead of malloc().  */
+  /* New elements must be added at the end.  */
+#ifdef __UCLIBC_HAS_XLOCALE__
+  __locale_t locale; /* thread-specific locale from uselocale() only! */
+#endif /* __UCLIBC_HAS_XLOCALE__ */
+} __attribute__ ((aligned(32))); /* We need to align the structure so that
+				    doubles are aligned properly.  This is 8
+				    bytes on MIPS and 16 bytes on MIPS64.
+				    32 bytes might give better cache
+				    utilization.  */
+
+
+
+/* Limit between the stack of the initial thread (above) and the
+   stacks of other threads (below). Aligned on a STACK_SIZE boundary.
+   Initially 0, meaning that the current thread is (by definition)
+   the initial thread. */
+
+/* For non-MMU systems also remember to stack top of the initial thread.
+ * This is adapted when other stacks are malloc'ed since we don't know
+ * the bounds a-priori. -StS */
+
+extern char *__pthread_initial_thread_bos;
+#ifndef __ARCH_HAS_MMU__
+extern char *__pthread_initial_thread_tos;
+#define NOMMU_INITIAL_THREAD_BOUNDS(tos,bos) if ((tos)>=__pthread_initial_thread_bos && (bos)<=__pthread_initial_thread_tos) __pthread_initial_thread_bos = (tos)+1
+#else
+#define NOMMU_INITIAL_THREAD_BOUNDS(tos,bos) /* empty */
+#endif /* __ARCH_HAS_MMU__ */
+
+/* Descriptor of the initial thread */
+
+extern struct _pthread_descr_struct __pthread_initial_thread;
+
+/* Limits of the thread manager stack. */
+
+extern char *__pthread_manager_thread_bos;
+extern char *__pthread_manager_thread_tos;
+
+/* Descriptor of the manager thread */
+
+extern struct _pthread_descr_struct __pthread_manager_thread;
+extern pthread_descr __pthread_manager_threadp attribute_hidden;
+
+/* Indicate whether at least one thread has a user-defined stack (if 1),
+   or all threads have stacks supplied by LinuxThreads (if 0). */
+
+extern int __pthread_nonstandard_stacks;
+
+/* The max size of the thread stack segments.  If the default
+   THREAD_SELF implementation is used, this must be a power of two and
+   a multiple of PAGE_SIZE.  */
+#ifndef STACK_SIZE
+#ifdef __ARCH_HAS_MMU__
+#define STACK_SIZE  (2 * 1024 * 1024)
+#else
+#define STACK_SIZE  (4 * __pagesize)
+#endif
+#endif
+
+/* Get some notion of the current stack.  Need not be exactly the top
+   of the stack, just something somewhere in the current frame.  */
+#ifndef CURRENT_STACK_FRAME
+#define CURRENT_STACK_FRAME  ({ char __csf; &__csf; })
+#endif
+
+/* Recover thread descriptor for the current thread */
+
+extern pthread_descr __pthread_find_self (void) __attribute__ ((pure));
+
+static inline pthread_descr thread_self (void) __attribute__ ((pure));
+static inline pthread_descr thread_self (void)
+{
+#ifdef THREAD_SELF
+  return THREAD_SELF;
+#else
+  char *sp = CURRENT_STACK_FRAME;
+#ifdef __ARCH_HAS_MMU__
+  if (sp >= __pthread_initial_thread_bos)
+    return &__pthread_initial_thread;
+  else if (sp >= __pthread_manager_thread_bos
+	   && sp < __pthread_manager_thread_tos)
+    return &__pthread_manager_thread;
+  else if (__pthread_nonstandard_stacks)
+    return __pthread_find_self();
+  else
+#ifdef _STACK_GROWS_DOWN
+    return (pthread_descr)(((unsigned long)sp | (STACK_SIZE-1))+1) - 1;
+#else
+    return (pthread_descr)((unsigned long)sp &~ (STACK_SIZE-1));
+#endif
+#else /* !__ARCH_HAS_MMU__ */
+  /* For non-MMU we need to be more careful about the initial thread stack.
+   * We refine the initial thread stack bounds dynamically as we allocate
+   * the other stack frame such that it doesn't overlap with them. Then
+   * we can be sure to pick the right thread according to the current SP */
+
+  /* Since we allow other stack frames to be above or below, we need to
+   * treat this case special. When pthread_initialize() wasn't called yet,
+   * only the initial thread is there. */
+  if (__pthread_initial_thread_bos == NULL) {
+      return &__pthread_initial_thread;
+  }
+  else if (sp >= __pthread_initial_thread_bos
+	   && sp < __pthread_initial_thread_tos) {
+      return &__pthread_initial_thread;
+  }
+  else if (sp >= __pthread_manager_thread_bos
+	   && sp < __pthread_manager_thread_tos) {
+      return &__pthread_manager_thread;
+  }
+  else {
+      return __pthread_find_self();
+  }
+#endif /* __ARCH_HAS_MMU__ */
+#endif
+}
+
+#endif	/* descr.h */

+ 29 - 224
libpthread/linuxthreads/internals.h

@@ -19,6 +19,7 @@
 
 
 /* Includes */
 /* Includes */
 
 
+#include <features.h>
 #include <bits/libc-tsd.h> /* for _LIBC_TSD_KEY_N */
 #include <bits/libc-tsd.h> /* for _LIBC_TSD_KEY_N */
 #include <limits.h>
 #include <limits.h>
 #include <setjmp.h>
 #include <setjmp.h>
@@ -27,8 +28,10 @@
 #include <bits/stackinfo.h>
 #include <bits/stackinfo.h>
 #include <sys/types.h>
 #include <sys/types.h>
 #include "pt-machine.h"
 #include "pt-machine.h"
+#include <ucontext.h>
+#include <bits/sigcontextinfo.h>
 #include "semaphore.h"
 #include "semaphore.h"
-#include "../linuxthreads_db/thread_dbP.h"
+#include "descr.h"
 #ifdef __UCLIBC_HAS_XLOCALE__
 #ifdef __UCLIBC_HAS_XLOCALE__
 #include <bits/uClibc_locale.h>
 #include <bits/uClibc_locale.h>
 #endif /* __UCLIBC_HAS_XLOCALE__ */
 #endif /* __UCLIBC_HAS_XLOCALE__ */
@@ -52,30 +55,14 @@
 # define THREAD_SETMEM_NC(descr, member, value) descr->member = (value)
 # define THREAD_SETMEM_NC(descr, member, value) descr->member = (value)
 #endif
 #endif
 
 
-/* Arguments passed to thread creation routine */
+#if !defined NOT_IN_libc && defined FLOATING_STACKS
-
+# define LIBC_THREAD_GETMEM(descr, member) THREAD_GETMEM (descr, member)
-struct pthread_start_args {
+# define LIBC_THREAD_SETMEM(descr, member, value) \
-  void * (*start_routine)(void *); /* function to run */
+  THREAD_SETMEM (descr, member, value)
-  void * arg;                   /* its argument */
+#else
-  sigset_t mask;                /* initial signal mask for thread */
+# define LIBC_THREAD_GETMEM(descr, member) descr->member
-  int schedpolicy;              /* initial scheduling policy (if any) */
+# define LIBC_THREAD_SETMEM(descr, member, value) descr->member = (value)
-  struct sched_param schedparam; /* initial scheduling parameters (if any) */
+#endif
-};
-
-
-/* We keep thread specific data in a special data structure, a two-level
-   array.  The top-level array contains pointers to dynamically allocated
-   arrays of a certain number of data pointers.  So we can implement a
-   sparse array.  Each dynamic second-level array has
-	PTHREAD_KEY_2NDLEVEL_SIZE
-   entries.  This value shouldn't be too large.  */
-#define PTHREAD_KEY_2NDLEVEL_SIZE	32
-
-/* We need to address PTHREAD_KEYS_MAX key with PTHREAD_KEY_2NDLEVEL_SIZE
-   keys in each subarray.  */
-#define PTHREAD_KEY_1STLEVEL_SIZE \
-  ((PTHREAD_KEYS_MAX + PTHREAD_KEY_2NDLEVEL_SIZE - 1) \
-   / PTHREAD_KEY_2NDLEVEL_SIZE)
 
 
 typedef void (*destr_function)(void *);
 typedef void (*destr_function)(void *);
 
 
@@ -85,105 +72,9 @@ struct pthread_key_struct {
 };
 };
 
 
 
 
-#define PTHREAD_START_ARGS_INITIALIZER { NULL, NULL, {{0, }}, 0, { 0 } }
+#define PTHREAD_START_ARGS_INITIALIZER(fct) \
-
+  { (void *(*) (void *)) fct, NULL, {{0, }}, 0, { 0 } }
-/* The type of thread descriptors */
-
-typedef struct _pthread_descr_struct * pthread_descr;
-
-/* Callback interface for removing the thread from waiting on an
-   object if it is cancelled while waiting or about to wait.
-   This hold a pointer to the object, and a pointer to a function
-   which ``extricates'' the thread from its enqueued state.
-   The function takes two arguments: pointer to the wait object,
-   and a pointer to the thread. It returns 1 if an extrication
-   actually occured, and hence the thread must also be signalled.
-   It returns 0 if the thread had already been extricated. */
-
-typedef struct _pthread_extricate_struct {
-    void *pu_object;
-    int (*pu_extricate_func)(void *, pthread_descr);
-} pthread_extricate_if;
-
-/* Atomic counter made possible by compare_and_swap */
-
-struct pthread_atomic {
-  long p_count;
-  int p_spinlock;
-};
 
 
-/* Context info for read write locks. The pthread_rwlock_info structure
-   is information about a lock that has been read-locked by the thread
-   in whose list this structure appears. The pthread_rwlock_context
-   is embedded in the thread context and contains a pointer to the
-   head of the list of lock info structures, as well as a count of
-   read locks that are untracked, because no info structure could be
-   allocated for them. */
-
-struct _pthread_rwlock_t;
-
-typedef struct _pthread_rwlock_info {
-  struct _pthread_rwlock_info *pr_next;
-  struct _pthread_rwlock_t *pr_lock;
-  int pr_lock_count;
-} pthread_readlock_info;
-
-struct _pthread_descr_struct {
-  pthread_descr p_nextlive, p_prevlive;
-                                /* Double chaining of active threads */
-  pthread_descr p_nextwaiting;  /* Next element in the queue holding the thr */
-  pthread_descr p_nextlock;	/* can be on a queue and waiting on a lock */
-  pthread_t p_tid;              /* Thread identifier */
-  int p_pid;                    /* PID of Unix process */
-  int p_priority;               /* Thread priority (== 0 if not realtime) */
-  struct _pthread_fastlock * p_lock; /* Spinlock for synchronized accesses */
-  int p_signal;                 /* last signal received */
-  sigjmp_buf * p_signal_jmp;    /* where to siglongjmp on a signal or NULL */
-  sigjmp_buf * p_cancel_jmp;    /* where to siglongjmp on a cancel or NULL */
-  char p_terminated;            /* true if terminated e.g. by pthread_exit */
-  char p_detached;              /* true if detached */
-  char p_exited;                /* true if the assoc. process terminated */
-  void * p_retval;              /* placeholder for return value */
-  int p_retcode;                /* placeholder for return code */
-  pthread_descr p_joining;      /* thread joining on that thread or NULL */
-  struct _pthread_cleanup_buffer * p_cleanup; /* cleanup functions */
-  char p_cancelstate;           /* cancellation state */
-  char p_canceltype;            /* cancellation type (deferred/async) */
-  char p_canceled;              /* cancellation request pending */
-  int * p_errnop;               /* pointer to used errno variable */
-  int p_errno;                  /* error returned by last system call */
-  int * p_h_errnop;             /* pointer to used h_errno variable */
-  int p_h_errno;                /* error returned by last netdb function */
-  char * p_in_sighandler;       /* stack address of sighandler, or NULL */
-  char p_sigwaiting;            /* true if a sigwait() is in progress */
-  struct pthread_start_args p_start_args; /* arguments for thread creation */
-  void ** p_specific[PTHREAD_KEY_1STLEVEL_SIZE]; /* thread-specific data */
-  void * p_libc_specific[_LIBC_TSD_KEY_N]; /* thread-specific data for libc */
-  int p_userstack;		/* nonzero if the user provided the stack */
-  void *p_guardaddr;		/* address of guard area or NULL */
-  size_t p_guardsize;		/* size of guard area */
-  pthread_descr p_self;		/* Pointer to this structure */
-  int p_nr;                     /* Index of descriptor in __pthread_handles */
-  int p_report_events;         /* Nonzero if events must be reported.  */
-  td_eventbuf_t p_eventbuf;     /* Data for event.  */
-  struct pthread_atomic p_resume_count; /* number of times restart() was
-					   called on thread */
-  char p_woken_by_cancel;       /* cancellation performed wakeup */
-  char p_condvar_avail;         /* flag if conditional variable became avail */
-  char p_sem_avail;             /* flag if semaphore became available */
-  pthread_extricate_if *p_extricate; /* See above */
-  pthread_readlock_info *p_readlock_list;  /* List of readlock info structs */
-  pthread_readlock_info *p_readlock_free;  /* Free list of structs */
-  int p_untracked_readlock_count;	/* Readlocks not tracked by list */
-  /* New elements must be added at the end.  */
-#ifdef __UCLIBC_HAS_XLOCALE__
-  __locale_t locale; /* thread-specific locale from uselocale() only! */
-#endif /* __UCLIBC_HAS_XLOCALE__ */
-} __attribute__ ((aligned(32))); /* We need to align the structure so that
-				    doubles are aligned properly.  This is 8
-				    bytes on MIPS and 16 bytes on MIPS64.
-				    32 bytes might give better cache
-				    utilization.  */
 
 
 /* The type of thread handles. */
 /* The type of thread handles. */
 
 
@@ -225,6 +116,16 @@ struct pthread_request {
 };
 };
 
 
 
 
+
+typedef void (*arch_sighandler_t) (int, SIGCONTEXT);
+union sighandler
+{
+  arch_sighandler_t old;
+  void (*rt) (int, struct siginfo *, struct ucontext *);
+};
+extern union sighandler __sighandler[NSIG];
+
+
 /* Signals used for suspend/restart and for cancellation notification.  */
 /* Signals used for suspend/restart and for cancellation notification.  */
 
 
 extern int __pthread_sig_restart;
 extern int __pthread_sig_restart;
@@ -240,41 +141,10 @@ extern int __pthread_sig_debug;
 
 
 extern struct pthread_handle_struct __pthread_handles[PTHREAD_THREADS_MAX];
 extern struct pthread_handle_struct __pthread_handles[PTHREAD_THREADS_MAX];
 
 
-/* Descriptor of the initial thread */
-
-extern struct _pthread_descr_struct __pthread_initial_thread;
-
-/* Descriptor of the manager thread */
-
-extern struct _pthread_descr_struct __pthread_manager_thread;
-
 /* Descriptor of the main thread */
 /* Descriptor of the main thread */
 
 
 extern pthread_descr __pthread_main_thread;
 extern pthread_descr __pthread_main_thread;
 
 
-/* Limit between the stack of the initial thread (above) and the
-   stacks of other threads (below). Aligned on a STACK_SIZE boundary.
-   Initially 0, meaning that the current thread is (by definition)
-   the initial thread. */
-
-/* For non-MMU systems also remember to stack top of the initial thread.
- * This is adapted when other stacks are malloc'ed since we don't know
- * the bounds a-priori. -StS */
-
-extern char *__pthread_initial_thread_bos;
-#ifndef __ARCH_HAS_MMU__
-extern char *__pthread_initial_thread_tos;
-#define NOMMU_INITIAL_THREAD_BOUNDS(tos,bos) if ((tos)>=__pthread_initial_thread_bos && (bos)<=__pthread_initial_thread_tos) __pthread_initial_thread_bos = (tos)+1
-#else
-#define NOMMU_INITIAL_THREAD_BOUNDS(tos,bos) /* empty */
-#endif /* __ARCH_HAS_MMU__ */
-
-
-/* Indicate whether at least one thread has a user-defined stack (if 1),
-   or all threads have stacks supplied by LinuxThreads (if 0). */
-
-extern int __pthread_nonstandard_stacks;
-
 /* File descriptor for sending requests to the thread manager.
 /* File descriptor for sending requests to the thread manager.
    Initially -1, meaning that __pthread_initialize_manager must be called. */
    Initially -1, meaning that __pthread_initialize_manager must be called. */
 
 
@@ -289,11 +159,6 @@ extern int __pthread_manager_reader;
 extern size_t __pthread_max_stacksize;
 extern size_t __pthread_max_stacksize;
 #endif
 #endif
 
 
-/* Limits of the thread manager stack. */
-
-extern char *__pthread_manager_thread_bos;
-extern char *__pthread_manager_thread_tos;
-
 /* Pending request for a process-wide exit */
 /* Pending request for a process-wide exit */
 
 
 extern int __pthread_exit_requested, __pthread_exit_code;
 extern int __pthread_exit_requested, __pthread_exit_code;
@@ -321,6 +186,11 @@ static inline pthread_handle thread_handle(pthread_t id)
 /* Validate a thread handle. Must have acquired h->h_spinlock before. */
 /* Validate a thread handle. Must have acquired h->h_spinlock before. */
 
 
 static inline int invalid_handle(pthread_handle h, pthread_t id)
 static inline int invalid_handle(pthread_handle h, pthread_t id)
+{
+  return h->h_descr == NULL || h->h_descr->p_tid != id || h->h_descr->p_terminated;
+}
+
+static inline int nonexisting_handle(pthread_handle h, pthread_t id)
 {
 {
   return h->h_descr == NULL || h->h_descr->p_tid != id;
   return h->h_descr == NULL || h->h_descr->p_tid != id;
 }
 }
@@ -351,17 +221,6 @@ extern size_t __pagesize;
 #define THREAD_MANAGER_STACK_SIZE  (2 * __pagesize - 32)
 #define THREAD_MANAGER_STACK_SIZE  (2 * __pagesize - 32)
 #endif
 #endif
 
 
-/* The max size of the thread stack segments.  If the default
-   THREAD_SELF implementation is used, this must be a power of two and
-   a multiple of PAGE_SIZE.  */
-#ifndef STACK_SIZE
-#ifdef __ARCH_HAS_MMU__
-#define STACK_SIZE  (2 * 1024 * 1024)
-#else
-#define STACK_SIZE  (4 * __pagesize)
-#endif
-#endif
-
 /* The base of the "array" of thread stacks.  The array will grow down from
 /* The base of the "array" of thread stacks.  The array will grow down from
    here.  Defaults to the calculated bottom of the initial application
    here.  Defaults to the calculated bottom of the initial application
    stack.  */
    stack.  */
@@ -369,12 +228,6 @@ extern size_t __pagesize;
 #define THREAD_STACK_START_ADDRESS  __pthread_initial_thread_bos
 #define THREAD_STACK_START_ADDRESS  __pthread_initial_thread_bos
 #endif
 #endif
 
 
-/* Get some notion of the current stack.  Need not be exactly the top
-   of the stack, just something somewhere in the current frame.  */
-#ifndef CURRENT_STACK_FRAME
-#define CURRENT_STACK_FRAME  ({ char __csf; &__csf; })
-#endif
-
 /* If MEMORY_BARRIER isn't defined in pt-machine.h, assume the
 /* If MEMORY_BARRIER isn't defined in pt-machine.h, assume the
    architecture doesn't need a memory barrier instruction (e.g. Intel
    architecture doesn't need a memory barrier instruction (e.g. Intel
    x86).  Still we need the compiler to respect the barrier and emit
    x86).  Still we need the compiler to respect the barrier and emit
@@ -415,54 +268,6 @@ extern size_t __pagesize;
 #define SPIN_SLEEP_DURATION 2000001
 #define SPIN_SLEEP_DURATION 2000001
 #endif
 #endif
 
 
-/* Recover thread descriptor for the current thread */
-
-extern pthread_descr __pthread_find_self (void) __attribute__ ((const));
-
-static inline pthread_descr thread_self (void) __attribute__ ((const));
-static inline pthread_descr thread_self (void)
-{
-#ifdef THREAD_SELF
-  return THREAD_SELF;
-#else
-  char *sp = CURRENT_STACK_FRAME;
-#ifdef __ARCH_HAS_MMU__
-  if (sp >= __pthread_initial_thread_bos)
-    return &__pthread_initial_thread;
-  else if (sp >= __pthread_manager_thread_bos
-	   && sp < __pthread_manager_thread_tos)
-    return &__pthread_manager_thread;
-  else if (__pthread_nonstandard_stacks)
-    return __pthread_find_self();
-  else
-    return (pthread_descr)(((unsigned long)sp | (STACK_SIZE-1))+1) - 1;
-#else
-  /* For non-MMU we need to be more careful about the initial thread stack.
-   * We refine the initial thread stack bounds dynamically as we allocate
-   * the other stack frame such that it doesn't overlap with them. Then
-   * we can be sure to pick the right thread according to the current SP */
-
-  /* Since we allow other stack frames to be above or below, we need to
-   * treat this case special. When pthread_initialize() wasn't called yet,
-   * only the initial thread is there. */
-  if (__pthread_initial_thread_bos == NULL) {
-      return &__pthread_initial_thread;
-  }
-  else if (sp >= __pthread_initial_thread_bos
-	   && sp < __pthread_initial_thread_tos) {
-      return &__pthread_initial_thread;
-  }
-  else if (sp >= __pthread_manager_thread_bos
-	   && sp < __pthread_manager_thread_tos) {
-      return &__pthread_manager_thread;
-  }
-  else {
-      return __pthread_find_self();
-  }
-#endif /* __ARCH_HAS_MMU__ */
-#endif
-}
-
 /* Debugging */
 /* Debugging */
 
 
 #ifdef DEBUG
 #ifdef DEBUG

+ 110 - 94
libpthread/linuxthreads/pthread.c

@@ -54,55 +54,63 @@ extern int _h_errno;
 /* Descriptor of the initial thread */
 /* Descriptor of the initial thread */
 
 
 struct _pthread_descr_struct __pthread_initial_thread = {
 struct _pthread_descr_struct __pthread_initial_thread = {
-  &__pthread_initial_thread,  /* pthread_descr p_nextlive */
+  .p_nextlive = &__pthread_initial_thread,
-  &__pthread_initial_thread,  /* pthread_descr p_prevlive */
+  .p_prevlive = &__pthread_initial_thread,
-  NULL,                       /* pthread_descr p_nextwaiting */
+  .p_nextwaiting = NULL,
-  NULL,			      /* pthread_descr p_nextlock */
+  .p_nextlock = NULL,
-  PTHREAD_THREADS_MAX,        /* pthread_t p_tid */
+  .p_tid = PTHREAD_THREADS_MAX,
-  0,                          /* int p_pid */
+  .p_pid = 0,
-  0,                          /* int p_priority */
+  .p_priority = 0,
-  &__pthread_handles[0].h_lock, /* struct _pthread_fastlock * p_lock */
+  .p_lock = &__pthread_handles[0].h_lock,
-  0,                          /* int p_signal */
+  .p_signal = 0,
-  NULL,                       /* sigjmp_buf * p_signal_buf */
+  .p_signal_jmp = NULL,
-  NULL,                       /* sigjmp_buf * p_cancel_buf */
+  .p_cancel_jmp = NULL,
-  0,                          /* char p_terminated */
+  .p_terminated = 0,
-  0,                          /* char p_detached */
+  .p_detached = 0,
-  0,                          /* char p_exited */
+  .p_exited = 0,
-  NULL,                       /* void * p_retval */
+  .p_retval = NULL,
-  0,                          /* int p_retval */
+  .p_retcode = 0,
-  NULL,                       /* pthread_descr p_joining */
+  .p_joining = NULL,
-  NULL,                       /* struct _pthread_cleanup_buffer * p_cleanup */
+  .p_cleanup = NULL,
-  0,                          /* char p_cancelstate */
+  .p_cancelstate = 0,
-  0,                          /* char p_canceltype */
+  .p_canceltype = 0,
-  0,                          /* char p_canceled */
+  .p_canceled = 0,
-  &_errno,                       /* int *p_errnop */
+  .p_errnop = &_errno,
-  0,                          /* int p_errno */
+  .p_errno = 0,
-  &_h_errno,                       /* int *p_h_errnop */
+  .p_h_errnop = &_h_errno,
-  0,                          /* int p_h_errno */
+  .p_h_errno = 0,
-  NULL,                       /* char * p_in_sighandler */
+  .p_in_sighandler = NULL,
-  0,                          /* char p_sigwaiting */
+  .p_sigwaiting = 0,
-  PTHREAD_START_ARGS_INITIALIZER, /* struct pthread_start_args p_start_args */
+  .p_start_args = PTHREAD_START_ARGS_INITIALIZER(NULL),
-  {NULL},                     /* void ** p_specific[PTHREAD_KEY_1STLEVEL_SIZE] */
+  .p_specific = {NULL},
-  {NULL},                     /* void * p_libc_specific[_LIBC_TSD_KEY_N] */
+  .p_libc_specific = {NULL},
-  0,                          /* int p_userstack */
+  .p_userstack = 0,
-  NULL,                       /* void * p_guardaddr */
+  .p_guardaddr = NULL,
-  0,                          /* size_t p_guardsize */
+  .p_guardsize = 0,
-  &__pthread_initial_thread,  /* pthread_descr p_self */
+  .p_self = &__pthread_initial_thread,
-  0,                          /* Always index 0 */
+  .p_nr = 0,
-  0,                          /* int p_report_events */
+  .p_report_events = 0,
-  {{{0, }}, 0, NULL},         /* td_eventbuf_t p_eventbuf */
+  .p_eventbuf = {{{0, }}, 0, NULL},
-  __ATOMIC_INITIALIZER,         /* struct pthread_atomic p_resume_count */
+  .p_resume_count = __ATOMIC_INITIALIZER,
-  0,                          /* char p_woken_by_cancel */
+  .p_woken_by_cancel = 0,
-  0,                          /* char p_condvar_avail */
+  .p_condvar_avail = 0,
-  0,                          /* char p_sem_avail */
+  .p_sem_avail = 0,
-  NULL,                       /* struct pthread_extricate_if *p_extricate */
+  .p_extricate = NULL,
-  NULL,	                      /* pthread_readlock_info *p_readlock_list; */
+  .p_readlock_list = NULL,
-  NULL,                       /* pthread_readlock_info *p_readlock_free; */
+  .p_readlock_free = NULL,
-  0                           /* int p_untracked_readlock_count; */
+  .p_untracked_readlock_count = 0,
+  .p_inheritsched = 0,
+#if HP_TIMING_AVAIL
+  .p_cpuclock_offset = 0,
+#endif
+#ifdef USE_TLS
+  .p_stackaddr = NULL,
+#endif
+  .p_alloca_cutoff = 0
 #ifdef __UCLIBC_HAS_XLOCALE__
 #ifdef __UCLIBC_HAS_XLOCALE__
   ,
   ,
-  &__global_locale_data,      /* __locale_t locale; */
+  .locale = &__global_locale_data
-#endif /* __UCLIBC_HAS_XLOCALE__ */
+#endif
 };
 };
 
 
 /* Descriptor of the manager thread; none of this is used but the error
 /* Descriptor of the manager thread; none of this is used but the error
@@ -110,55 +118,63 @@ struct _pthread_descr_struct __pthread_initial_thread = {
    and the address for identification.  */
    and the address for identification.  */
 #define manager_thread (&__pthread_manager_thread)
 #define manager_thread (&__pthread_manager_thread)
 struct _pthread_descr_struct __pthread_manager_thread = {
 struct _pthread_descr_struct __pthread_manager_thread = {
-  NULL,                       /* pthread_descr p_nextlive */
+  .p_nextlive = NULL,
-  NULL,                       /* pthread_descr p_prevlive */
+  .p_prevlive = NULL,
-  NULL,                       /* pthread_descr p_nextwaiting */
+  .p_nextwaiting = NULL,
-  NULL,			      /* pthread_descr p_nextlock */
+  .p_nextlock = NULL,
-  0,                          /* int p_tid */
+  .p_tid = 0,
-  0,                          /* int p_pid */
+  .p_pid = 0,
-  0,                          /* int p_priority */
+  .p_priority = 0,
-  &__pthread_handles[1].h_lock, /* struct _pthread_fastlock * p_lock */
+  .p_lock = &__pthread_handles[1].h_lock,
-  0,                          /* int p_signal */
+  .p_signal = 0,
-  NULL,                       /* sigjmp_buf * p_signal_buf */
+  .p_signal_jmp = NULL,
-  NULL,                       /* sigjmp_buf * p_cancel_buf */
+  .p_cancel_jmp = NULL,
-  0,                          /* char p_terminated */
+  .p_terminated = 0,
-  0,                          /* char p_detached */
+  .p_detached = 0,
-  0,                          /* char p_exited */
+  .p_exited = 0,
-  NULL,                       /* void * p_retval */
+  .p_retval = NULL,
-  0,                          /* int p_retval */
+  .p_retcode = 0,
-  NULL,                       /* pthread_descr p_joining */
+  .p_joining = NULL,
-  NULL,                       /* struct _pthread_cleanup_buffer * p_cleanup */
+  .p_cleanup = NULL,
-  0,                          /* char p_cancelstate */
+  .p_cancelstate = 0,
-  0,                          /* char p_canceltype */
+  .p_canceltype = 0,
-  0,                          /* char p_canceled */
+  .p_canceled = 0,
-  &__pthread_manager_thread.p_errno, /* int *p_errnop */
+  .p_errnop = &__pthread_manager_thread.p_errno,
-  0,                          /* int p_errno */
+  .p_errno = 0,
-  NULL,                       /* int *p_h_errnop */
+  .p_h_errnop = NULL,
-  0,                          /* int p_h_errno */
+  .p_h_errno = 0,
-  NULL,                       /* char * p_in_sighandler */
+  .p_in_sighandler = NULL,
-  0,                          /* char p_sigwaiting */
+  .p_sigwaiting = 0,
-  PTHREAD_START_ARGS_INITIALIZER, /* struct pthread_start_args p_start_args */
+  .p_start_args = PTHREAD_START_ARGS_INITIALIZER(__pthread_manager),
-  {NULL},                     /* void ** p_specific[PTHREAD_KEY_1STLEVEL_SIZE] */
+  .p_specific = {NULL},
-  {NULL},                     /* void * p_libc_specific[_LIBC_TSD_KEY_N] */
+  .p_libc_specific = {NULL},
-  0,                          /* int p_userstack */
+  .p_userstack = 0,
-  NULL,                       /* void * p_guardaddr */
+  .p_guardaddr = NULL,
-  0,                          /* size_t p_guardsize */
+  .p_guardsize = 0,
-  &__pthread_manager_thread,  /* pthread_descr p_self */
+  .p_self = &__pthread_manager_thread,
-  1,                          /* Always index 1 */
+  .p_nr = 1,
-  0,                          /* int p_report_events */
+  .p_report_events = 0,
-  {{{0, }}, 0, NULL},         /* td_eventbuf_t p_eventbuf */
+  .p_eventbuf = {{{0, }}, 0, NULL},
-  __ATOMIC_INITIALIZER,         /* struct pthread_atomic p_resume_count */
+  .p_resume_count = __ATOMIC_INITIALIZER,
-  0,                          /* char p_woken_by_cancel */
+  .p_woken_by_cancel = 0,
-  0,                          /* char p_condvar_avail */
+  .p_condvar_avail = 0,
-  0,                          /* char p_sem_avail */
+  .p_sem_avail = 0,
-  NULL,                       /* struct pthread_extricate_if *p_extricate */
+  .p_extricate = NULL,
-  NULL,	                      /* pthread_readlock_info *p_readlock_list; */
+  .p_readlock_list = NULL,
-  NULL,                       /* pthread_readlock_info *p_readlock_free; */
+  .p_readlock_free = NULL,
-  0                           /* int p_untracked_readlock_count; */
+  .p_untracked_readlock_count = 0,
+  .p_inheritsched = 0,
+#if HP_TIMING_AVAIL
+  .p_cpuclock_offset = 0,
+#endif
+#ifdef USE_TLS
+  .p_stackaddr = NULL,
+#endif
+  .p_alloca_cutoff = 0
 #ifdef __UCLIBC_HAS_XLOCALE__
 #ifdef __UCLIBC_HAS_XLOCALE__
   ,
   ,
-  &__global_locale_data,      /* __locale_t locale; */
+  &__global_locale_data
-#endif /* __UCLIBC_HAS_XLOCALE__ */
+#endif
 };
 };
 
 
 /* Pointer to the main thread (the father of the thread manager thread) */
 /* Pointer to the main thread (the father of the thread manager thread) */

+ 0 - 1
libpthread/linuxthreads/signals.c

@@ -77,7 +77,6 @@ int pthread_kill(pthread_t thread, int signo)
 }
 }
 
 
 /* User-provided signal handlers */
 /* User-provided signal handlers */
-typedef void (*arch_sighandler_t) __PMT ((int, SIGCONTEXT));
 static union
 static union
 {
 {
   arch_sighandler_t old;
   arch_sighandler_t old;