Back to index

glibc  2.9
tls.h
Go to the documentation of this file.
00001 /* Definitions for thread-local data handling.  linuxthreads/sparc version.
00002    Copyright (C) 2002, 2003, 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 
00025 # include <pt-machine.h>
00026 # include <stdbool.h>
00027 # include <stddef.h>
00028 # include <stdint.h>
00029 
00030 /* Type for the dtv.  */
00031 typedef union dtv
00032 {
00033   size_t counter;
00034   struct
00035   {
00036     void *val;
00037     bool is_static;
00038   } pointer;
00039 } dtv_t;
00040 
00041 typedef struct
00042 {
00043   void *tcb;         /* Pointer to the TCB.  Not necessary the
00044                         thread descriptor used by libpthread.  */
00045   dtv_t *dtv;
00046   void *self;        /* Pointer to the thread descriptor.  */
00047   int multiple_threads;
00048   uintptr_t sysinfo;
00049   uintptr_t stack_guard;
00050   uintptr_t pointer_guard;
00051 } tcbhead_t;
00052 
00053 #else /* __ASSEMBLER__ */
00054 # include <tcb-offsets.h>
00055 #endif /* __ASSEMBLER__ */
00056 
00057 #ifdef HAVE_TLS_SUPPORT
00058 
00059 /* Signal that TLS support is available.  */
00060 # define USE_TLS     1
00061 
00062 # ifndef __ASSEMBLER__
00063 /* Get system call information.  */
00064 #  include <sysdep.h>
00065 
00066 /* Get the thread descriptor definition.  */
00067 #  include <linuxthreads/descr.h>
00068 
00069 /* This is the size of the initial TCB.  */
00070 #  define TLS_INIT_TCB_SIZE sizeof (tcbhead_t)
00071 
00072 /* Alignment requirements for the initial TCB.  */
00073 #  define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t)
00074 
00075 /* This is the size of the TCB.  */
00076 #  define TLS_TCB_SIZE sizeof (struct _pthread_descr_struct)
00077 
00078 /* Alignment requirements for the TCB.  */
00079 #  define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct)
00080 
00081 /* The TCB can have any size and the memory following the address the
00082    thread pointer points to is unspecified.  Allocate the TCB there.  */
00083 #  define TLS_TCB_AT_TP     1
00084 
00085 /* Install the dtv pointer.  The pointer passed is to the element with
00086    index -1 which contain the length.  */
00087 #  define INSTALL_DTV(descr, dtvp) \
00088   ((tcbhead_t *) (descr))->dtv = (dtvp) + 1
00089 
00090 /* Install new dtv for current thread.  */
00091 #  define INSTALL_NEW_DTV(DTV) \
00092   (((tcbhead_t *) __thread_self)->dtv = (DTV))
00093 
00094 /* Return dtv of given thread descriptor.  */
00095 #  define GET_DTV(descr) \
00096   (((tcbhead_t *) (descr))->dtv)
00097 
00098 /* Code to initially initialize the thread pointer.  */
00099 # define TLS_INIT_TP(descr, secondcall) \
00100   (__thread_self = (__typeof (__thread_self)) (descr), NULL)
00101 
00102 /* Return the address of the dtv for the current thread.  */
00103 #  define THREAD_DTV() \
00104   (((tcbhead_t *) __thread_self)->dtv)
00105 
00106 /* Set the stack guard field in TCB head.  */
00107 #define THREAD_SET_STACK_GUARD(value) \
00108   THREAD_SETMEM (THREAD_SELF, p_header.data.stack_guard, value)
00109 # define THREAD_COPY_STACK_GUARD(descr) \
00110   ((descr)->p_header.data.stack_guard \
00111    = THREAD_GETMEM (THREAD_SELF, p_header.data.stack_guard))
00112 
00113 /* Get/set the stack guard field in TCB head.  */
00114 #define THREAD_GET_POINTER_GUARD() \
00115   THREAD_GETMEM (THREAD_SELF, p_header.data.pointer_guard)
00116 #define THREAD_SET_POINTER_GUARD(value) \
00117   THREAD_SETMEM (THREAD_SELF, p_header.data.pointer_guard, value)
00118 # define THREAD_COPY_POINTER_GUARD(descr) \
00119   ((descr)->p_header.data.pointer_guard = THREAD_GET_POINTER_GUARD ())
00120 
00121 # endif
00122 
00123 #else
00124 
00125 # define NONTLS_INIT_TP \
00126   do {                                                               \
00127     static const tcbhead_t nontls_init_tp                            \
00128       = { .multiple_threads = 0 };                                   \
00129     __thread_self = (__typeof (__thread_self)) &nontls_init_tp;                    \
00130   } while (0)
00131 
00132 #endif /* USE_TLS */
00133 
00134 #endif /* tls.h */