1 /* Definitions for thread-local data handling. linuxthreads/IA-64 version. 2 Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. 3 This file is part of the GNU C Library. 4 5 The GNU C Library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 The GNU C Library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with the GNU C Library; if not, see 17 <http://www.gnu.org/licenses/>. */ 18 19 #ifndef _TLS_H 20 #define _TLS_H 21 22 #ifndef __ASSEMBLER__ 23 24 # include <pt-machine.h> 25 # include <stdbool.h> 26 # include <stddef.h> 27 28 /* Type for the dtv. */ 29 typedef union dtv 30 { 31 size_t counter; 32 struct 33 { 34 void *val; 35 bool is_static; 36 } pointer; 37 } dtv_t; 38 39 #else /* __ASSEMBLER__ */ 40 # include <tcb-offsets.h> 41 #endif /* __ASSEMBLER__ */ 42 43 #ifdef HAVE_TLS_SUPPORT 44 45 /* Signal that TLS support is available. */ 46 # define USE_TLS 1 47 48 # ifndef __ASSEMBLER__ 49 50 typedef struct 51 { 52 dtv_t *dtv; 53 void *private; 54 } tcbhead_t; 55 56 /* This is the size of the initial TCB. */ 57 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t) 58 59 /* Alignment requirements for the initial TCB. */ 60 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t) 61 62 /* This is the size of the TCB. */ 63 # define TLS_TCB_SIZE sizeof (tcbhead_t) 64 65 /* This is the size we need before TCB. */ 66 # define TLS_PRE_TCB_SIZE sizeof (struct _pthread_descr_struct) 67 68 /* Alignment requirements for the TCB. */ 69 # define TLS_TCB_ALIGN __alignof__ (struct _pthread_descr_struct) 70 71 /* The DTV is allocated at the TP; the TCB is placed elsewhere. */ 72 # define TLS_DTV_AT_TP 1 73 74 /* Install the dtv pointer. The pointer passed is to the element with 75 index -1 which contain the length. */ 76 # define INSTALL_DTV(tcbp, dtvp) \ 77 ((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1 78 79 /* Install new dtv for current thread. */ 80 # define INSTALL_NEW_DTV(DTV) \ 81 (((tcbhead_t *)__thread_self)->dtv = (DTV)) 82 83 /* Return dtv of given thread descriptor. */ 84 # define GET_DTV(tcbp) \ 85 (((tcbhead_t *) (tcbp))->dtv) 86 87 #if defined NEED_DL_SYSINFO 88 # define INIT_SYSINFO \ 89 (((tcbhead_t *) __thread_self)->private = (void *) GLRO(dl_sysinfo)) 90 #else 91 # define INIT_SYSINFO 0 92 #endif 93 94 /* Code to initially initialize the thread pointer. This might need 95 special attention since 'errno' is not yet available and if the 96 operation can cause a failure 'errno' must not be touched. */ 97 # define TLS_INIT_TP(tcbp, secondcall) \ 98 (__thread_self = (__typeof (__thread_self)) (tcbp), INIT_SYSINFO, NULL) 99 100 /* Return the address of the dtv for the current thread. */ 101 # define THREAD_DTV() \ 102 (((tcbhead_t *)__thread_self)->dtv) 103 104 /* Return the thread descriptor for the current thread. */ 105 # undef THREAD_SELF 106 # define THREAD_SELF (__thread_self - 1) 107 108 # undef INIT_THREAD_SELF 109 # define INIT_THREAD_SELF(descr, nr) \ 110 (__thread_self = (struct _pthread_descr_struct *)(descr) + 1) 111 112 # define TLS_MULTIPLE_THREADS_IN_TCB 1 113 114 # endif 115 116 #endif /* USE_TLS */ 117 118 #endif /* tls.h */ 119