1 /* Definition for thread-local data handling. linuxthreads/SH version. 2 Copyright (C) 2002, 2003, 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 # include <pt-machine.h> 23 24 #ifndef __ASSEMBLER__ 25 # include <stdbool.h> 26 # include <stddef.h> 27 # include <stdint.h> 28 29 /* Type for the dtv. */ 30 typedef union dtv 31 { 32 size_t counter; 33 void *pointer; 34 } dtv_t; 35 36 37 typedef struct 38 { 39 void *tcb; /* Pointer to the TCB. Not necessary the 40 thread descriptor used by libpthread. */ 41 dtv_t *dtv; 42 void *self; /* Pointer to the thread descriptor. */ 43 } tcbhead_t; 44 45 46 /* We can support TLS only if the floating-stack support is available. */ 47 #if defined FLOATING_STACKS && defined HAVE_TLS_SUPPORT 48 49 /* Get system call information. */ 50 # include <sysdep.h> 51 52 /* Signal that TLS support is available. */ 53 //# define USE_TLS 1 54 55 56 /* Get the thread descriptor definition. */ 57 # include <linuxthreads/descr.h> 58 59 /* This is the size of the initial TCB. */ 60 # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t) 61 62 /* Alignment requirements for the initial TCB. */ 63 # define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t) 64 65 /* This is the size of the TCB. */ 66 # define TLS_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 TLS blocks start right after the TCB. */ 72 # define TLS_DTV_AT_TP 1 73 74 75 /* Install the dtv pointer. The pointer passed is to the element with 76 index -1 which contain the length. */ 77 # define INSTALL_DTV(descr, dtvp) \ 78 ((tcbhead_t *) (descr))->dtv = dtvp + 1 79 80 /* Install new dtv for current thread. */ 81 # define INSTALL_NEW_DTV(dtv) \ 82 ({ struct _pthread_descr_struct *__descr; \ 83 THREAD_SETMEM (__descr, p_header.data.dtvp, (dtv)); }) 84 85 /* Return dtv of given thread descriptor. */ 86 # define GET_DTV(descr) \ 87 (((tcbhead_t *) (descr))->dtv) 88 89 /* Code to initially initialize the thread pointer. This might need 90 special attention since 'errno' is not yet available and if the 91 operation can cause a failure 'errno' must not be touched. */ 92 # define TLS_INIT_TP(descr, secondcall) \ 93 ({ \ 94 void *_descr = (descr); \ 95 int result; \ 96 tcbhead_t *head = _descr; \ 97 \ 98 head->tcb = _descr; \ 99 /* For now the thread descriptor is at the same address. */ \ 100 head->self = _descr; \ 101 \ 102 __asm__ ("ldc %0,gbr" : : "r" (_descr)); \ 103 \ 104 0; \ 105 }) 106 107 108 /* Return the address of the dtv for the current thread. */ 109 # define THREAD_DTV() \ 110 ({ struct _pthread_descr_struct *__descr; \ 111 THREAD_GETMEM (__descr, p_header.data.dtvp); }) 112 113 #endif /* FLOATING_STACKS && HAVE_TLS_SUPPORT */ 114 #endif /* __ASSEMBLER__ */ 115 116 #endif /* tls.h */ 117