Back to index

glibc  2.9
tls.h
Go to the documentation of this file.
00001 /* Definition for thread-local data handling.  linuxthreads/hppa version.
00002    Copyright (C) 2005 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _TLS_H
00021 #define _TLS_H
00022 
00023 #ifndef __ASSEMBLER__
00024 # include <pt-machine.h>
00025 # include <stdbool.h>
00026 # include <stddef.h>
00027 
00028 /* Type for the dtv.  */
00029 typedef union dtv
00030 {
00031   size_t counter;
00032   struct
00033   {
00034     void *val;
00035     bool is_static;
00036   } pointer;
00037 } dtv_t;
00038 
00039 #else /* __ASSEMBLER__ */
00040 # include <tcb-offsets.h>
00041 #endif /* __ASSEMBLER__ */
00042 
00043 
00044 #if defined HAVE_TLS_SUPPORT 
00045 
00046 /* Signal that TLS support is available.  */
00047 # define USE_TLS     1
00048 
00049 # ifndef __ASSEMBLER__
00050 
00051 typedef struct
00052 {
00053   dtv_t *dtv;
00054   void *private;
00055 } tcbhead_t;
00056 
00057 /* Include some syscall information for other headers */
00058 #  include <sysdep.h>
00059 
00060 /* This is the size of the initial TCB.  */
00061 #  define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
00062 
00063 /* Alignment requirements for the initial TCB.  */
00064 #  define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
00065 
00066 /* This is the size of the TCB.  */
00067 #  define TLS_TCB_SIZE sizeof (tcbhead_t)
00068 
00069 /* This is the size we need before TCB.  */
00070 #  define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct)
00071 
00072 /* Alignment requirements for the TCB.  */
00073 #  define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
00074 
00075 /* The TLS blocks start right after the TCB.  */
00076 #  define TLS_DTV_AT_TP     1
00077 
00078 /* Return the thread descriptor for the current thread.  */
00079 #  undef THREAD_SELF
00080 #  define THREAD_SELF                            \
00081   ({ struct _pthread_descr_struct *__self;       \
00082        __self = __get_cr27();                    \
00083        __self - 1;                        \
00084    })
00085 
00086 #  undef INIT_THREAD_SELF
00087 #  define INIT_THREAD_SELF(descr, nr)                          \
00088   ({ struct _pthread_descr_struct *__self = (void *)descr;     \
00089        __set_cr27(__self + 1);                                 \
00090        0;                                               \
00091    })
00092 
00093 /* Access to data in the thread descriptor is easy.  */
00094 #define THREAD_GETMEM(descr, member) \
00095   ((void) sizeof (descr), THREAD_SELF->member)
00096 #define THREAD_GETMEM_NC(descr, member) \
00097   ((void) sizeof (descr), THREAD_SELF->member)
00098 #define THREAD_SETMEM(descr, member, value) \
00099   ((void) sizeof (descr), THREAD_SELF->member = (value))
00100 #define THREAD_SETMEM_NC(descr, member, value) \
00101   ((void) sizeof (descr), THREAD_SELF->member = (value))
00102 
00103 /* Install the dtv pointer.  The pointer passed is to the element with
00104    index -1 which contain the length.  */
00105 #  define INSTALL_DTV(tcbp, dtvp) \
00106   ((tcbhead_t *) (tcbp))->dtv = dtvp + 1
00107 
00108 /* Install new dtv for current thread.  */
00109 #  define INSTALL_NEW_DTV(dtv) \
00110   ({ tcbhead_t *__tcbp = (tcbhead_t *)__get_cr27();     \
00111        __tcbp->dtv = dtv;                        \
00112    })
00113 
00114 /* Return dtv of given thread descriptor.  */
00115 #  define GET_DTV(tcbp) \
00116   (((tcbhead_t *) (tcbp))->dtv)
00117 
00118 /* Code to initially initialize the thread pointer.  This might need
00119    special attention since 'errno' is not yet available and if the
00120    operation can cause a failure 'errno' must not be touched.  */
00121 #  define TLS_INIT_TP(tcbp, secondcall) \
00122   ({ __set_cr27(tcbp); 0; })
00123 
00124 /* Return the address of the dtv for the current thread.  */
00125 #  define THREAD_DTV()                                  \
00126   ({ tcbhead_t *__tcbp = (tcbhead_t *)__get_cr27();     \
00127        __tcbp->dtv;                              \
00128    })
00129 
00130 # define TLS_MULTIPLE_THREADS_IN_TCB 1
00131 
00132 /* Get the thread descriptor definition.  This must be after the
00133    the definition of THREAD_SELF for TLS.  */
00134 #  include <linuxthreads/descr.h>
00135 
00136 # endif /* __ASSEMBLER__ */
00137 
00138 #else
00139 
00140 # ifndef __ASSEMBLER__
00141 
00142 typedef struct
00143 {
00144   void *tcb;
00145   dtv_t *dtv;
00146   void *self;
00147   int multiple_threads;
00148 } tcbhead_t;
00149 
00150 /* Get the thread descriptor definition.  */
00151 #  include <linuxthreads/descr.h>
00152 
00153 #  define NONTLS_INIT_TP \
00154   do {                                                                \
00155     static const tcbhead_t nontls_init_tp = { .multiple_threads = 0 };       \
00156     INIT_THREAD_SELF(&nontls_init_tp, 0);                      \
00157   } while (0)
00158 
00159 # endif /* __ASSEMBLER__ */
00160 
00161 #endif /* HAVE_TLS_SUPPORT */
00162 
00163 #endif /* tls.h */